402380: GYM100741 B Personal programming language

Memory Limit:64 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Personal programming languagetime limit per test1 secondmemory limit per test64 megabytesinputstandard inputoutputstandard output

Everybody knows that you are not a real programmer until you create your own programming language. Informikas is aware of that too. Finally he is ready to become a real programmer.

Informikas doesn't want to create general purpose language (there are already so many of them!). He is creating a programming language to build text using functions.

The function in the programming language is declared and defined like this:

def f = word

Here "f" is a function name and "word" is the word returned by the function. For example, the following function would return "hello":

def h = hello

In addition, functions can be extended. To extend the function you add to function declaration with <function-name>. Only functions that are already declared can be used for extension. In the following example function f3 extends functions f1 and f2; function f5 extends f3 and f4; function f6 extends f3 and f2:

def f1 = world

def f2 = hello

def f3 with f2 with f1 = say

def f4 = please

def f5 with f3 with f4 = dont

def f6 with f3 with f2 = rather

Extending means that the function returns not a single word it defines, but also the words of extended functions. In the previous example calling the function "f3" would return the word defined in "f3", followed by the word defined in "f2" (the first function extended), following by the word defined in "f1" (the second function extended). The result of "f3" would be words "say hello world".

If the function extends other function which is also extending something, then the extensions gets propagated all the way down. In the previous example calling "f5" would result in string "dont say hello world please", because after flattening "f3" you would get:

f5 with f3 with f2 with f1 with f4

However, there is special case. If the same function gets extended multiple times, only the last occurrence would be left. For example, "f6" would be flattened to:

//flattened, but wrong – multiple occurence of "f2"

f6 with f3 with f2 with f1 with f2

//right, leaving only the last occurence of "f2"

f6 with f3 with f1 with f2

resulting in text "rather say world hello".

Knowing the syntax of the language, could you write a compiler which would compute the text returned?

Input

In the first line of input there is integer N (1 ≤ N ≤ 105) – the number of functions defined. In the following N lines there are N functions defined, in the format:

def Fi with Gi1 with Gi2 with ... with Gij = Wi

where Fi is the name of the function, Gi1, ... , Gij are the names of extended functions, Wi is the word returned by the function Fi. Each of Fi, Gij and Wi consists of [1;10] alphanumeric characters. In the last line there is a string H – the function being called, one of Fi.

It is guaranteed that function is used for extending (positions Gij) only if it was defined (position Fi) above. It is also guaranteed that the word "with" would be used no more than 105 times. In addition, words "def" and "with" are reserved and won't be used in place of neither Fi, Gij nor Wi (however, words "WITH", "wiTH", "Def", etc. are not reserved).

Output

Output the string which would be printed after calling function H.

ExamplesInput
4
def a = one
def b with a = two
def c with a with b = three
def d with c = four
c
Output
three two one 
Input
3
def a = sense
def b with a = make
def c with b with a with b = doesnt
c
Output
doesnt make sense 
Note

This problem was inspired by how Scala programming language deals with multiple inheritance.

加入题单

上一题 下一题 算法标签: