Domino of words P47539


Statement
 

pdf   zip

You are given nn words. Can you permute the words (not their letters) so that the second word begins with the last letter of the first word, the third word begins with the last letter of the second word, and so on?

Input

Input consists of several cases, each with nn, followed by nn words made up of between 1 and 10 lowercase letters. You can assume 1n1051 \le n \le 10^5.

Output

For every case, print “yes” if it is possible arrange all the words like in the game of domino. Otherwise, print “no”.

Public test cases
  • Input

    3 the easiest task
    2 or not
    1 hello
    2 ab abc
    5 za z zz zz bz
    3 a a a
    

    Output

    yes
    no
    yes
    no
    yes
    yes
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++