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())
words = []
ans = 1
for i in range(n):
    word = input()
    if word not in words:
        words.append(word)
    else:
        ans = 0
if len(words) == n:
    for i in range(n-1):
        word = words[i]
        if words[i][len(word)-1] == words[i+1][0]:
            continue
        else:
            ans = 0
            break

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

Solution (Python):
import sys
input = sys.stdin.read().split()

N = int(input[0])
words = input[1:]

hantei = 0

for i in range(N-1):
    for j in range(i+1,N):
        if words[i] == words[j]:    
            hantei += 1
            break
    if list(words[i])[-1] != list(words[i+1])[0]:   
        hantei += 1
        break

if hantei == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
counter = 0
qq = 0
L = []
for i in range(N) :
    if i == 0 :
        w = input()
        L.append(w)
        q = w[-1]
    if i != 0 :
        w = input()
        if w in L :
            qq += 1
        L.append(w)
        p = w[0]
        if p == q :
            q = w[-1]
            counter += 1

            
            
if counter == N-1 and qq == 0 :
    print("Yes")
else :
    print("No")

Solution (Python):

n = int(input())

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

first = w[0][0]
new_w = []
res = True
for i in range(n):
    if w[i][0] != first or w[i] in new_w:
        res = False
        break
    new_w = w[0:i+1]
    first = w[i][-1]

if res:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys

line = input()
n = int(line)

word_list = []
line = input()
word_list.append(line)
prefix = line[-1:]


ans = "Yes"
for i in range(1, n):
    line = input()

    if line in word_list:
        ans = "No"
    
    word_list.append(line)

    atama = line[:1]
    

    if atama != prefix:
        ans = "No"

    prefix = line[-1:]
    

    if i == 0:
        continue

print(ans)

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

w = str(input())
W = list(w)

Ws = [w]
stop = W[-1]
count = 1

for i in range(N-1):

	w2 = str(input())
	W2 = list(w2)
	if(w2 not in Ws):
		if(W2[0]==stop):
			stop = W2[-1]
			count += 1
			Ws.append(w2)

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

Solution (Python):

import sys
iN = int(input())
aList = [x.strip() for x in sys.stdin.readlines()]



dicList = {aList[0]:1}
for i in range(1,iN):
    if aList[i][0] != aList[i-1][-1] :
        print("No")
        exit()
    if aList[i] not in dicList :
        dicList[aList[i]] = 0
    else:
        print("No")
        exit()
print("Yes")

Solution (Python):
n = int(input())
s = []
f = 0

for i in range(n):
    t = input()
    if t in s:
        f = 1
    elif i != 0 and s[i-1][-1] != t[0]:
        f = 1
    s.append(t)
    
if f == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
def count_word(words, word):
    count = 0

    for w in words:
        if w == word:
            count += 1

    return count

n = int(input())

words = []
for i in range(n):
    words.append(input())

bind_letter = ""
for word in words:
    matches = count_word(words, word)
    if matches >= 2:
        print("No")
        exit()

    if bind_letter != "":
        if word[0] != bind_letter:
            print("No")
            exit()
    bind_letter = word[len(word) - 1]
    
print("Yes")

Solution (Python):
n=int(input())
string_list=[input() for i in range(n)]
ans=0
for i in range(n-1):
    if string_list[i][-1:] != string_list[i+1][:1] :
        ans +=1
zako =set(string_list)

if len(string_list) == len(zako) and ans==0 :
    print("Yes")
else:
    print("No")

Solution (Python):
N=int(input())
list1=[]

s=input()
S=s
list1.append(s)

for i in range(N-1):
    s=input()
    
    
    if s in list1:
        print("No")
        exit()
    elif s[0] != S[len(S)-1]:
        print("No")
        exit()
    else:
        S=S+s
        list1.append(s)
print("Yes")

Solution (Python):
def is_unique(seq):
    return len(seq) == len(set(seq))

N = int(input())
words = []
for i in range(N):
    words.append(input())
hantei = 0
for i in range(N-1):
    a = [x for x in words[i]]
    b = [x for x in words[i+1]]
    if a[len(a)-1] == b[0]:
        pass
    else:
        hantei += 1
        break
