Թաքցված խնդիր
|Այս խնդիրը թաքցված է խմբագրական խրհրդի անդամի կողմից քանի որ կամ այն ոչ ճիշտ լեզվով է գրված,|կամ թեստային տվյալներն են սխալ, կամ խնդրի ձևակերպումը պարզ չէ։|

ACM_0244 - DOMINOES

   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 ad- jacent 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

stdin

stdout

1

2

1 2

1 3

YES

2

3

1 2

1 3

1 4

NO

3

2

1 2

3 4

NO


Ավելացրեց.Հրանտ Հովհաննիսյան
Ամսաթիվ.2014-10-08
Ժամանակի սահմանափակումը.1s
Ծրագրի տեքստի սահմանափակումը.50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Լեզուներ.Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE
Աղբյուրը.Central QF 2014.J

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.