Domino of words P47539


Statement
 

pdf   zip

thehtml

You are given n 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 n, followed by n words made up of between 1 and ‍10 lowercase letters. You can assume 1 ≤ n ≤ 105.

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++