408894: GYM103372 I Cities Solitaire
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.
InputThe 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$$$).
OutputPrint "YES" if Bytica can reach the goal of the game, or "NO" otherwise.
ExamplesInput4 kyiv minsk vinnytsia amsterdamOutput
YESInput
3 paris stockholm miamiOutput
NO