if hantei == 0 and is_unique(words) == True:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
s = S()
last = s[-1]
lis = [s]
for i in range(n-1):
    s = S()
    if s in lis or s[0] != last:
        print("No")
        exit()
    else:
        last = s[-1]
        lis.append(s)
print("Yes")

Solution (Python):


import sys

input = sys.stdin.readline
n = int(input())
w = []

for i in range(n):
    w.append(str(input()))

for i in range(n):
    if w.count(w[i]) > 1:
        print("No")
        exit(0)

    if i != n - 1:
        if w[i][-2] != w[i + 1][0]:
            print("No")
            exit(0)


print("Yes")

Solution (Python):
N = int(input())
list = []
result = True
for i in range(N):
    word = input()
    if i > 0:
        chk_word = list[i - 1]
        if chk_word[-1] != word[0]:
            result = False
    list.append(word)
    if list.count(word) > 1:
        result = False
print('Yes' if result else 'No')

Solution (Python):



n = int(input().strip())
ws = []
w = None
ret = 'Yes'
for i in range(n):
    w_ = input().strip()
    if w_ in ws:
        ret = 'No'
    else:
        ws.append(w_)
    if w is None:
        w = w_
        continue
    if w[-1] != w_[0]:
        ret = 'No'
    w = w_
print(ret)

Solution (Python):
import collections

N = int(input())
W = [input() for i in range(N)]
c = collections.Counter(W)

for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        print("No")
        exit()
if len(c) != N:
    print("No")
    exit()
print("Yes")

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

res = 'No'
ok_list = []
for i in range(n-1):
    if siritori_list[i][-1] == siritori_list[i+1][0]:
        ok_list.append('ok')

siritori_set_list = list(set(siritori_list))

if len(siritori_set_list) == n and len(ok_list) == n-1:
    res = 'Yes'

print(res)

Solution (Python):
n = int(input())
ws = [input().rstrip() for _ in range(n)]

ans = len(ws)==len(set(ws))
for pre, pos in zip(ws, ws[1:]):
    ans &= pre[-1]==pos[0]

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

Solution (Python):
N=input("")
N=int(N)
S=[]
f=1
for i in range(1,N+1,1):
    mystr=input("")
    if i>=2:
        if lastchar!=mystr[0]:
            f=0
            break
        if mystr in S:
            f=0
            break

    lastchar=mystr[-1]
    S+=[mystr]
if f==0:
    print("No")
else:
    print("Yes")

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

W = []
for _ in range(N):
    w = input()
    W.append(w)

W_set = set(W)
if len(W_set) != N:
    print('No')
else:
    last = None
    satisfy = True
    for w in W:
        if last == None:
            last = w[-1]
            continue
        else:
            if w[0] != last:
                satisfy = False
                break
            last = w[-1]

    if satisfy:
        print('Yes')
    else:
        print('No')

Solution (Python):
arr=[]
n=int(raw_input())
for i in range(n):
	arr.append(raw_input())
b=[arr[0]]
t=True
for i in range(1,len(arr)):
	if arr[i] not in b and b[-1][-1]==arr[i][0]:
		b.append(arr[i])
	else:
		t=False
		break
print "Yes" if t else "No"

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

bb = []
if len(set(aa)) != len(aa):
    print('No')
else:
    for i in range(n-1):
        if aa[i][-1] == aa[i+1][0]:
            bb.append(True)
        else:
            bb.append(False)
    if all(bb):
        print('Yes')
    else:
        print('No')

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

t = "Yes"

li_uniq = []
for x in W:
    if x not in li_uniq:
        li_uniq.append(x)


if W == li_uniq:
    for i in range(N - 1):
        if W[i][-1] == W[i+1][0]:
            continue
        else:
            t = "No"
else:
    t = "No"

print(t)

Solution (Python):
N = int(input())
W = []
for i in range(N):
    X = input()
    W.append(X)
    if i >= 1:
        if W[i-1][len(W[i-1])-1] != W[i][0]:
            print("No")
            exit()
    for j in range(i):
        if W[i] == W[j]:
            print("No")
            exit()
else:
    print("Yes")

Solution (Python):
N = int(input())
W = [input() for x in range(N)]
counter=0
def isunique(seq):
    return len(seq) == len(set(seq))

if isunique(W) == False:
    print("No")
else:
    for i in range(N-1):
        if W[i][-1]==W[i+1][0]:
            counter += 0
        else:
            counter += 1
    if counter ==0:
        print("Yes")
    else:
        print("No")

Solution (Python):
N = int(input())
used_words = []

pre_word = input()
used_words.append(pre_word)
state = "Yes"


for i in range(N-1):
    W = input()

    if pre_word[-1] != W[0]:
        state = "No"
        break

    for uw in used_words:
        if uw == W:
            state = "No"
            break
    if state == "No":
        break

    used_words.append(W)
    pre_word = W

print(state)

Solution (Python):
from collections import Counter

n = int(input())
words = []
flag = True

for i in range(n):
    w = input()
    if i >= 1:
        if words[-1][-1] != w[0]:
            flag = False
        
    words.append(w)

    
c = Counter(words)

for j in  c.values():
    if j != 1:
        flag = False
        
if flag :
    print('Yes')
else:
    print('No')

Solution (Python):
n=int(input())
w=[input() for _ in range(n)]
j=True
t=w[0][-1]
for i in range(1,n):
    if w[i][0]!=t:
        j=False
    else:
        t=w[i][-1]
from collections import Counter
c=Counter(w)
x=[list(c.items())[i][1] for i in range(len(list(c.items())))]
if max(x)>1:
    j=False
print("Yes" if j else "No")

Solution (Python):
N = int(input())
flag = False
dic = []

word = input()
dic.append(word)

for i in range(N-1):
    word = input()
    if(word not in dic and word[0] == dic[-1][-1]):
        dic.append(word)
    else:
        flag = True
        break
if(flag == True):
    print('No')
else:
    print('Yes')

Solution (Python):
N = input()
a = []
for i in range(int(N)):
    content = input()
    if a.count(content) != 0:
        print("No")
        exit()
    elif len(a) > 0 and a[-1][-1] != content[0]:
        print("No")
        exit()
    else:
        a.append(content)

print("Yes")

Solution (Python):
def is_unique(seq):
    return len(seq) == len(set(seq))


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


for i in range(N-1):
    if a[i][-1:] != a[i+1][0]:
        print("No")
        break
else:
    if is_unique(a) == True:
        print("Yes")
    else:
        print("No")

Solution (Python):
n = int(input())
wl = []
for i in range(n):
    w = input()
    if i != 0:
        wp = wl[-1]
        if w[0] != wp[-1]:
            print("No")
            break
        if w in wl:
            print("No")
            break
    wl.append(w)
else:
    print("Yes")

Solution (Python):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  
 
n = ni()
 
ss = []
for i in range(n):
    ss.append(ns())
 
for i in range(n):
    for j in range(i):
        if ss[i] == ss[j]:
            print("No")
            sys.exit(0)
 
for i in range(n-1):
    if ss[i][-1] != ss[i+1][0]:
        print("No")
        sys.exit(0)
 
print("Yes")

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

if len(S) != len(set(S)):
    print("No")
    
else:
    next_s = S[0][0]
    for s in S:
        if next_s != s[0]:
            print("No")
            break
        
        next_s = s[-1]
    else:
        print("Yes")

Solution (Python):
N=int(input())
mojiretsu=[]
c1=""
c2=""

c3=""
c4=""
for i in range(N):
    mojiretsu.append(input())

for i in range(N):
    c1=mojiretsu[i]
    for j in range(N):
        c2=mojiretsu[j]
        if i!=j:
            if c1==c2:
                print("No")
                exit()

for i in range(N-1):
    c3=mojiretsu[i]
    c3=c3[-1]
    c4=mojiretsu[i+1]
    c4=c4[0:1]
    
    if c3!=c4:
        print("No")
        exit()
        
                
print("Yes")

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

past_words = []
for i in range(n):
    s = input()
    if s in past_words:
        print("No")
        exit(0)
    if past_words and past_words[-1][-1] != s[0]:
        print("No")
        exit(0)
    past_words.append(s)
print("Yes")

Solution (Python):
N = int(input())
W = [input() for i in range(N)]
ans = 0
if len(W) != len(set(W)):
    ans = 1
else:
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            ans = 1
            break

if ans == 0:
    print('Yes')
else:
    print('No')

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

frag = 1
for str in list:
  if list.count(str) != 1:
    frag = 0
for i in range(1,N):
  if list[i - 1][len(list[i - 1]) - 1] != list[i][0]:
    frag = 0
    
if frag == 1:
  print("Yes")
else:
  print("No")

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

print(get_res(words))

Solution (Python):




def main():
    n = int(input())
    w = [input() for i in range(n)]

    w_set = set()
    for i in range(n):
        if i == 0:
            w_set.add(w[i])
        else:
            wi, wii = w[i][-1], w[i-1][0]
            if w[i][0] == w[i-1][-1] and w[i] not in w_set:
                w_set.add(w[i])
            else:
                print("No")
                exit()

    print("Yes")



if __name__ == '__main__':
    main()

Solution (Python):
import sys
N = int(input())
W=[]
for i in range(N):
	W = W +[input()]
for j in range(N-1):
	if W[j][-1]==W[j+1][0]:
		pass
	else:
		print("No")
		sys.exit()
for k in range(N):
	if W.count(W[k])==1:
		pass
	else:
		print("No")
		sys.exit()
print("Yes")

Solution (Python):
N=int(input())
prev=input()
words = [prev]
for i in range(N-1):
  cur = input()
  if cur[0] != prev[-1] or cur in words:
    print('No')
    break
  words.append(cur)
  prev = cur
else:
  print('Yes')

Solution (Python):
n = int(input())
w = []
res = 'Yes'
prev = ''

for i in range(n):
    w.append(input())

for word in w:
    if w.count(word) > 1:
        res = 'No'
        break

for i in range(n):
    if i == 0:
        prev = w[i]
    else:  
        if prev[-1] != w[i][0]:
            res = 'No'
            break
        prev = w[i]
print(res)

Solution (Python):
N = int(input())
L = [ input() for i in range(N)]
tmpl = []
tmp = L[0][0]
res = "Yes"
for l in L:
    if l in tmpl:
        res = "No"
        break
    if l[0] != tmp:
        res = "No"
        break
    tmp = l[-1]
    tmpl.append(l)
   
print(res)

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

flag = 0
word = input()
wordlist = [word]

for i in range(N-1):
    word = input()
    if flag == 1:
        break
    elif word[0] != wordlist[i][-1]:
        flag = 1
        break
    elif word in wordlist:
        flag = 1
        break
    wordlist.append(word)

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

Solution (Python):


N = int(input())
wN = [input() for i in range(N)]

wN2 = list(set(wN))

if len(wN) != len(wN2):
    print('No')
    exit()

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

Solution (Python):


N=int(input())
word=""
wordb=""
flag=0
lis=[]
for i in range(N):
    word=input()
    lis.append(word)
    if i!=0:
        if word[0]!=wordb[len(wordb)-1]:
            flag=1
            break
    wordb=word
for j in range(len(lis)):
    if lis.count(lis[j])>1:
        flag=1
        break
if flag==0:
    print("Yes")
else:
    print("No")

Solution (Python):
def is_unique(seq):
    return len(seq) == len(set(seq))

N = int(input())
word_list = []
flag = True
word = input()
word_list.append(word)
for i in range(1,N):
    word = input()
    check = word_list[i-1]
    if check[-1] == word[0]:
        word_list.append(word)
        if is_unique(word_list) == False:
            flag = False
            break
    else:
        flag = False
        break
if flag == True:
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
a=[input() for i in range(n)]
b=set(a)
c=0
if len(a)!=len(b):print("No")
else:
  for x in range(n-1):
     if a[x][len(a[x])-1]!=a[x+1][0]:c+=1
     else:pass
  if c>0:print("No")
  else:print("Yes")

Solution (Python):


n = int(input())

word_ary = []
word_set = set()

def main():
	for i in range(1, n + 1):
		w = input()
		if i > 1 and word_ary[i - 2][-1:] != w[0]:
			print('No')
			return
		if w in word_set:
			print('No')
			return
		word_ary.append(w)
		word_set.add(w)
	print('Yes')
			
main()

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

flag = True

bw = ''
wl = []
for i in range(N):
    w = input().strip()
    if i != 0:
        if bw[-1] is not w[0]:
            flag = False
        if w in wl:
            flag = False
        if flag is False:
            break
    wl.append(w)
    bw = w

