Problem:
 Score : 200 points    Problem Statement Takahashi is practicing shiritori alone again today.  Shiritori is a game as follows:   In the first turn, a player announces any one word.  In the subsequent turns, a player announces a word that satisfies the following conditions:  That word is not announced before.  The first character of that word is the same as the last character of the last word announced.     In this game, he is practicing to announce as many words as possible in ten seconds.  You are given the number of words Takahashi announced, N , and the i -th word he announced, W_i , for each i . Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.      Constraints  N is an integer satisfying 2 \leq N \leq 100 .  W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.         Input Input is given from Standard Input in the following format:  N  W_1  W_2  :  W_N       Output If every word announced by Takahashi satisfied the conditions, print Yes ; otherwise, print No .        Sample Input 1 4
hoge
english
hoge
enigma      Sample Output 1 No  As hoge is announced multiple times, the rules of shiritori was not observed.       Sample Input 2 9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly      Sample Output 2 Yes       Sample Input 3 8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa      Sample Output 3 No       Sample Input 4 3
abc
arc
agc      Sample Output 4 No

Solution (Python):
n = int(input())
word = input()
words = {word}
for i in range(n-1):
    word2 = input()
    if word[-1] == word2[0] and word2 not in words:
        words.add(word2)
        word = word2
    else:
        print('No')
        exit()
print('Yes')

Solution (Python):
n = int(input())
w = [input() for i in range(n)]
flag = 1
for i in range(n):
  for j in range(n):
    if i == j:
      continue
    if w[i] == w[j]:
      flag = flag *0
      break
for i in range(n):
  if i == 0:
    continue
  if w[i-1][-1] == w[i][0]:
    flag = flag * 1
  else:
    flag = flag * 0
    
if flag == 1:
  print("Yes")
else:
  print("No")

Solution (Python):
import sys
N=int(input())
a=[[] for i in range(N)]
for i in range(N):
    a[i]=input()
    
for i in range(N):
    if i>0:
        if a[i-1][len(a[i-1])-1]!=a[i][0]:
            print("No")
            sys.exit()

for i in range(N):
    for j in range(1,N-i-1):
        if a[i] == a[N-j]:
                print("No")
                sys.exit()

print("Yes")

Solution (Python):
from collections import Counter
N = int(input())
wlist = [input() for i in range(N)]
wlist_counter = Counter(wlist)
ans = 1

if wlist_counter.most_common()[0][1] >= 2:
    ans = 0

for i in range(0,N-1):
    W_ed = wlist[i]
    W_st = wlist[i+1]
    if W_ed[-1] != W_st[0]:
        ans = 0
        break

if ans == 0:
    print("No")
elif ans == 1:
    print("Yes")

Solution (Python):
N = int(input())
words = []
for i in range(N) :
	words.append(input())

first_word = words[0][0]
last_word = ""
is_okay = True

tmp_words = list(set(words))
if (len(tmp_words) != len(words)) :
	is_okay = False

for s in words :
	if (first_word != s[0]) :
		is_okay = False
		break
	
	first_word = s[-1]


if(is_okay) :
	print("Yes")
else :
	print("No")

Solution (Python):
import sys

N = int(input())
W = [input() for _ in range(N)]

if len(set(W)) != N:
    print('No')
    sys.exit()

prev = W[0][-1]
for w in W[1:]:
    if prev != w[0]:
        print('No')
        sys.exit()
    prev = w[-1]

print('Yes')

Solution (Python):
n = int(input())
w = [input() for i in range(n)]
flag = 1



for i in range(n):
  for j in range(n):
    if i == j:
      continue
    if w[i] == w[j]:
      flag = flag *0
      break
    
for i in range(n):
  if i == 0:
    continue
  if w[i-1][-1] == w[i][0]:
    flag = flag * 1
  else:
    flag = flag * 0
    
if flag == 1:
  print("Yes")
else:
  print("No")

Solution (Python):
import sys
N=int(input())
a=[[] for i in range(N)]
for i in range(N):
    a[i]=input()
    
for i in range(N):
    if i>0:
        if a[i-1][len(a[i-1])-1]!=a[i][0]:
            print("No")
            sys.exit()

for i in range(N):
    for j in range(1,N-i-1):
        if a[i] == a[N-j]:
                print("No")
                sys.exit()

