408894: GYM103372 I Cities Solitaire

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. Cities Solitairetime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard output

Bytica is playing the solitaire game based on the well-known Cities game.

In the solitaire version, you have the list of $$$n$$$ city names, and your goal is to arrange them in sequence such as for any $$$1 \le i < n$$$ the last letter of $$$i$$$-th word is the first letter of $$$i+1$$$-st word, and the last letter of the $$$n$$$-th word is the first letter of the first word.

Given the list of city names, prepared by Bytica, check if she can reach the goal of the solitaire game.

Input

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of cities in the list. Each of the following $$$n$$$ lines contains one city name — the non-empty string $$$s_i$$$, composed from lowercase English letters ($$$1 \le |s_i| \le 30$$$).

Output

Print "YES" if Bytica can reach the goal of the game, or "NO" otherwise.

ExamplesInput
4
kyiv
minsk
vinnytsia
amsterdam
Output
YES
Input
3
paris
stockholm
miami
Output
NO

加入题单

上一题 下一题 算法标签: