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):
import io
import sys
def solve(lista):    
    listb = []
    hantei = "true"
    for i in lista:
        if i not in listb:
            listb.append(i)
        else:
            hantei = "false"
    for i in range(len(listb)-1):
        if listb[i][-1] != listb[i+1][0]:
            hantei = "false"
    if hantei == "true":
        return("Yes")
    else:
        return("No")

def readQuestion():
    line1 = sys.stdin.readline().rstrip()
    lista = []
    for i in range(int(line1)):
        line2 = sys.stdin.readline().rstrip()
        lista.append(line2)
    return (lista)

def main():
    a = readQuestion()
    answer = solve(a)
    print(answer)
    
if __name__ == '__main__':
    main()

Solution (Python):
def solve(string):
    ins = string.split("\n")
    if len(set(ins[1:])) < int(ins[0]):
        return "No"
    for _p, _n in zip(ins[1:], ins[2:]):
        if _p[-1] != _n[0]:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    tmp = [str(n)]
    for _ in range(n):
        tmp.append(input())
    print(solve("\n".join(tmp)))

Solution (Python):
a=int(input())
b=[]
for i in range(a):
    b.append(input())
    if i!=0:
        if b[i-1][-1]!=b[i][0]:
            print("No")
            exit()
        for j in range(i-1):
            if b[j]==b[i]:
                print("No")
                exit()
print("Yes")

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

if len(b) != len(set(b)):
    print("No")
    sys.exit()

for x in range(a):
    if b[x]!=b[a-1]:
        
        if b[x][len(b[x])-1] != b[x+1][0]:
            print("No")
            break


else:
    print("Yes")

Solution (Python):
N = int(input())
W = []
Ws = []
first = []
count = 0
for i in range(N):
    W.append(input())
    Ws.append(list(W[i]))
else:
    first.append(len(W))
    first.append(len(set(W)))
    if first[0] != first[1]:
        print("No")
    else:
        for i in range(N-1):
            maxw = len(Ws[i]) - 1
            if Ws[i][maxw] == Ws[i + 1][0]:
                count += 1
        else:
            if count == N - 1:
                print("Yes")
            else:
                print("No")

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

if len(word) != len(set(word)):
	print("No")
	exit()

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

print("Yes")

Solution (Python):



n = int(input())
words = [input() for _ in range(n)]

success = True

if len(set(words)) != len(words):
    success = False

if success:
    last = words[0][0]
    for word in words:
        if last[-1] != word[0]:
            success = False 
            break
        last = word

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

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


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

    for i in range(n-1):
        if w[i][-1] != w[i + 1][0] or not is_unique(w):
            valid = False
            break
        else:
            valid = True

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


if __name__ == '__main__':
    main()

Solution (Python):

 
 
def is_unique(seq):
    return len(seq) == len(set(seq))
 
 
def main():
    n = int(input())
    shiri = True
 
    w = []
    for i in range(n):
        w.append(input())
 
    for i in range(n-1):
        if w[i][-1] != w[i + 1][0]:
            shiri = False
            break
 
    if not is_unique(w):
        shiri = False
 
    if shiri:
        print('Yes')
    else:
        print('No')
 
 
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
Ws = [input() for i in range(N)]

ret = "Yes"
if len(Ws) != len(list(set(Ws))):
    ret = "No"
    
for i in range(N-1):
    if Ws[i][-1] != Ws[i+1][0]:
        ret = "No"
    
    
print (ret)

Solution (Python):
N = int(input())
Ws = [input() for i in range(N)]

if len(Ws) != len(list(set(Ws))):
    print("No")
    exit(0)

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

print("Yes")

Solution (Python):
n=int(input())
s=[input()for _ in[0]*n]
f=0
for i in range(1,n):
    f+=s[i-1][-1]!=s[i][0]
print("No"if f or len(set(s))<n else"Yes")

Solution (Python):
def main():
    N = int(input())
    W = [input() for _ in range(N)]
 
    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]
 
    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")
 
 
if __name__ == '__main__':
    main()

Solution (Python):
import math


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

    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]

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


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
words = [input() for _ in range(N)]
a = words[0]
if len(set(words)) != N:
  print("No")
  exit()
for i in range(1, N):
  b = words[i]
  if a[-1] != b[0]:
    print("No")
    exit()
  else:
    a = b

print("Yes")