print("Yes")

Solution (Python):
import sys
c = int (input())
words = []
No=" "
for i in range (c) :
    words.append(input())
for x in range(len(words)-1):
    if words.count(words[x]) > 1 or words[x+1][0] != words[x][-1]:
        No="No"
        print (No)
        sys.exit() 


if No != "No":
     print ("Yes")

Solution (Python):
import sys
import string
input=sys.stdin.readline

n=int(input())
l=[list(input().rstrip()) for i in range(n)]
if len(set(map(tuple,l)))!=len(l):
        print('No')
else:
    for i in range(n-1):
        if l[i][-1]!=l[i+1][0]:
            print('No')
            break
    else:
        print('Yes')

Solution (Python):
import sys
n = int (input())
words = []
No=" "
for i in range (n) :
    words.append(input())
for x in range(len(words)-1):
    if words.count(words[x]) > 1 or words[x+1][0] != words[x][-1]:
        No="No"
        print (No)
        sys.exit() 
if No != "No":
     print ("Yes")

Solution (Python):
import sys
n = int (input())
words = []
No=" "
for i in range (n) :
    words.append(input())
for x in range(len(words)-1):
    if words.count(words[x]) > 1 or words[x+1][0] != words[x][-1]:
        No="No"
        print (No)
        sys.exit() 
if No != "No":
     print ("Yes")

Solution (Python):
N = int(input())
a = list(input() for i in range(N)) 
k = 0
for i in range(N-1): 
  if a.count(a[i]) != 1:
    print('No')
    break
  elif (a[i+1][0:1]) != (a[i][-1:]): 
    print('No')
    break
  else:
    k = k + 1

if k == (N-1):
  print('Yes')

Solution (Python):
N = int(input())
a = list(input() for i in range(N)) 
k = 0
for i in range(N-1): 
  if a.count(a[i]) != 1:
    print('No')
    break
  elif a[N-1] == a[i]:
    print('No')
    break
  elif (a[i+1][0:1]) != (a[i][-1:]): 
    print('No')
    break
  else:
    k = k + 1

if k == (N-1):
  print('Yes')

Solution (Python):
a=int(input())
b=[]
for i in range(a):
	b.append(input())

c=list(set(b))

if len(b)!=len(c):
	print("No")
else:
	hantei=True
	for i in range(a-1):
		if b[i][-1]==b[i+1][0]:
			continue
		else:
			hantei=False
			break
	if hantei:
		print("Yes")
	else:
		print("No")

Solution (Python):
lst = []
ans = True
for _ in range(int(input())):
    a = input()
    if len(lst) == 0:
        lst.append(a)
    else:
        x = lst[len(lst)-1]
        if x[len(x)-1] != a[0] or a in lst:
            ans = False
            break
        lst.append(a)
print("Yes" if ans is True else "No")

Solution (Python):
N=int(input())
count=0
m=[]
s=input()
m.append(s)
for i in range(N-1):
    l=input()
    if l not in m and m[i][-1]==l[0]:
        count+=1
    m.append(l)
if count==N-1:
    print("Yes")
else:
    print("No")

Solution (Python):




w=[]
N=int( input() )

for i in range (0,N):
    wi= input()
    w.append(wi)



comment="Yes"
for i in range (1,N):
    xyz=len(w[i-1])-1
    if(w[i][0]==w[i-1][xyz]):
        pass
    else:
        
        comment="No"
        break




for i in range(0,N):
    if(comment=="No"):break
    for u in range(i+1,N):
        if(w[i]==w[u]):
            comment="No"
            break
print(comment)

Solution (Python):
N=int(input())
c=0
m=[]
s=input()
m.append(s)
for i in range(N-1):
  l=input()
  if l not in m and m[i][-1]==l[0]:
    c+=1
  m.append(l)
if c==N-1:
  print("Yes")
else:
  print("No")

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    used = []
    for _ in range(N):
        W = input()
        if W in used:
            print(No)
            return

        if len(used) != 0 and used[-1][-1] != W[0]:
            print(No)
            return

        used.append(W)

    print(Yes)
    
if __name__ == '__main__':
    main()

