Robotopia


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C++, Java, Python

You're playing Robotopia, a simulation game where you create and manage a bustling society of robots. There are many types of robots that can be created to perform various tasks throughout Robotopia's districts. There are some limitations: some robots have prerequisites that must be built first, and some types of robots cannot be placed into the same district.

To make life easier when designing Robotopia, you come up with a list of rules to follow. Each rule has one of the following formats:

  • Coexist A B: Robots of type A and type B must be placed in the same district
  • Incompatible A B: Robots of type A and type B must not be placed in the same district
  • DependsOn A B: Type A robots can only exist if type B robots also exist (B is a prerequisite for A)

You want to determine whether your list of rules is consistent with no contradictions. If the rules are valid, you can start building your robot metropolis!

Input

The first line contains a single integer n (1 \leq n \leq 10^5), the number of rules given.

The next n lines contain strings R, A, and B — the rule, a robot of type A and a robot of type B. All strings are 100 characters or less.

Output

Output "Yes" if the list of rules are correct, and output "No" otherwise.

Clarification

  • The robots are not necessarily built in the order they're given in the input. What matters is that the rules are consistent.
  • DependsOn A B only requires that type B robots are built before type A robots. It does not restrict which districts A or B can be placed in.

Example

Input 1
4
Coexist A B
Coexist C B
Incompatible C D
DependsOn E A
Output 1
Yes
Input 2
2
Coexist A B
Incompatible A B
Output 2
No

Comments

There are no comments at the moment.