ÀÂÒ
Language: Russian
English

Remote Training on Programming

Problems Online status Contests
News FAQ E-learning
For authors:
Register  ||  Login
 
Hello, Guest! Please login or register.

1334. Dominoes

Time Limit: 1 seconds
Memory Limit:65536KB
Points:100
View Problem Statistics Submit Problem added debug

Vasya, the bus conductor who likes to look for lucky tickets, is also good at playing dominoes. One day someone brought him a number of domino tiles, and he wondered if it would be possible to use all the tiles making a valid line of play, meaning that adjacent tiles touch with an equal number of spots. See an example below (the line makes turns in the figure):

Note: each domino is a 1x2 rectangular tile consisting of two squares (ends). Each end is marked with up to 6 spots or is blank.

Your task is to write a program that determines if it is possible to make a continuous line of play using a given set of n tiles. Adjacent tiles in the line must have an equal number of spots on the touching ends.

Limitations

1 £ n £ 1000.

Input

The first line of the input file contains an integer n, the number of tiles in the set. The following n lines describe the tiles. Each line contains two space-delimited integers from 0 to 6, the number of spots on the two ends of a tile.

Output

The program should output a single string (without quotation marks): “YES” if it is possible to make a continuous line of play using the given tiles, or “NO”, otherwise.

Example

Input

Output

2

1 2

1 3

YES

3

1 2

1 3

1 4

NO

2

1 2

3 4

NO

 


View Problem Statistics Submit Problem discussion Author/source:
Problems from Contests and Camps / World Championship in Programming (ICPC) / Rybinsk-2014 /
1333. I - Belt Drive 1334. 1335. K - Embroidery
time generating 0.125 sec.
© Copyright VSU, AVT, Nosov D.A., Andrianov I.A.