Solution (Python):
def shiritori(n, ws):
    if len(ws) != len(set(ws)):
        return 'No'

    for i in range(1, len(ws)):
        if ws[i - 1][-1] != ws[i][0]:
            return 'No'
    return 'Yes'

n = int(input())
ws = []
for _ in range(n):
    ws += [input()]
print(shiritori(n, ws))

Solution (Python):
import sys
n = int(input())
W = ['']*n
for i in range(n):
    W[i] = input()
if len(W) != len(set(W)):
    print('No')
    sys.exit(0)
for i in range(n-1):
    if W[i][-1] != W[i+1][0]:
        print('No')
        sys.exit(0)
print('Yes')

Solution (Python):
import sys

n=int(input())
wli=[]
w=input()
wli.append(w)

for i in range(n-1):
    w=input()
    if w in wli:
        print("No")
        sys.exit()
    elif wli[i][-1:]!=w[0]:
        print("No")
        sys.exit()
    else:
        wli.append(w)

print("Yes")

Solution (Python):
import sys

N=int(input())
W_li=[]
W=input()
W_li.append(W)

for i in range(N-1):
    W=input()
    if W in W_li:
        print("No")
        sys.exit()
    elif W_li[i][-1:]!=W[0]:
        print("No")
        sys.exit()
    else:
        W_li.append(W)
        
print("Yes")

Solution (Python):
def abc109_b():
    n = int(input())
    words = [input() for _ in range(n)]
    for i in range(n-1):
        if words[i][-1] != words[i+1][0]:
            return "No"
    if len(set(words)) != len(words):
        return "No"
    return "Yes"


print(abc109_b())

Solution (Python):
n = int(input())
ans = 'Yes'
dic = []
iw = input()
dic.append(iw)
for i in range(1,n):
    p = i - 1
    w = input()
    if w in dic or dic[p][-1]!=w[0]:
        ans = 'No'
    dic.append(w)
print(ans)

Solution (Python):

n=int(input())
data=[]
check=True
data.append(input())
for i in range(1,n):
  data.append(input())
  for j in range(i):
    if(data[i]==data[j]):
      check=False
  if(data[i-1][len(data[i-1])-1]!=data[i][0]):
    check=False
if(check==False):
  print("No")
else:
  print("Yes")

Solution (Python):

N = int(input())

W = []
re = 'Yes'
last = ''
for i in range(N):
    W.append(input())
    if last != '' and last != W[i][0:1]:
        re = 'No'
    elif W.count(W[i]) >= 2:
        re = 'No'
    last = W[i][-1]
        
print(re)

Solution (Python):
import sys

n=int(input())
mydict={}
before="!"
for i in range(n):
    tmp=input()
    if(before=="!"):
        before=tmp[0]
    if(tmp in mydict or before!=tmp[0]):
        print("No")
        sys.exit()
    mydict[tmp]=i
    before=tmp[-1]

print("Yes")

Solution (Python):
n=int(input())
x=[]
x.append(input())
last_char=x[0][-1]
f_l_checker=True
for i in range(1,n):
    x.append(input())
    if f_l_checker:
        first_char=x[i][0]
        if first_char==last_char:
            f_l_checker=True
            last_char=x[i][-1]
        else:
            f_l_checker=False
            
set_x=set(x)
if len(set_x)==n and f_l_checker==True:
    print('Yes')
else:
    print('No')

Solution (Python):
n=int(input())
x=[]
f_l_checker=True
x.append(input())
for i in range(1,n):
    x.append(input())
    if f_l_checker:
        if x[i][0]==x[i-1][-1]:
            for j in range(i):
                if x[i]==x[j]:
                    f_l_checker=False
        else:
            f_l_checker=False
if f_l_checker:
    print('Yes')
else:
    print('No')

Solution (Python):
n=int(input())
x=[]
x.append(input())
last_char=x[0][-1]
f_l_checker=True
 
for i in range(1,n):
    x.append(input())
    if f_l_checker:
        first_char=x[i][0]
        if first_char==last_char:
            f_l_checker=True
            last_char=x[i][-1]
        else:
            f_l_checker=False
            
set_x=set(x)
if len(set_x)==n and f_l_checker==True:
    print('Yes')
else:
    print('No')

Solution (Python):
n=int(input())
x=[]
x.append(input())
last_char=x[0][-1]
f_l_checker=True
 
for i in range(1,n):
    x.append(input())
    if f_l_checker:
        first_char=x[i][0]
        if first_char==last_char:
            f_l_checker=True
            last_char=x[i][-1]
        else:
            f_l_checker=False
            
set_x=set(x)
if len(set_x)==n and f_l_checker==True:
    print('Yes')
else:
    print('No')

Solution (Python):
n=int(input())
x=[]
f_l_checker=True
x.append(input())
for i in range(1,n):
    x.append(input())
    if f_l_checker:
        if x[i][0]==x[i-1][-1]:
            for j in range(i):
                if x[i]==x[j]:
                    f_l_checker=False
        else:
            f_l_checker=False
if f_l_checker:
    print('Yes')
else:
    print('No')

Solution (Python):
n=int(input())
s=[]
f_l_checker=True
s.append(input())
for i in range(1,n):
    s.append(input())
    if f_l_checker:
        if s[i][0]==s[i-1][-1]:
            for j in range(i):
                if s[j]==s[i]:
                    f_l_checker=False
        else:
            f_l_checker=False
if f_l_checker:
    print("Yes")
else :
    print("No")

Solution (Python):
n=int(input())
s=[]
fla=True
s.append(input())
for i in range(1,n):
    s.append(input())
    if fla :
        if s[i][0]==s[i-1][len(s[i-1])-1]:
            for j in range(i):
                if s[j]==s[i]:
                    fla=False
        else:
            fla=False
if fla:
    print("Yes")
else :
    print("No")

Solution (Python):
def a():
    n=int(input())
    w=list()
    for i in range(n):
        z=input()
        w.append(z)
    for i in range(1,n):
        if w[i][0]!=w[i-1][len(w[i-1])-1]:
            print("No")
            return 0
    w.sort()
    for i in range(n-1):
        if w[i]==w[i+1]:
            print("No")
            return 0
    print("Yes")
    return 0
a()

Solution (Python):
import sys
n = int(input())
w = []
for x in range(n):
    w.append(input())

sw = sorted(w)
for i in range(1, len(sw)):
    if sw[i - 1] == sw[i]:
        print("No")
        sys.exit()
for i in range(1, len(w)):
    if w[i - 1][-1] != w[i][0]:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
import sys

n = int(input())
w = []
for _ in range(n):
  w.append(input())

sw = sorted(w)
for i in range(1, len(sw)):
  if sw[i - 1] == sw[i]:
    print("No")
    sys.exit()

for i in range(1, len(w)):
  if w[i - 1][-1] != w[i][0]:
    print("No")
    sys.exit()

print("Yes")

Solution (Python):
n=int(input())
s=[]
fla=True
s.append(input())
for i in range(1,n):
    s.append(input())
    if fla :
        if s[i][0]==s[i-1][len(s[i-1])-1]:
            for j in range(i):
                if s[j]==s[i]:
                    fla=False
        else:
            fla=False
if fla:
    print("Yes")
else :
    print("No")

Solution (Python):
n=int(input())
s=[]
for i in range (n):
    s.append('a')
for i in range(n):
    s[i]= [j for j in input()]
flag=True
for i in range(n-1):
    k = len(s[i])
    if s[i][k-1]==s[i+1][0]:
        for j in range(n):
            if s[i]==s[j] and i!=j:
                flag=False
                break
    else:
        flag=False
        break
if flag :
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
a = []
flag = 1
for i in range(N):
    a.append(str(input()))
    if i != 0:
        for j in range(i):
            if a[i] == a[j]:
                flag =0


back = a[0][-1]
for i in range(1,N):
    front = a[i][0]
    if front != back:
        flag = 0
        break
    back = a[i][-1]

if flag == 0:
    print("No") 
else:
    print("Yes")

Solution (Python):
N=int(input())
W=[]
same=[]
counter=0
for i in range(N):
    W.append(input())

for i in range(len(W)):
    for x in range(i+1,len(W)):
        if W[i]==W[x]:
            same.append(W[i])
  
for i in range(len(W)-1):
    if len(same)!=0:
        counter=0
        break
    
    if W[i][-1]==W[i+1][0]:
        counter+=1
        
        
    if W[i][-1]!=W[i+1][0]:
        counter+=0
        
if counter==len(W)-1:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())

chr = [str(input()) for i in range (n)]


first = [chr[x][:1] for x in range(n)]


last = [chr[y][-1] for y in range(n)]


same = 1
for z in range (n-1):
  if last[z] == first[z+1]:
    same = 0
  else:
    same = 1
    break

dbl = 0
for i in range (n):
  for j in range (i+1, n):
    if chr[i] == chr[j]:
      dbl = 1
    else:
      continue


if same == 0 and dbl == 0:
  print("Yes")
else:
  print("No")

Solution (Python):
x=int(input())
words=[]
found=0
word_1=''
word_2=''
for i in range(x):
    words.append(input())

for j in range(x-1):
    for k in range(j+1,x):
        if words[j]==words[k]:
            found=-1
for c in range(x-1):
    word_1=words[c]
    word_2=words[c+1]
    if word_1[-1]!=word_2[0]:
        found=-1
if found==-1:
    print("No")
else:
    print("Yes")

Solution (Python):
n = input()
last_word = raw_input()
arr = [last_word]
f = 0
for i in range(n-1):
    str = raw_input()
    if str in arr:
        f = 1
        break
    elif str[0] == last_word[-1]:
        last_word = str
        arr.append(str)
    else:
        f = 1
        break
if f == 0:
    print "Yes"
else:
    print "No"

Solution (Python):
n = input()
last_word = raw_input()
arr = [last_word]
f = 0
for i in range(n-1):
    str = raw_input()
    if str in arr:
        f = 1
        break
    elif str[0] == last_word[-1]:
        last_word = str
        arr.append(str)
    else:
        f = 1
        break
if f == 0:
    print "Yes"
else:
    print "No"

Solution (Python):
N = int(input().rstrip())
l = []
w = ""
for i in range(N):
  cur = input().rstrip()
  if (w != "" and w != cur[0]) or cur in l:
    print("No")
    exit()
  l.append(cur)
  w = cur[-1]
print("Yes")

Solution (Python):
N = int(input())
W = [input() for i in range(N)]
a = set()
b = W[0][0] 
OK = True
for w in W:
    if b[-1]!=w[0] or w in a:
        OK = False
    a.add(w)
    b = w
print('Yes' if OK else 'No')

Solution (Python):
N = int(input())
W = [input() for i in range(N)]
a = set()
b = W[0][0] 
OK = True
for w in W:
    if b[-1]!=w[0] or w in a:
        OK = False
    a.add(w)
    b = w
print('Yes' if OK else 'No')

Solution (Python):
N = int(input())
w = []
for i in range(N):
    w.append(input())

p = 0
for i in range(N):
  for j in range(i+1,N):
    if w[i] == w[j]:
      p = 1
      break
v = []
    
for i in range(N):
  v.append([])

for j in range(N):
  for s in list(w[j]):
    v[j].append(s)

for k in range(N):
  if k != 0:
    if v[k - 1][len(v[k - 1]) - 1] != v[k][0]:
      p = 1
      break

if p == 0:
  print("Yes")
else:
  print("No")

Solution (Python):
n=int(input())
s=[]
for i in range (n):
    s.append('a')
for i in range(n):
    s[i]= [j for j in input()]
flag=True
for i in range(n-1):
    k = len(s[i])
    if s[i][k-1]==s[i+1][0]:
        for j in range(n):
            if s[i]==s[j] and i!=j:
                flag=False
                break
    else:
        flag=False
        break
if flag :
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
list_words = []
for q in range(n):
    list_words.append(input())


def check(l):
    for i in range(len(l)-1):
        if l[i][-1] != l[i+1][0]:
            return "No"
    for o in range(len(l)):
        if l[o] in l[:o] or o in l[o+1:]:
            return "No"
    return "Yes"


print(check(list_words))

Solution (Python):
N=int(input())
w=[]
c=[]
r=0
for i in range(N):
    w.append(input())

for i in range(N-1):
    if w[i][len(w[i])-1]!=w[i+1][0]:
        r+=1
for v in w:
    if v not in c:
        c.append(v)
if len(c)==len(w):
    r+=0
else:
    r+=1
       
if r==0 :
    print("Yes")
else:
    print("No")

Solution (Python):
c=int(input())
l=[]
b=''
f=False
for i in range(c):
	a=input()
	if l.count(a)>0 or (b!='' and a[0]!=b[-1]):
		f=True
	b=a
	l.append(a)
