Contests Virtual Contests Problems Submit Runs Status Rank List Forum

2244.   Poor Wenwen
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 252   Accepted Runs: 59    Multiple test files

Goodhorse's little niece Wenwen is very clever, but she is not very happy, because her mother always leaves her many difficult homework to do. Every time when goodhorse comes to see wenwen, she always takes out many homework, and let goodhorse to solve. One of the homework is : Given Wenwen is a variable, equals to sum of some variables and some constant numbers. Each variable is also equal to sum of some variables and some numbers. Wenwen need to work out what herself equals to.

All the equations are in following forms:

"wenwen=apple+pear+9"
"apple=9+3"
"pear=apple"

Because wenwen's mother has promised that, if she can work out this problem, she will be able to go to play in Guihu Park with her uncle. Otherwise, she will not be allowed to play even watching TV. So goodhorse is very keen to help her.

Input

The first line contains an integer n (n ≤ 10), denotes the total number of equations. Each of the following n lines is one valid equation. Every variable will appear in and only in one equation's beginning. Each equation's length will not exceed 100. Each variable's value will be positive and not exceed 10000. Each equation will only contain "=","+", variables and numbers, and will not contain blank/space character. Each variable will only contain lowercase characters and each number is 10-based, contains only digit characters.

Output

If one variable's value needs its own value at last, i.e. there exists an assignment loop, output "poor wenwen:(". Otherwise output wenwen's value in form of "wenwen=A", which A is the value.

Sample Input 1

4
wenwen=apple+banana+pear+5
apple=banana+pear
banana=pear
pear=10


Sample Output 1

wenwen=45


Sample Input 2

3
apple=banana
banana=wenwen+1
wenwen=apple+2+3


Sample Output 2

poor wenwen:(


Hint

Please note that wenwen herself is also a variable.

Source: TOJ 2006 Weekly Contest 7
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.3.0
Maintance:G.D.Retop. Developer: SuperHacker, G.D.Retop