if flag:
    print('Yes')
else:
    print('No')

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

W = []
fg = True

for lop in range(N):
    W.append(input())
    
w = set(W)
if not(len(w) == N):
    fg = False
else:
    mae = W[0]
    for lop in range(1,N):
        if not(mae[-1:] == W[lop][0]):
            fg = False
        mae = W[lop]
if fg :
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
w=[]
dup=False
for _ in range(n):
    s=input()
    if s in w:
        dup=True
    w.append(s)
if dup:
    print('No')

else:
    last=w[0][0]
    for wi in w:
        if last!=wi[0]:
            print('No')
            break
        last=wi[-1]
    else:
        print('Yes')

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

bag = set(W)
zipped = [(W[i-1], W[i]) for i in range(1, len(W))]
valid = len(bag) == len(W) and all(p[-1] == q[0] for p, q in zipped)

print('Yes' if valid else 'No')

Solution (Python):
N = int(input().strip())
sirito_list = []
is_siritori = True
for _ in range(N):
  if not sirito_list:
    sirito_list.append(input().strip())
  else:
    tmp_word = input().strip()
    if tmp_word[0] != sirito_list[-1][-1] or tmp_word in sirito_list:
      print('No')
      is_siritori = False
      break
    else:
      sirito_list.append(tmp_word)
if is_siritori:
  print('Yes')

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

last = None
seen = set()
for _ in range(n):
  w = input()
  if w in seen or (last and last[-1] != w[0]):
    print("No")
    break
  seen.add(w)
  last = w
else:
  print("Yes")

Solution (Python):
import sys
N = int(input())
W = []
for _ in range(N):
    W.append(input())
for i in range(N):
    if W.count(W[i]) >= 2:
        print('No')
        sys.exit()
    elif i < N - 1:
        if not W[i][len(W[i]) - 1] == W[i + 1][0]:
            print('No')
            sys.exit()
print('Yes')

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

check = []
for i in range(len(w)-1):
    if w[i][-1] == w[i+1][0] :
        check.append(True)
    else :
        check.append(False)

if len(w) == len(list(set(w))) and all(check) :
    print("Yes")
else :
    print("No")

Solution (Python):
n = int(input())
w = []
noFlag = 0
for i in range(n):
    tmp = input()
    if tmp in w:
        noFlag = 1
    if not w == []:
        if not tmp[0] == w[-1][-1]:
            noFlag = 1
    w.append(tmp)

if noFlag == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
N=int(input())
W=[]
miss_flag=False
past_W=[]

for i in range(N):
    W.append(str(input()))

for i in range(N):
    
    if W[i] in past_W:
        miss_flag=True
        break
    if i<N-1:
        if W[i][len(W[i])-1]!=W[i+1][0]:
            miss_flag=True
            break    

    past_W.append(W[i])
    

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

Solution (Python):
n = int(raw_input())
a = [raw_input() for i in xrange(n)]

if len(set(a)) != n:
	print "No"
	exit(0)

for i in xrange(1, n):
	if a[i - 1][-1] != a[i][0]:
		print "No"
		exit(0)

print "Yes"

Solution (Python):
import sys
N=int(input())
wordlist=[]
wordbefore=input()
wordlist.append(wordbefore)
for i in range (1,N):
    word=input()
    if word in wordlist:
        print("No")
        sys.exit()
    if wordbefore[len(wordbefore)-1] !=word[0]:
        print("No")
        sys.exit()        
    wordlist.append(word)
    wordbefore=word    
print ("Yes")

Solution (Python):
n = int(input())
a = [input() for i in range(n)]
b = []
b.append(a[0])
res = True
for i in range(1,n):
    if a[i-1][-1] != a[i][0]:
        res = False
        break
    if a[i] in b:
        res = False
        break
    b.append(a[i])

if res:
    print('Yes')
else:
    print('No')

Solution (Python):

n = int(input())
d = [input()]

ret = "Yes"
for _ in range(n-1):
    w = input()
    if w[0]!=d[-1][-1] or w in d:
        ret = "No"
    d.append(w)

print(ret)