if f:
	print('No')
else:
	print('Yes')

Solution (Python):
n = int(input())
l= []
x = 0
for elt in range(n):
    inp = input()
    l.append(inp)
for elt in range(len(l)):
    if l.count(l[elt]) > 1 :
        print("No")
        x+=1
        break

    else:
        if elt < len(l)-1:
            if l[elt][-1] != l[elt+1][0]:
                print("No")
                x += 1
                break
if x == 0:
    print("Yes")

Solution (Python):
N = int(input())
W = [input() for _ in range(N)]

for i in range(N):
    if W[i] in W[i+1:]:
        print('No')
        
        exit()
    elif i > 0 and W[i-1][-1] != W[i][0]:
        
        print('No')
        exit()

print('Yes')

Solution (Python):
def get():
    n = int(input())

    g = []
    for _ in range(n):
        g.append(input())

    return g

def yesOrNo(g):
    c = 0
    
    for i in range(len(g)):
        for j in range(i+1, len(g), 1):
            if g[i] == g[j]:
                c += 1
                break
    
    for i in range(1, len(g), 1):
        if(g[i][0] != g[i-1][len(g[i-1])-1]):
            c += 1
            break

    return c
    

g = get()
r = yesOrNo(g)

if r != 0:
    print("No")

else:
    print("Yes")

Solution (Python):
num=int(input())
list1=[]
flag=0
j=0

for i in range(num):

    a=input()



    if a in list1:
        flag+=1
    list1.append(a)
    if j>0:
        if list1[i-1][len(list1[i-1])-1]==list1[i][0]:
           pass

        else:
          flag+=2

    j=1

if flag>0:
    print("No")
else:
    print("Yes")

Solution (Python):
N=int(input())
W=[]
for i in range(N):
  W.append(input())
for i in range(N-1):
  if W[i][-1] != W[i+1][0]:
    print('No')
    exit()
  for j in range(i+1, N):
    if W[i]==W[j]:
      print('No')
      exit()
print('Yes')

Solution (Python):
from math import*
import sys
n = int(input())
listtt = []
string=input()
lastChar = string[-1]
listtt.append(string)
k=n-1
while(k) :
    k-=1
    string = input()
    if (string[0]!=lastChar):
       print("No")
       sys.exit()
    else :
       lastChar=string[-1]
       listtt.append(string)
for i in listtt :
    if listtt.count(i) > 1 :
        print ("No")
        sys.exit()
print ("Yes")

Solution (Python):
n=int(input())
used=[]
used.append(input())
chain=used[0][-1]
res="Yes"
for i in range(n-1):
    s=input()
    c=s[0]
    if s in used or chain!=c:
        res="No"
        break
    used.append(s)
    chain=s[-1]
    

print(res)

Solution (Python):
def Condition(W):
    for i in range(len(W)):
        for j in range(i,len(W)):
            if W[i]==W[j] and i!=j:
                print('No')
                return None
    for i in range(len(W)-1):
        k=len(W[i])-1
        if W[i][k]!=W[i+1][0]:
            print('No')
            return None
    print('Yes')    


N=int(input())
W=[]
for i in range (N):
    W.append(input())    
Condition(W)

Solution (Python):
n = int(input())

li = [input() for _ in range(n)]
set_li = set(li)
flag = 'Yes'

if len(li) == len(set_li):
    for i in range(n):
        li[i] = list(li[i])
    for i in range(n-1):
        if li[i][len(li[i])-1] != li[i+1][0]:
            flag = 'No'
            break
else:
    flag = 'No'

print(flag)

Solution (Python):


from collections import Counter


def solve(words):
    if Counter(words).most_common()[0][1] > 1:  
        return "No"
    else:
        
        
        if list(map(lambda x: x[0], words[1:])) == list(map(lambda x: x[-1], words[:-1])):
            return "Yes"
        else:
            return "No"


def solve2(words):
    for i in range(len(words) - 1):
        if words[i] in words[i + 1:]:
            return "No"
        else:
            if words[i][-1] != words[i + 1][0]:
                return "No"
    return "Yes"


if __name__ == "__main__":
    N = int(input(""))
    words = [input("") for i in range(N)]
    print(solve2(words))

