#P1251. Special Week With Calculation

Special Week With Calculation

题目描述

One day, Special Week plays with her classmates Teio and Myqueen. They are playing a game with calculation. First of all Teio and Myqueen will write some codes which are about some calculations on the paper.

Then Special Week will calculate the result by herself with her mind only. This is very interesting for Special Week, and she calculates quickly. As there are so many codes on the paper, she is tired reading all the codes by herself. So she approaches them to read the code to her.

But Teio and Myqueen doesn't read the code one by one, they just reads the code at whatever time they like. But they also obey the order of the code, which is from top to bottom.

So, this is different from the original game, because there are some shared values in their codes so the results may change depending on the order of the code read by them.

For example, if the codes on Teio's paper is:

x=1; 
x=x+1; 
a=x+1; 
print a; 

And the codes on Myqueen's paper is:

x=2; 
x=x+2; 
b=x-3; 
print b; 

So, in the original game, the result of aa is 3 and the result of bb is 1.

But if they read the code asynchronously, which may be like below:

x=1; //Teio's code 
x=2; //Myqueen's code 
x=x+1; //Teio's code 
a=x+1; // Teio's code 
x=x+2; // Myqueen's code 
b=x-3; // Myqueen's code 
print a; // Teio's code 
print b; // Myqueen's code 

The result of a and b are different from the original game's, which is a=4a=4 and b=2b=2.

So, in this situation, Special Week just wants to know how many different results of aa and how many different results of bb if they read the code asynchronously?

输入格式

The first line of the input contains one positive integer n(1lenle10)n(1\\le n\\le10) indicating the lines of Teio's code.

Then followed nn lines, Teio's codes.

Then followed one positive integer m(1lemle10)m(1\\le m\\le10) indicating the number of lines of Myqueen's codes.

Then followed mm lines, Myqueen's codes.

The codes only consist of:

?=! //? can be values and ! can be integer or values like a=5 a=4 b=3 b=a 
?=?+! //? can be values and ! can be values or integers like a=b+x a=a+5 a=x+5 
?=?-! 
print ? //? can be a or b 

And it is guaranteed that:

  1. Teio's codes will end with print a and Myqueen's will end with print b and the print command will only appear once in both ends of the codes.
  2. There will only contain values aa,bb and xx and all the values are shared values.
  3. Initially, a=b=x=0a=b=x=0.
  4. All the integers in the input are less than 100.

输出格式

The first line print the possible values of aa in increasing order.

The second line print the possible values of bb in increasing order.

样例

4 
x=1 
x=x+1 
a=x+1 
print a 
4 
x=2 
x=x+2 
b=x-3 
print b
3 4 5 6 
-2 -1 0 1 2
5 
x=1 
x=x+5 
a=x-1 
a=a+b 
print a 
4 
x=4 
x=x+12 
b=x-3 
print b
3 5 8 15 16 17 18 20 26 27 28 32 33 38 
-2 3 10 13 15 18 

1 
print a 
1 
print b 

0 
0