Solution (Python):
N = int(input())
pre_w = input()
his = [pre_w]
for i in range(N-1):
    w = input()
    if pre_w[-1] != w[0]:
        print("No")
        break
    elif w in his:
        print("No")
        break
    his.append(w)
    pre_w = w
    if i == N-2:
        print("Yes")

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

Solution (Python):
n = int(input())
w0 = str(input())
list = [w0]
count = 0
for i in range(n-1):
  w = str(input())
  list.append(w)
  if len(list) != len(set(list)) or w0[-1:] != w[:1]:
    print("No")
    count = 1
    break
  w0 = w
if count == 0:
  print("Yes")

Solution (Python):
n = int(input())
mojilist = []
ans = "No"
for x in range(n):
    moji = input()
    if moji in mojilist:
        break
    mojilist.append((moji))

if len(mojilist) == n:
    mae = list(mojilist[0])
    for x in range(1, n):
        tugi = list(mojilist[x])
        if mae[-1] != tugi[0]:
            break
        else:
            mae = tugi
        if x == n-1:
            ans = "Yes"

print(ans)

Solution (Python):
N = int(input())
listS = [input() for i in range(N)]
ans = "Yes"
for j in range(1, N):
    if listS.count(listS[j]) == 1 and listS[j - 1][-1] == listS[j][0]:
        continue
    else:
        ans = "No"
        break

print(ans)

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

rule_length = True
rule_2time = True
rule_startEnd = True

for i in range(N):
    word = input()
    if 1 > len(word) or len(word) > 10:
         rule_length = False
    if word in words:
        rule_2time = False
    if i !=0 and words[-1][-1] != word[0]:
        rule_startEnd = False    
    words.append(word)

if rule_length and rule_2time and rule_startEnd:
    print('Yes')
else:
    print('No')

Solution (Python):
flag = "Yes"
N = int(input())
W = input()
words = [W]
while len(words) < N:
    a = input()
    if W[-1] == a[0] and (a not in words):
        W = a
        words.append(a)
    else:
        flag = "No"
        words.append(a)

    

print(flag)

Solution (Python):
n = int(input())
s = input()
W = set()
W.add(s)

for i in range(n-1):
  ns = input()
  if s[-1] != ns[0] or (ns in W):
    print('No')
    break
  s = ns
  W.add(ns)
else:
  print('Yes')

Solution (Python):
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

arr=[]
for i in range(1,1+n):
    
    arr.append(arr_data[i][0])

chkflg=True
if len(arr)!=len(set(arr)):
    chkflg=False
    
for i in range(0,n-1):
    
    if arr[i][-1]!=arr[i+1][0]:

        chkflg=False
        break
        
print("Yes" if chkflg else "No")

Solution (Python):
num_word = int(input())
word_list=[]
word_list = [str(input()) for i in range(num_word)] 
 
word_list_temp=[]
for j in range(len(word_list)):
  if j == len(word_list)-1:
    print ("Yes")
    break
  else:
    old_word=word_list[j]
    old_word_sep=list(old_word)
    word_list_temp.append(old_word)
    new_word=word_list[j+1]
    new_word_sep=list(word_list[j+1])
    if old_word_sep[len(old_word)-1]!=new_word_sep[0]:
      print ("No")
      break
    elif new_word in list(word_list_temp):
      print ("No")
      break
    else:
      continue

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

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

Solution (Python):
N=int(input())
last = input()
wds = set([last])
res = "Yes"
for i in range(N-1):
    wd = input()
    if wd in wds or last[-1]!=wd[0]: 
        res = "No"
        break
    last = wd
    wds.add(wd)
print(res)

Solution (Python):


n = input()
n = int(n)

w = []
for i in range(n):
    _w = input()
    w.append(_w)
ans = "Yes"
for i in range(0,len(w)-1):
    for j in range(i+1,len(w)):
        if w[i] == w[j]:
            ans = "No"
for i in range(0,len(w)-1):
    if w[i][-1] != w[i+1][0] :
        ans ="No"

print(ans)

Solution (Python):
N = int(input())
word_list = []
yes_or_no = []
for i in range(N):
    w = str(input())
    if w not in word_list:
        word_list.append(w)
    elif w in word_list:
        yes_or_no.append('No')
        
    if i == 0:
        continue
    else:
        if w[0] == word_list[i-1][-1]:
            yes_or_no.append('Yes')
        else:
            yes_or_no.append('No')
if 'No' in yes_or_no:
    print('No')
else:
    print('Yes')

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

stock = []
last = W[0][0]

for i in range(0,len(W)):
    
    if W[i] in stock:
        print('No')
        break
    
    if W[i][0] != last:
        print('No')
        break
    stock.append(W[i])
    last = W[i][-1]
    
    if i+1 == len(W):
        print('Yes')

Solution (Python):
list_length = int(input())
word_list = list()
for i in range(list_length):
  w = input()
  try:
    if w[0] != word_list[-1][-1]:
      break                
  except IndexError:
  	pass
  word_list.append(w)

if len(set(word_list)) == list_length:
  print('Yes')
else:
  print('No')

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

n = int(input())
w = [input().rstrip() for _ in range(n)]
w_alter = []



for i in range(n-1):
    w_alter.append(w.pop(0))
    if w_alter[i] in w:
        
        print("No")
        exit()
    if w_alter[i][-1] != w[0][0]:
        
        
        print("No")
        exit()

print("Yes")

Solution (Python):
import sys
N = int(input())
s = []
for i in range(N):
    s.append(input())
for i, s0 in enumerate(s):
    for j, s1 in enumerate(s):
        if i != j and s0 == s1:
            print('No')
            sys.exit()
s0 = s[0]
for i in range(1, len(s)):
    s1 = s[i]
    if s0[-1] != s1[0]:
        print('No')
        sys.exit()
    s0 = s1
print('Yes')

Solution (Python):
n = input()
d = set()
pre = ""
for i in range(n):
    s = raw_input()
    if s in d:
        print "No"
        exit()
    if pre == "" or pre[-1] == s[0]:
        d.add(s)
        pre = s
    else:
        print "No"
        exit()
print "Yes"

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

ok = True

for i in range(N-1):
    w = input()
    if ok:
        ok = ok and (not w in ws) and (w[0] == ws[-1][-1])
    ws.append(w)

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

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

valid  = len(set(w)) == len(w) and \
         all(a[-1] == b[0] for a, b in zip(w, w[1:]))

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

Solution (Python):
import sys
cap=int(input())
word_list=[str(input()) for i in range(cap)]


li_uniq = list(set(word_list))
if( not len(li_uniq)==len(word_list) ):
    print ('No')
    sys.exit()
lastc=word_list[0][0:1]
for string in word_list:
    if(not string[0:1]==lastc):
        print('No')
        sys.exit()
    lastc = string[-1:]
print('Yes')

Solution (Python):
count = input()
inputed = []
last = ""
judge = "Yes"
for i in range(int(count)):
    new_inputed = input()
    if i != 0 and (new_inputed[0] != last or new_inputed in inputed):
        judge = "No"
    last = new_inputed[-1]
    inputed.append(new_inputed)
print(judge)

Solution (Python):
N = int(input())
a = [input() for i in range(N)]

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

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

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

word_set = set()

chaine = []
for i in range(n):
  w = input()
  word_set.add(w)
  if chaine == []: 
    chaine.append( w[0] + w[-1] )
  else:
    if chaine[-1][-1] == w[0]:
      chaine.append( w[0] + w[-1] )

if len(word_set) == n and len(chaine) == n:
  print('Yes')
else:
  print('No')

Solution (Python):
N = int(input())
lastWord = input()
unique = {lastWord}

for i in range(N-1):
    nextWord = input()
    if nextWord in unique or lastWord[-1] != nextWord[0]:
        print("No")
        raise SystemExit
    lastWord = nextWord
    unique.add(nextWord)

print("Yes")

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

words = []

for i in range(length):
  words.append(input())
  
flg = 'Yes'
pre = words[0]
for word in words[1:]:
  if pre[-1] != word[0]:
    flg = 'No'
  pre = word

if len(words) != len(set(words)):
  flg = 'No'
  
print(flg)

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

ws = [input()]
f = True

for _ in range(n-1):
    w = input()
    if w not in ws and ws[-1][-1] == w[0]:
        ws.append(w)
    else:
        f = False
        break

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

Solution (Python):
n=int(input())
line=[input() for i in range(n)]
if n==len(set(line)):
    for i in range(n-1):
        if not line[i][-1]==line[i+1][0]:
            print("No")
            break
    else:print("Yes")
else:print("No")

Solution (Python):
N=int(input())
a=[input() for i in range(N)]
if len(set(a))!=N:
	print("No")
	exit()
for i in range(1,N):
	if a[i-1][-1]!=a[i][0]:
		print("No")
		exit()
print("Yes")

Solution (Python):
n = int(input())
arr = [input()]
for _ in range(n-1):
    w = input()
    s = arr[-1][-1]
    if w in arr or s != w[0]:
        print("No")
        exit()
    arr.append(w)