Solution (Python):


from collections import Counter


def solve(words):
    commons = Counter(words).most_common()
    if commons[0][1] > 1:
        return "No"
    else:
        
        first_letters = list(map(lambda x: x[0], words[1:]))
        
        last_letters = list(map(lambda x: x[-1], words[:-1]))
        if first_letters == last_letters:
            return "Yes"
        else:
            return "No"


if __name__ == "__main__":
    N = int(input(""))
    words = [input("") for i in range(N)]
    print(solve(words))

Solution (Python):
import collections

N=int(input())
arr=[]
for i in range(N):    
    arr.append(input())  

lastchar=list(arr[0])[len(arr[0])-1]
count=1
for i in range(1,N):
    firstchar=list(arr[i])[0]
    if(lastchar==firstchar):
        lastchar=list(arr[i])[len(arr[i])-1]
        count+=1
    else:        
        break

flag=True

tocheck=list(collections.Counter(arr).values())

for item in tocheck:
    if(item>1):        
        flag=False        
        break

if(N==count and flag==True):
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
s=[input()]
f=True
for i in range(1,n):
    d=input()
    if d in s or s[i-1][len(s[i-1])-1]!=d[0]: 
        f= False
    s.append (d)


if f :
    print ("Yes")

else:
    print ("No")

Solution (Python):
n=int(input())
w=[input()]
check=True
for i in range (1,n):
    x = input()
    if x in w or w[i-1][len(w[i-1])-1]!=x[0]:
        check=False
    w.append(x)
if check:
    print('Yes')
else:
    print('No')

Solution (Python):
n=int(input())
w=[input()]
check=True
for i in range (1,n):
    x = input()
    if x in w or w[i-1][len(w[i-1])-1]!=x[0]:
        check=False
    w.append(x)
if check:
    print('Yes')
else:
    print('No')

Solution (Python):
a=int(input())
x=[input()]
flag=0
for i in range(1,a):
    s=input()
    if s in x or x[i-1][len(x[i-1])-1]!=s[0] :
      
        flag=1
    x.append(s)
        
if flag == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
a=int(input())
x=[input()]
flag=0
for i in range(1,a):
    s=input()
    if s in x or x[i-1][len(x[i-1])-1]!=s[0] :
        x.append("1")
        flag=1
    else:
        x.append(s)
if flag == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
word=[]
for i in range(n):
    word.append(input())
 
 
cnt=0
for i in range (n-1):
    if word[i][len(word[i]) - 1] != word[i + 1][0]:
        cnt += 1
        print("No")
        break
    for j in range (i):
     if word[i+1]==word[j]:
        cnt+=1
        print ("No")
        break
 
if cnt==0:
    print("Yes")

Solution (Python):
n=int(input())
word=[]
for i in range(n):
    word.append(input())


cnt=0
for i in range (n-1):
    if word[i][len(word[i]) - 1] != word[i + 1][0]:
        cnt += 1
        print("No")
        break
    for j in range (i):
     if word[i+1]==word[j]:
        cnt+=1
        print ("No")
        break

if cnt==0:
    print("Yes")

Solution (Python):
n = int(input())
l= []
x = 0
for elt in range(n):
    inp = input()
    l.append(inp)
for elt in range(len(l)):
    if l.count(l[elt]) > 1 :
        print("No")
        x+=1
        break

    else:
        if elt < len(l)-1:
            if l[elt][-1] != l[elt+1][0]:
                print("No")
                x += 1
                break
if x == 0:
    print("Yes")

Solution (Python):
n=int(input())
w=[]
for i in range(n):
    x=input()
    w.append(x)

s=set(w)
if len(s)<len(w):
    print('No')
    exit()

for i in range(n-1):
    if w[i][-1]!=w[i+1][0]:
        print('No')
        exit()

print ('Yes')

Solution (Python):
n = int(input())
l= []
x = 0
for elt in range(n):
    inp = input()
    l.append(inp)
for elt in range(len(l)):
    if l.count(l[elt]) > 1 :
        print("No")
        x+=1
        break

    else:
        if elt < len(l)-1:
            if l[elt][-1] != l[elt+1][0]:
                print("No")
                x += 1
                break
if x == 0:
    print("Yes")