Solution (Python):
N = int(input())
W = []
head = ''
ans = "Yes"
for i in range(N):
    W.append(input())
while len(W) != 0:
    word = W[-1]
    W.pop()
    if word in W or (head != '' and word[-1] != head):
        ans = "No"
        break
    head = word[0]
print(ans)

Solution (Python):
def siritori(N, W):
    if len(set(W)) < N:
        return False

    for i in range(N-1):
        word = W[i]
        following_word = W[i+1]

        if word[-1] != following_word[0]:
            return False

    return True

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

if siritori(N, W):
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
memory = set()
end = None
break_flg = False
for i in range(n):
  w = input()
  if w in memory:
    print("No")
    break_flg = True
    break
  start = w[0]
  if end == start or end is None:
    memory.add(w)
    end = w[-1]
  else:
    print("No")
    break_flg = True
    break
if not break_flg:
  print("Yes")

Solution (Python):
n = int(input())
temp = []
for i in range(n):
    temp.append(input())
temp_res = set(temp)
if len(temp) != len(temp_res):
    print("No")
else:
    ans = 0
    for i in range(n-1):
        
        temp_c1 = str(temp[i])
        temp_c2 = str(temp[i+1])
        
        
        
        if temp_c1[-1] == temp_c2[0]:
            ans+=1
        
    if ans == n-1:
        print("Yes")
    else:
        print("No")

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

list = []
result = 'Yes'
for i in range(n):
    if w_list[i] not in list:
        list.append(w_list[i])
    else:
        result = 'No'

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

Solution (Python):
n = int(input())
words = []
for i in range(n):
    words.append(input())
words_uniq = list(set(words))
result = []
if len(words) != len(words_uniq):
    print('No')
else:
    for i in range(1, len(words)):
        if words[i-1][-1] == words[i][0]:
            result.append('Yes')
        else:
            result.append('No')

    if 'No' in result:
        print('No')
    else:
        print('Yes')

Solution (Python):
N = int(input())
W = input()
dict = {W:1}
p = W
ans = 'Yes'
for n in range(N-1):
  W = input()
  if (p[-1] != W[0]) or (W in dict):
    ans = 'No'
    break
  else:
    dict[W] = 1
    p = W
print(ans)

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

w = []
p = []
for i in range(n):
    temp = input()
    w.append(list(temp))
    p.append(temp)

if len(set(p)) != len(p):
    print('No')
    exit()

a = ""
b = w[0][len(w[0]) - 1]
for i in range(1, n):
    a = w[i][0]
    if a != b:
        print('No')
        exit()
    else:
        b = w[i][len(w[i]) - 1]

print('Yes')

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

a = []
for i in range(N):
  a.append(input())
  if i > 0:
    curword = a[i]
    lastword = a[i-1]
    if lastword[len(lastword)-1] != curword[0]:
      print('No')
      exit()
    if curword in a[:len(a)-1]:
      print('No')
      exit()


print('Yes')

Solution (Python):
n = int(input())
w = list(input() for i in range(n))
check = 0
if all(w[i][-1] == w[i+1][0] for i in range(n-1)):
  if len(w) == len(list(set(w))):
    check = 1
    
if check ==1:
  print("Yes")
else:
  print("No")

Solution (Python):
n = int(raw_input())
w = []

for i in range(n):
    tmp = raw_input()
    w.append(tmp)
    

flag = 0
for i in range(n):
    kensa = w[i]
    for j in range(n):
        if(j==i):
            continue
        if(kensa == w[j]):
            flag = 1

for i in range(n):
    if(i==0):
        continue
    if(w[i-1][-1] != w[i][0]):
        flag = 1
            

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

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


def judge_siri():
    L = []
    for i in range(N):
        S = input()
        if S in L:
            return "No"
        if len(L) != 0 and S[0] != L[-1][-1]:
             return "No"
        L.append(S)
    return "Yes"

print(judge_siri())

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

ans = 'Yes'

w = []

for i in range(n):
	a = input()
	if a in w:
		ans = 'No'
	else:
		w.append(a)
b = w[0]
c = w[1:]
for i in c:
	if i[0] == b[-1]:
		b = i
	else:
		ans = 'No'
		break
print(ans)

Solution (Python):
n=int(input())
flag=0
w=[]
used=[]
for _ in range(n):
    w.append(str(input()))