print("Yes")

Solution (Python):
ans = "Yes"
inp = int(input())
s = [];
shiri = input()
s.append(shiri)

for i in range(inp-1):
    shiri = input()
    
    shiri_s = list(shiri)
    shiri_s = shiri_s[0]
    
    s_e = list(s[-1])
    s_e = s_e[-1]
    if shiri in s or shiri_s != s_e:
        ans = "No"
        break
    s.append(shiri)
    
print(ans)

Solution (Python):

import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return input()
def n():
    return int(input())

N = n()
che = 0
name = []
name.append(s())
for i in range(1,N):
    tmp = s()
    if tmp in name or tmp[0] != name[-1][-1]:
        print('No')
        exit()
    else:
        name.append(tmp)
print('Yes')

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

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

print("Yes")

Solution (Python):
result = True
words = []
n = int(input())

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

for i in range(n-1):
    word = words.pop(0)

    if word[-1] != words[0][0] or word in words:
        result = False
        break

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

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

if len(set(w)) == n:
	for i in range(n-1):
		if w[i][-1] != w[i+1][0]:
			print("No")
			exit()
	print("Yes")
else:
	print("No")

Solution (Python):
import sys
n = int(input())
ss = [input()]
for i in range(n-1):
  s = input()
  if s in ss:
    print("No")
    sys.exit()
  if s[0]!=ss[-1][-1]:
    print("No")
    sys.exit()
  ss.append(s)
print("Yes")

Solution (Python):
N = int(input())
W = []
W.append(input())
for _ in range(N-1):
    W.append(input())
    if (W[-1] in W[:-2]) or (W[-1][0] != W[-2][-1]):
        print("No")
        break
else:
    print("Yes")

Solution (Python):
N = input()

dic = {}

bf = raw_input()
dic[bf] = 1

frag = True

for i in range(N - 1):
    nw = raw_input()
    if bf[len(bf) - 1] != nw[0] or nw in dic:
        frag = False
    else:
        dic[nw] = 1
        bf = nw

if frag:
    print "Yes"
else:
    print "No"

Solution (Python):
N = int(input())
W = []
W.append(input())
for _ in range(N-1):
    W.append(input())
    if W[-1] in W[:-2]:
        print("No")
        break
    if W[-1][0] != W[-2][-1]:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
n = int(input())
lst = []
dlst = []
ans = "Yes"
for i in range(n):
    lst.append(input())
st = set(lst)
for i in st:
    if lst.count(i) != 1:
        ans = "No"
for i in range(1, n):
    if lst[i-1][-1] != lst[i][0]:
        ans = "No"
print(ans)

Solution (Python):
n=int(input())
li=[]
for i in range(0,n):
    n=input()
    li.append(n)
flag=0
chck=1
temp=li[0]
for j in li:
    t=li.count(j)
    if(t>1):
        flag=1
        break
    if(chck!=1):
        p=len(temp)
        ch=temp[p-1]
        
        ch1=j[0]
        if(ch==ch1):
            flag=0
            temp=j
        else:
            flag=1
            break
    chck=chck+1
if(flag==1):
    print('No')
else:
    print('Yes')

Solution (Python):



a = int(raw_input())


i=0
l = [0]*a
for i in range(0, a):
    b = str(raw_input())
    l[i] = list(b)


cnt = 0




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 is_unique(l)== True:
    
    if all(l[i][-1] == l[i+1][0] for i in range(a-1)):
        print "Yes"
    else:
        print "No"
else:
    print "No"

Solution (Python):
num      = int(input())
is_valid = True
words    = []
words.append(input())
for i in range(1, num):
    word = input()
    words.append(word)
    if words[i-1][-1] != word[0]:
        print('No')
        quit()

if len(words) != len(set(words)):
    print('No')
else:
    print('Yes')

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

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

Solution (Python):

n=int(input())
l=[input() for _ in range(n)]
la=l[0][-1]
flag=True

for i in range(1,n):
    if la==l[i][0]:
        la=l[i][-1]
    else:
        flag=False
        break

if len(set(l))!=n:
    flag=False
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
words = []
flag = True

for i in range(n):
    word = input()
    if word in words:
        flag = False
        break
    else:
        words.append(word)
if not flag:
    print("No")
    quit()

for i in range(1, n):
    if words[i-1][-1:] != words[i][0:1]:
        flag = False

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

