Bad Maths

View as PDF

Submit solution

Points: 100
Time limit: 10.0s
Memory limit: 977M

Author:
Problem type

You are given a series of equations of the form a \times b = 1 or a \times b = -1. (Where a and b represent some variable). You are tasking with finding out whether each equation is consistent with the previous equations. If the equation is inconsistent, you may assume it is false for the following equations.

Input

The first line contains an integer n, stating the number of equations.

The following n lines are of the form a b c, stating a \times b = c where a and b are strings.

Output

For each equation, output a line containing Yes or No, stating whether it is consistent with the previous equations.

Example 1

Input
10
c c -1
a b 1
c c 1
d e 1
c e 1
c a 1
b e -1
b b -1
b b -1
e b 1
Output
No
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes

Example 2

Input
20
c b 1
e c -1
b b 1
d f -1
a d -1
b c 1
d b 1
f e -1
d b 1
e d 1
c d 1
f a -1
e e 1
c b 1
d d 1
d e -1
b a 1
b a 1
d f 1
a f -1
Output
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
Yes
Yes
No
No
No
No

Comments

There are no comments at the moment.