Solution (Python):
n= int(input())
w=[]
w.append(input())
c=0
for i in range(n-1):
    s=input()
    if s not in w and w[i][len(w[i])-1] == s[0]:
        c+=1
        w.append(s)
    else:
        break
 
 
if c==n-1:
    print("Yes")
else:
    print ("No")

Solution (Python):
n= int(input())
w=[]
w.append(input())
c=0
for i in range(n-1):
    s=input()
    if s not in w and w[i][len(w[i])-1] == s[0]:
        c+=1
        w.append(s)
    else:
        break


if c==n-1:
    print("Yes")
else:
    print ("No")

Solution (Python):
n = int(input())
words = []
won = True
for i in range(n):
    new_word = input()
    if i > 0 and won:
        if new_word in words or new_word[0] != words[i-1][len(words[i-1])-1]:
            won = False
    words.append(new_word)

if won:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
a = [input() for i in range(n)]
ans = 'Yes'
for i in range(n):
    if a.count(a[i])!=1:
        ans = 'No'
        break
for i in range(n-1):
    if a[i][-1] != a[i+1][0]:
        ans = 'No'
        break
print(ans)

Solution (Python):
a=int(input())
x=[]
flag=0
for i in range(a):
    s=input()
    if i==0:
        x.append(s)
        continue
    
    if s in x or x[i-1][len(x[i-1])-1]!=s[0] :
        x.append("1")
        flag=1
    else:
        x.append(s)
if flag == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
import collections

N = int(input())

words = [input() for i in range(N)]

C = collections.Counter(words)
if C.most_common()[0][1] > 1:
    print('No')
    exit()

for i in range(N-1):
    if words[i][-1] != words[i+1][0]:
        print('No')
        exit()

print('Yes')

Solution (Python):
N = int(input())
W = [input() for i in range(N)]
L = list()
ans = ''
for a in W:
  if W.count(a) >= 2:
    ans = 'No'
    break
  elif L == []:
    a = list(a)
    a.reverse()
    L.append(a[0])
  else:
    a = list(a)
    if a[0] == L[0]:
      a.reverse()
      L[0] = a[0]
      ans = 'Yes'
    else:
      ans = 'No'
      break
print(ans)

Solution (Python):
def is_valid(ws):
    n = len(ws)
    for i in range(1, n):
        if ws[i-1][-1] != ws[i][0]:
            return False
    return len(set(ws)) == n

def solve(ws):
    return "Yes" if is_valid(ws) else "No"

assert solve(["hoge","english","hoge","enigma"]) == "No"
assert solve(["basic","c","cpp","php","python","nadesico","ocaml","lua","assembly"]) == "Yes"
n = input()
ws = [raw_input() for i in range(n)]
print solve(ws)

Solution (Python):
n = int(input())
w = [input() for _ in range(n)]

for i in range(1, len(w)):
    if w[i][0] != w[i - 1][-1]:
        print('No')
        exit()
    else:
        for j in range(0, i):
            if w[j] == w[i]:
                print('No')
                exit()
print('Yes')

Solution (Python):

import collections
a=int(input())
l=[]
c=0
for x in range(a):
    l.append(input())
if len(set(l))!=a:
    print("No")
else:
    k=l.pop(0)[-1]
    for x in l:
        if k==x[0]:
            k=x[-1]
            c+=1
    if c+1==a:
        print("Yes")
    else:
        print("No")

Solution (Python):
n=int(input())
a=[]
for i in range(n):
  a.append((input()))
if(len(a)==len(set(a))):
  for i in range(n-1):
    if(a[i][-1]!=a[i+1][0]):
      print("No")
      exit(0)
  print("Yes")
else:
  print("No")
  exit(0)

Solution (Python):
n = int(input())
key = input()
x = {}
x[key] = None
s = list(key)[-1]
flag = True
for i in range(n - 1):
    xx = input()
    if xx not in x and s == list(xx)[0]:
        x[xx] = None
        s = list(xx)[-1]
    else:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys


def main():
    n = int(input())
    s = set()

    p = input()
    s.add(p)

    for i in range(n - 1):
        w = input()

        if w in s or w[0] != p[-1]:
            print('No')
            return
        
        p = w
        s.add(w)
    
    print('Yes')
        

if __name__ == '__main__':
    main()