Solution (Python):
length = int(input())
wset = set()
flag = 1
word = input()
wset.add(word)
for i in range(length - 1):
	add = word[-1]
	word = input()
	if add != word[0] or word in wset:
		flag=0
		break
	wset.add(word)
if flag == 1:
	print('Yes')
else:
	print('No')

Solution (Python):



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


def main():
    n = int(input())
    shiri = True

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

    for i in range(n-1):
        if w[i][-1] != w[i + 1][0]:
            shiri = False
            break

    if not is_unique(w):
        shiri = False

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


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
counter = 0
old_list = []
for i in range(N):
    word = input()
    if i == 0:
        old = word
        counter += 1
        old_list.append(word)
    else:
        if old[-1] == word[0] :
            if not (word in old_list):
                counter +=1
        old_list.append(word)
        old = word
if counter == N:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
W = input()
used = {W:True}
prev = W
for i in range(N-1):
    W = input()
    if W in used.keys() or W[0] != prev[-1]:
        print("No")
        break
    used[W] = True
    prev = W
else:
    print("Yes")

Solution (Python):
N=int(input())
list=[input() for i in range(N)]
list2=[list[i].endswith(list[i+1][0]) for i in range(N-1)]
if False in list2 or len(list)!=len(set(list)):
    print("No")
else:
    print("Yes")

Solution (Python):


N = int(input())
Word = []
flag = True
for i in range(N):
    a = list(input())
    if a in Word:
        flag = False
        break
    Word.append(a)
if flag:
    for i in range(N-1):
        if Word[i][len(Word[i])-1] != Word[i+1][0]:
            flag = False
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
N=int(input())
W=[]
for _i in range(N):
    W.append(input())
if(sorted(W)!=sorted(list(set(W)))):
    print("No")
else:
    for i in range(len(W)-1):
        if(W[i][-1]!=W[i+1][0]):
            print("No")
            break
    else:
        print("Yes")

Solution (Python):
a = int(input())
strings =[input() for i in range(a)]

b = 0
c = 1



if len(strings) == len(set(strings)):
    while c <= a - 1:
        finish = strings[b][-1:]
        start = strings[c][0:1]
        if finish == start:
            b += 1
            c += 1
            if c == a:
                print("Yes")
        else:
            print("No")
            break
else:
    print("No")

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

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

h = []
for i in range(1,N):
    h.append(W[i][0])
t = []
for i in range(N-1):
    t.append(W[i][-1])    

flg = 1
for i in range(N-1):
    if h[i] != t[i]: flg = 0
W.sort()
for i in range(N-1):
    if W[i] == W[i+1]: flg = 0

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

Solution (Python):
import sys
if __name__ == '__main__':
    N = int(input())
    W = [str(input()) for _ in range(N)]
    if len(W) != len(set(W)):
        print('No')
        sys.exit(0)
    for i in range(1,N):
        if W[i-1][-1] != W[i][0]:
            print('No')
            sys.exit(0)
    print('Yes')

Solution (Python):
s = set()
pv = ""

fail = False
N = input()
for _ in xrange(N):
    w = raw_input()
    if w in s or (pv and w[0] != pv[len(pv)-1]):
        fail=True
        break
    s.add(w)
    pv = w
if fail:
    print "No"
else:
    print "Yes"

Solution (Python):
n=int(input())
w1=input()
detalist={w1}
last=w1
flag=True
for _ in [0]*(n-1):
    wi=input()
    if wi in detalist or wi[0] != last[-1]:
        flag=False
        break
    last=wi
    detalist.add(wi)
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
s=set()
yn=1
w=input()
s.add(w)
for i in range(n-1):
    a=w[-1]
    w=input()
    
    if a!=w[0] or w in s:
        yn=0
        break
    s.add(w)
if yn==1:
    print('Yes')
else:
    print('No')

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

tmpW = input()
past = set()
past.add(tmpW)
flag = True
for i in range(N - 1):
    W = input()
    if(tmpW[-1:] != W[0:1]):
        flag = False
    elif(W in past):
        flag = False
    tmpW = W

    past.add(W)
    

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

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

for n in range(N):
    a = input()
    l.append(a)

l_uniq = list(set(l))

if len(l) == len(l_uniq):
    for i in range(0, N-1):
        if l[i+1][0] != l[i][-1]:
            print("No")
            break
    else:
        print("Yes")
else:
    print("No")

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

for n in range(N):
    a = input()
    l.append(a)

l_uniq = list(set(l))

if len(l) == len(l_uniq):
    for i in range(0, N-1):
        if l[i+1][0] != l[i][-1]:
            print("No")
            break
    else:
        print("Yes")
