Preparing NOJ

Cities Solitaire

1000ms 524288K

Description:

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.

Sample Input:

4
kyiv
minsk
vinnytsia
amsterdam

Sample Output:

YES

Sample Input:

3
paris
stockholm
miami

Sample Output:

NO

Info

CodeForces Gym

Provider CodeForces Gym

Origin XXII Open Cup. Grand Prix of Korea (Division 2)

Code GYM103372I

Tags

Submitted 0

Passed 0

AC Rate 0%

Date 10/31/2021 14:45:49

Related

Nothing Yet