The Merger


Submit solution

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

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

The University of Adelaide and the University of South Australia are merging! To manage the growing cohort of computer science students, you must assign each student's classes to one of two campuses.

To minimize disruption to student life, students can make either of two types of requests:

  • LOVE: The student names two peers. They want both of them assigned to the same campus as themselves.
  • HATE: The student names two peers. They want both of them to be assigned to a different campus than themselves.

Given a list of students and their requests, is it possible to assign everyone to campuses in a way that satisfies all of these constraints?

Input

The first line consists of an integer n (1 \leq n \leq 3 \times 10^4), the number of requests.

The next n lines contain S, C, S_1, and S_2, where:

  • S is the name of the student making the request.
  • C is either:
    • LOVE, indicating that student S wants to be assigned to the same campus as both S_1 and S_2.
    • HATE, indicating that student S wants to be assigned to a different campus than both S_1 and S_2.
  • 1 \leq S.\text{length}, S_1.\text{length}, S_2.\text{length} \leq 20.
  • S \neq S_1 \neq S_2.

Output

Output "Yes" if it is possible to assign the students to campuses so that everyone's requests can be fulfilled. Otherwise, output "No".

Clarifications

  • Some students may choose not to make a request.
  • Some students can make more than one request.
  • All requests are unique.

Example

Input 1
6
Tom LOVE Shayla Jack
Irhas HATE Maged Tom
Kevin LOVE Tim Patrick
Shayla LOVE Tom Ray
Ray HATE Tim Kevin
Tim HATE Tom Jack
Output 1
Yes
  • Tom, Jack, Shayla, Maged, Ray
  • Irhas, Tim, Patrick, Kevin

Everyone is happy:

  • Tom is happy because they are with Shayla and Jack.
  • Irhas is happy because he is not with Tom or Maged.
  • Kevin is happy because he is with Tim and Patrick.
  • Shayla is happy because they are with Tom and Ray.
  • Ray is happy because he not with Tim and Kevin.
  • Tim is happy because he is not with Tom and Jack.
Input 2
2
A LOVE B C
A LOVE D E
Output 2
Yes

Everyone is happy, and they can all go to the same campus.

Input 3
3
A HATE B C
B HATE A C
C HATE A B
Output 3
No

Everyone hates each other, so no two people can be on the same campus.

Input 4
6
A LOVE B C
A LOVE B C
A LOVE B C
B HATE C D
D LOVE C E
E HATE B A
Output 4
No

Comments

There are no comments at the moment.