for i in range(n):
    if i==0:
        used.append(w[i])
    else:
        if (w[i] not in used) and (w[i-1])[-1]==(w[i])[0:1]:
            used.append(w[i])
        else:
            print('No')
            flag+=1
            break
if flag>0:
    pass
else:
    print('Yes')

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

flag = 0
words = set()
for i in range(n):
    x = input()
    if i==0:
        y = x[0]
    words.add(x)

    
    
    if not(y[-1] == x[0] and i < len(words)):
        flag = 1
        break
    y = x

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

Solution (Python):
n = int(input())
w = []
for i in range(n):
    w.append(str(input()))
check = 'Yes'
for i in range(n-1):
    a = w[i][-1]
    b = w[i+1][0]
    if a != b:
        check = 'No'
def is_unique(seq):
    seen = []
    unique_list = [x for x in seq if x not in seen and not seen.append(x)]
    return len(seq) == len(unique_list)
if not is_unique(w):
    check = 'No'
print(check)

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

words = []

for i in range(wd_cnt):
    word = input()
    if word in words:
        print('No')
        exit()
    if len(words) > 0 and (word[0] != words[len(words) - 1][-1]):
        print('No')
        exit()
    words.append(word)
print('Yes')

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

ans = 0

if len(set(w_list)) != N:
    print('No')
    exit()
for i in range(1,N):
    if w_list[i-1][-1] == w_list[i][0]:
        ans += 1
if ans == N - 1:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
st = set()
s = []
ok = True
for i in range(n):
  s.append(input())
for i in range(n):
  if s[i] in st:
    ok = False
  if i > 0 and s[i][0] != s[i-1][-1]:
    ok = False
  st.add(s[i])
print("Yes" if ok else "No")

Solution (Python):
N = int(input())
L = []
oldword = input()
L.append(oldword)
for i in range(N-1):
    newword = input()
    if newword[0] == oldword[-1] and newword not in L:
        ans = 'Yes'
        L.append(newword)
        oldword = newword
    else:
        ans = 'No'
        break

print(ans)

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

Solution (Python):

from sys import stdin

ns = lambda: stdin.readline()[:-1] 
ni = lambda: int(stdin.readline()) 
na = lambda: list(map(int, stdin.readline().split())) 

N = ni()

Words = []
w = ns()
last = w[-1]
Words.append(w)
flag = 1
for _ in range(N-1):
    w = ns()
    if w[0] != last:
        flag = 0
    if w in Words:
        flag = 0
    last = w[-1]
    Words.append(w)

if flag == 1:
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
w = [input() for i in range(N)]
a=[w[0]]
for i in range(N-1):
   if w[i+1] in a:
       print('No')
       exit()
   else:
       if w[i][-1] ==w[i+1][0]: 
           a.append(w[i+1])
       else:
           print('No')
           exit()
print('Yes')

Solution (Python):
import sys

n=int(input())

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

prev=[]
for i in range(n):
    x=w[i]
    if x in prev:
        print('No')
        sys.exit()
    elif i>0 and x[0]!=w[i-1][-1]:
        print('No')
        sys.exit()
    else:
        prev.append(x)
print('Yes')

Solution (Python):
N = int(input())
d = {}
last = None
flag = True

for _ in range(N):
    word = input()
    if word in d.keys():
        flag = False
    else:
        d[word] = 1

    if last is not None and last != word[0]:
        flag = False
    else:
        last = word[-1]

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

Solution (Python):
from sys import stdin, stdout
from collections import Counter

input = lambda: stdin.readline().rstrip()


def main():
    N = int(input())
    W = stdin.read().splitlines()

    word = Counter(W)
    last = W[0][-1]
    for i in range(1, N):
        s = W[i]
        if word[s] > 1 or s[0] != last:
            print('No')
            return
        last = s[-1]
    print('Yes')

main()

Solution (Python):
import sys
N = int(input())
W = [input() for _ in range(N)]
d = set()
last = ""
for i in range(N):
    if W[i] in d:
        print("No")
        sys.exit()
    if last != "" and last != W[i][0]:
        print("No")
        sys.exit()
    last = W[i][-1]
    d.add(W[i])

print("Yes")