else:
    print("No")

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

    r = input()
    s = set()
    s.add(r)
    r = r[-1]
    for i in range(n - 1):
        w = input()
        if w in s or r != w[0]:
            print('No')
            return
        s.add(w)
        r = w[-1]
    print('Yes')

main()

Solution (Python):
n = int(input())
w = [input() for i in range(n)]
l = list(set(w))
if len(l) != n:
    print("No")
    quit()
a = w[0][-1]
for i in range(1,n):
    if a != w[i][0]:
        print("No")
        quit()
    a = w[i][-1]
print("Yes")

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

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

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

ans = "Yes"

for i in range(N - 1):
    if (W[i][-1] != W[i+1][0]):
        ans = "No"

if (len(W) != len(set(W))):
    ans = "No"

print(ans)

Solution (Python):
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)

n = int(input())
tango = []
for i in range(n):
    tango.append(list(input()))
    
rule1 = True
rule2 = True

for i in range(n-1):
    if tango[i][len(tango[i])-1] != tango[i+1][0]:
        rule1 = False

if not is_unique(tango):
    rule2 = False
    
if rule1 and rule2:
    print('Yes')
else:
    print('No')

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

bigram = [(w[i-1], w[i]) for i in range(1, len(w))]
valid  = len(set(w)) == len(w) and \
         all(a[-1] == b[0] for a, b in bigram)

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

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

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

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

    tail = w[-1]

print('Yes')

Solution (Python):
n = int(input())
a = [input() for i in range(n)]
for i in range(n):
    num  = a.count(a[i])
    if num > 1:
        print('No')
        exit()
for i in range(n-1):
    if a[i][-1] == a[i+1][0]:
        continue
    else:
        print('No')
        exit()
print('Yes')

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

W = []
Se = set()
for i in range(N):
  st = input()
  W.append(st)
  Se.add(st)
  
if len(Se) != N:
  print("No")
  exit(0)

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

print("Yes")

Solution (Python):
"""
B - Shiritori
しりとりを判定
条件は、
まだ発言なし
頭とお尻一致
"""

N = int(input())

says = []
for part in range(N):
    says.append(input())

says_unique = []
for say in says:
    
    if say in says_unique:
        print("No")
        break
    
    
    if len(says_unique) == 0:
        says_unique.append(say)
    else:
        if say[0] == says_unique[-1][-1]:
            says_unique.append(say)
        else:
            print("No")
            break
else:
    print("Yes")

Solution (Python):

import sys

n=int(raw_input())
s=[]
for i in xrange(n):
 s.append(raw_input())
if len(s)!=len(set(s)):
 print 'No'
 sys.exit()
for i in xrange(n-1):
 if s[i][-1]!=s[i+1][0]:
  print 'No'
  sys.exit()
print 'Yes'

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

if len(word) > len(set(word)):
    print('No')
else:
    success = True
    for i in range(N-1):
        if word[i][-1] != word[i+1][0]:
            success = False
            print('No')
            break
    if success:
        print('Yes')

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

words.append(input())
ans = True
for _ in range(N-1):
    w = input()
    l = words[-1]
    ans &= (not w in words)
    ans &= (w[0] == l[-1])
    words.append(w)

print(["No", "Yes"][ans])

Solution (Python):
from itertools import tee
N = int(input())
w0, w1 = tee((input() for _ in range(N)), 2)

words = {next(w1)}
flag = 'Yes'
for a,b in zip(w0,w1):
  if a[-1] != b[0] or b in words:
    flag = 'No'
  words.add(b)

print(flag)

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

Solution (Python):
N = int(input())
W = []
flag = "Yes"
last_chara = ''
for i in range(N):
  now_W = input()
  www = list(now_W)
  if i != 0:
    if www[0] != last_chara:
      flag = "No"
      break
  if now_W in W:
    flag = "No"
    break
  W.append(now_W)
  last_chara = www[-1]
print(flag)

Solution (Python):
N = int(input())
s = set()
pr = None
ok = 1
for i in range(N):
    w = input()
    if pr and pr != w[0]:
        ok = 0
    if w in s:
        ok = 0
    pr = w[-1]
    s.add(w)
print('Yes'*ok or'No')

Solution (Python):
n = int(input())
w = [input() for _ in range(n)]
valid = len(w) == len(set(w))
for i in range(1, n):
    valid &= w[i][0] == w[i - 1][-1]
print('Yes' if valid else 'No')