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())
w = [input() for i in range(n)]
ans1=""
for i in range(n-1):
    if w[i][-1]!=w[i+1][0]:
        ans1="No"
if len(w)==len(set(w)):
    ans2="Yes"
else:
    ans2="No"
if ans1=="" and ans2=="Yes":
    ans="Yes"
else:
    ans="No"
print(ans)

Solution (Python):
N = int(input())
w = input()
W = []
W.append(w)
z = w[-1]
for i in range(N-1):
    w = input()
    if z != w[0] or W.count(w)!=0:
        ans = 'No'
        break
    W.append(w)
    z = w[-1]
    ans = 'Yes'
print(ans)

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

for i in range(N-1):
  wd = input()
  if wd in w or w[-1][-1:] != wd[0]:
    print('No')
    exit()
  else:
    w.append(wd)
  
print('Yes')

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

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


w = [list(x) for x in Words]

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



if len(set(Words)) == n:
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
W = [input() for i in range(N)]
S = set([W[0]])
ans = "Yes"
for i in range(1,N):
  if W[i] in S:
    ans = "No"
  if W[i][0] != W[i-1][-1]:
    ans = "No"
  S.add(W[i])
print(ans)

Solution (Python):
N = int(input())
W = [input() for i in range(N)]
L = [W[0]]
ans = "Yes"
for i in range(1,N):
  if W[i] in L:
    ans = "No"
  if W[i][0] != W[i-1][-1]:
    ans = "No"
  L.append(W[i])
print(ans)

Solution (Python):
import collections
N = int(input())
ws =[input() for i in range(N)]
word = collections.defaultdict(int)
flag = True
for i in range(N-1):
    if ws[i][-1] != ws[i+1][0]:
        flag = False
        break
    word[ws[i]] += 1
word[ws[-1]] += 1
for n in word.values():
    if n >= 2:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

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

Solution (Python):
n = int(input())
s = input()
s_list = [s]
for i in range(n-1):
    tem = input()
    if s[-1] == tem[:1] and not tem in s_list:
        s = tem
        s_list.append(s)
        continue
    print("No")
    exit()
print("Yes")

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

W = input()

last = W[-1]
word_list = {W}
result = 'Yes'

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

    if W[0] == last:
        last = W[-1]
    else:
        result = 'No'

    if W in word_list:
        result = 'No'
    else:
        word_list.add(W)

print(result)

Solution (Python):
n=int(input())
l=[]
for i in range(n):
	s=input()
	if len(l)!=0 and (l[-1][-1]!=s[0] or s in l):
		print('No')
		break
	l.append(s)
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(set(W)) != n:
    ans = "No"
print(ans)

Solution (Python):
n = int(input())
w = [input().rstrip() for i in range(n)]
use = [w[0]]
for i in range(1,n):
  if w[i][0] == w[i-1][-1] and w[i] not in use:
    use.append(w[i])
  else:
    print('No')
    exit()
print('Yes')

Solution (Python):
n = int(input())
data = [input().rstrip() for _ in range(n)]
used = [data[0]]
 
for i in range(1, n):
    if data[i][0] == data[i - 1][-1] and data[i] not in used:
        used.append(data[i])
    else:
        print("No")
        exit()
print('Yes')

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

Solution (Python):

n = int(input())
data = [input().rstrip() for _ in range(n)]
used = [data[0]]

for i in range(1, n):
    if data[i][0] == data[i - 1][-1] and data[i] not in used:
        used.append(data[i])
    else:
        print("No")
        exit()
        
print("Yes")

Solution (Python):

n = int(input())
data = [input().rstrip() for _ in range(n)]
used = [data[0]]

for i in range(1, n):
    if data[i][0] == data[i - 1][-1] and data[i] not in used:
        used.append(data[i])
    else:
        print("No")
        break
        
if len(used) == n:
    print("Yes")

Solution (Python):
N = int(input())
W = [input().rstrip() for _ in range(N)]
W_set = set(tuple(W))
for i in range(N-1):
  if W[i][-1] == W[i+1][0]:
    continue
  else:
    print("No")
    exit()
for word in W_set:
    if W.count(word) != 1:
        print("No")
        exit()
print("Yes")

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

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

for i in range(N-1):
  
  if words[i][-1] != words[i+1][0]:
    flag=0

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

Solution (Python):
n=int(input())
lstw=[input() for _ in range(n)]
string=[]
flag=False
cnt=0

if len(lstw)==1:
    flag=True
elif len(lstw)==len(set(lstw)):
    for i in range(n):
        string.append(lstw[i][:1])
        string.append(lstw[i][-1:])
    for i in range(1,n):
        if string[2*i-1]==string[2*i]:
            cnt+=1
    if cnt==(n-1):
        flag=True

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

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

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

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

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

Solution (Python):
N = int(input())
W = [input() for _ in range(N)]
ans = "Yes"
for i in range(1, N):
	if W[i] in W[: i] or W[i][0] != W[i - 1][-1]:
		ans = "No"
		break
print(ans)

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

def endgame():
    print("No")
    exit()

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

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

for i in range(N):
    roop = True
    for j in range(i + 1, N):
        if W[i] == W[j]:
            flag = False
            roop = False
    if not roop:
        break

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

Solution (Python):

def main():
    num = int(input())
    data = [input() for i in range(num)]

    if len(data) != len(set(data)):
        print('No')
    else:
        flg = 1
        for i in range(num - 1):
            if data[i + 1][0] != data[i][-1]:
                flg = 0
                break

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




if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
flag = "Yes "
words = []
for i in range(n):
    words.append(input())
beforeW = ""
counter = 0
for w in words:
    if beforeW == "":
        beforeW = w
        continue
    else:
        tailChar = beforeW[-1:]
        headChar = w[0]
        if tailChar == headChar:
            if words.count(w) == 1:
                beforeW = w
                continue
            else:
                flag = "No "
                break
        else:
            flag = "No "
            break
print(flag)

Solution (Python):
import sys

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


jud = ''
strlist = []
for string in s:
    pre = string[0]
    suf = string[-1]
    if string in strlist:
        print('No')
        sys.exit()

    if jud == '':
        jud = suf
    else:
        if pre != jud:
            print('No')
            sys.exit()
        else:
            jud = suf
    strlist.append(string)
print('Yes')

Solution (Python):
N = int(input())
list = []
bool = True

for i in range(N):
    list.append(input())
if len(set(list)) != len(list):
    bool = False
else:
    for i in range(N - 1):
        if list[i][-1] != list[i+1][0]:
            bool = False

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

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

for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        print("No")
        quit()
for j in range(n):
    if w.count(w[j]) != 1:
        print("No")
        quit()
print("Yes")

Solution (Python):
N = int(input())
w_list = [""]*N
is_cor = True
for i in range(N):
  w_list[i] = input()
for i in range(N-1):
  b = w_list.copy()
  b[i] = ""
  if w_list[i][len(w_list[i])-1] != w_list[i+1][0] or w_list[i] in b:
    print("No")
    is_cor = False
    break
if is_cor:
  print("Yes")

Solution (Python):
N = int(input())
M = [0]*N
for i in range(N):
    M[i] = input()

check = 0
for i in range(N-1):
    if M[i][-1] != M[i+1][0]:
        check = 1

if len(M) != len(set(M)):
    check = 1
if check == 1:
    print("No")
else :
    print("Yes")

Solution (Python):
n=int(input())
ans="Yes"
A=[]
w=input()
for i in range(n-1):
  A.append(w)
  ww=input()
  if ww in A or w[-1]!=ww[0]:
    ans="No"
  w=ww
print(ans)

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

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

for i, k in enumerate(W):
    if i == 0:
        continue
    
    if W.count(k) != 1:
        print('No')
        exit()
    elif k[0] != W[i-1][-1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
N=int(input())
N-=1
w=input()
f=w[-1]
word={w}
for i in range(N):
    w=input()
    ini=w[0]
    if w in word:
        print("No")
        quit()
    if ini!=f:
        print("No")
        quit()
    word.add(w)
    f=w[-1]
print("Yes")

Solution (Python):
n = int(input())
W = []
K = []
ans = "Yes"
for i in range(n):
    W.append(input())



for i in range(n-1):
    if W[i] in K:
        ans = "No"
        break

    K.append(W[i])

    if W[i][-1] != W[i+1][0]:
        ans = "No"
        break

if W[-1] in K:
    ans = "No"

print(ans)

Solution (Python):
n = int(input())
new_w = input()
w = [new_w]
w_str = list(new_w)
f = False
k = False
final_w = w_str[-1]
for i in range(n - 1):
    new_w = input()
    for j in w:
        if new_w == j:
            k = True
    w.append(new_w)
    if k:
        f = True
    w_str = list(new_w)
    if final_w != w_str[0]:
        f = True
    else:
        final_w = w_str[-1]
if f:
    print("No")
else:
    print("Yes")

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

w.append(input())

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

print(ans)

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

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

def set_str(l):
    return len(l) == len(set(l))
if set_str(l):
    occurrence_No = True
    for i in range(len(l)):
        call_l = l[i]
        if i != 0 and l[i-1][-1] != call_l[0] :
            print("No")
            occurrence_No = False
            break
    if occurrence_No:
        print("Yes")
else:
    print("No")

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

for idx,val in enumerate(W):
    if idx == 0:
        continue
    if W[idx-1][-1] != val[0] or W.count(val) > 1:
        print('No')
        exit()
print('Yes')

Solution (Python):
N = int(input())
W = []
flg = True
for i in range(N):
    w = input()
    if i != 0:
        if W[i-1][len(W[i-1])-1] != w[0]:
            print('No')
            flg = False
            break
        if w in W:
            print('No')
            flg = False
            break
    W += [w]
if flg:
    print('Yes')

Solution (Python):


n = int(input())
a = [input() for i in range(n)]
count = 0

for i in range(n - 1):
    if a[i][-1] != a[i+1][0]:
        count += 1

import collections
b = collections.Counter(a)

if b.most_common(1)[0][1] >= 2:
    count += 1

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

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  

def solve(N: int, W: "List[str]"):
    used = set()
    used.add(W[0])
    ret = YES
    for i in range(1, N):
        if W[i][0] != W[i - 1][-1] or W[i] in used:
            ret = NO
            break
        used.add(W[i])
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    W = [ next(tokens) for _ in range(N) ]  
    solve(N, W)

if __name__ == '__main__':
    main()

Solution (Python):


N=int(input())
start=[]
for i in range(N):
    start.append(input())
cnt=0
for i in range(N):
    if i!=0 and start[i][0]==start[i-1][-1]:
        cnt+=1
        
if len(start)==len(set(start)) and cnt==N-1:
    print('Yes')
else:
    print('No')

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

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

def alg1(W):
  list = [W[0],]
  point = W[0]
  for i in range(1,N):
    if W[i] not in list and W[i][0] == point[-1]:
      list.append(W[i])
      point = W[i]
    else:
      return 'No'
  return 'Yes'

print(alg1(W))

Solution (Python):
N = int(input())
Mylog = []
cnt = 0
x = list(input())
Mylog.append(x)
for i in range(1,N):
  x = list(input())
  Mylog.append(x)
  if (x in Mylog[:-1]) or (Mylog[i-1][-1] != Mylog[i][0]):
    cnt += 1

print("Yes" if cnt==0 else "No")

Solution (Python):

N = int(input())
l = [input()]
for i in range(N-1):
    tmp = input()
    if tmp not in l and l[-1][-1] == tmp[0]:
        l.append(tmp)
print("Yes" if len(l) == N else "No")

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left

def main():
	N = int(input())
	W = []
	for _ in range(N):
		tmp = input()
		if tmp in W:
			print("No")
			sys.exit()
		W.append(tmp)
		
	for i, val in enumerate(W):
		if i > len(W)-2:
			print("Yes")
			sys.exit()
		
		if val[len(val)-1] != W[i+1][0]:
			print("No")
			sys.exit()
	
	print("No")
		
	
if __name__ == "__main__":
	main()

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

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

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

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

prev_last=None
for i in range(n):
    w = input()
    if prev_last != None:
        if prev_last != w[0] or w in words:
            print("No")
            exit()
    prev_last = w[-1]
    words.append(w)

print("Yes")

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

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

Solution (Python):
n = int(input())
w = []
ng = 0

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

for i in range(1,n):
    if w[i-1][-1] != w[i][0]:
        ng += 1
        break
    if w.count(w[i-1]) > 1:
        ng += 1
        break

if ng > 0:
    print('No')
else:
    print('Yes')

Solution (Python):
import copy
n = int(input())
w = [input() for i in range(n)]
flag = True
count = 0
for i in range(n):
    w_temp = copy.deepcopy(w)
    w_temp.pop(i)
    if w[i] in w_temp:
        print('No')
        exit()
for i in range(1, n):
    if w[i][0] != w[i-1][-1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
n=int(input())
arr=[]
flag=True
s=input()
arr.append(s)
for _ in range(n-1):
  w=input()
  if w in arr:
    flag=False
  if s[-1] != w[0]:
    flag=False
  arr.append(w)
  s=w
if flag:
  print('Yes')
else:
  print('No')

Solution (Python):
N = int(input())
W = [input() for _ in range(N)]
d = {}
alp = W[0][-1]
d[W[0]] = True
for i in range(1, N):
    if W[i] in d:
        print("No")
        exit()
    if alp != W[i][0]:
        print("No")
        exit()
    d[W[i]] = True
    alp = W[i][-1]
print("Yes")

Solution (Python):
N=int(input())
W=[input() for _ in range(N)]
his=set()
ok=True
lc=W[0][0]
for w in W:
	if w in his or lc != w[0]:
		ok=False
		break
	his.add(w)
	lc=w[len(w)-1]
print("Yes" if ok else "No")

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

f = True
for i in range(len(W)-1):
    if W[i][-1] != W[i+1][0]:
        f = False
        break

if f and N==len(set(W)):
    print('Yes')
else:
    print('No')

Solution (Python):


n = int(input())
a = [input() for i in range(n)]
count = 0

for i in range(n - 1):
    if a[i][-1] != a[i+1][0]:
        count += 1

import collections
b = collections.Counter(a)

if b.most_common(1)[0][1] >= 2:
    count += 1

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

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

for i in range(N-1):
    if W[i][len(W[i])-1] != W[i+1][0]:
        flag = False
        
for i in range(N):
    for j in range(N):
        if i != j:
            if W[i] == W[j]:
                flag = False

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

Solution (Python):
def main():
	n = int(input())
	said = set()
	first = input()
	said.add(first)
	last = first[-1]
	is_shiritori = True
	for _ in range(n-1):
		word = input()
		if word in said or word[0] != last:
			is_shiritori = False
		said.add(word)
		last = word[-1]

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


if __name__ == '__main__':
    main()

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

flag = True
if N == len(set(W)):
  for i in range(1, N):
    if W[i - 1][-1] != W[i][0]:
      flag = False
      break
else:
  flag = False
print('Yes' if flag else 'No')

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

Solution (Python):
import sys

N = int(input())
judge = []
for i in range(N):
    W = input()
    if W in judge:
        print('No')
        sys.exit()
    else:
        if not judge:
            judge.append(W)
        else:
            if judge[-1][-1] != W[0]:
                print('No')
                sys.exit()
            else:
                judge.append(W)

print('Yes')

Solution (Python):


tmp = True

N = int(input())
w = [input() for i in range(N)]
if len(set(w)) != N:
    tmp = False
for i in range(N-1):
    if w[i][-1] != w[i+1][0]:
        tmp = False
print('Yes'if tmp else 'No')

Solution (Python):
_,*l=open(0);print('YNeos'[any(a[-2]!=b[0]*l.count(a)for a,b in zip(l,l[1:]))::2])

Solution (Python):
n = int(input())
done = set()
start = input()
done.add(start)
status = True
for i in range(n-1):
    x = input()
    if x in done:
        status = False
    if x[0] != start[-1]:
        status = False
    done.add(x)
    start = x
if status:
    print("Yes")
else:
    print("No")

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

before = []
answer = 'Yes'

for i in range(N):
    s = input()
    if s in before:
        answer = 'No'
    if len(before) > 0:
        if before[-1][-1] != s[0]:
            answer = 'No'

    before.append(s)

print(answer)

Solution (Python):
from collections import Counter

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

cnt = Counter(w_list).most_common(1)[0][1]
if cnt > 1:
    print('No')
else:
    for i in range(0,N - 1):
        if w_list[i][-1] != w_list[i + 1][0]:
            print('No')
            break
    else:
        print('Yes')

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

for i, w in enumerate(words):
    if i == 0:
        continue
    if words.count(w) > 1:
        print('No')
        break
    if w[0] != words[i - 1][-1]:
        print('No')
        break
else:
    print('Yes')

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

flag = False
for i in range(N-1):
  if words[i][-1] != words[i+1][0]:
    flag = True
  else:
    continue

if len(words) != len(set(words)):
  print("No")
elif flag == True:
  print("No")
else:
  print("Yes")

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

print("Yes")

Solution (Python):
import sys
n = int(raw_input())
w0 = str(raw_input())
wlist = [w0]
for i in range(1,n):
	w = str(raw_input())
	wlist.append(w)
	if (wlist.count(w)>=2) | (w0[-1] != w[0]):
		print 'No'
		sys.exit()
	else:
		w0 = w
print 'Yes'

Solution (Python):
n = int(input())
last = ""
flg = 0
li = []
for i in range(n):
    s = input()
    str = list(s)  
    if last == "":
        last = str[-1]
        li.append(s)
        continue

    if str[0] != last or s in li:
        flg = 1

    last = str[-1]
    li.append(s)


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

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

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

yes = 0

for i in range(N-1):
  if (word.count(word[i]) > 1 or word.count(word[-1]) > 1):
    break
  if word[i][-1] == word[i+1][0]:
    yes += 1
    continue
  else:
    break

if yes == N-1:    
  print('Yes')
else:
  print('No')

Solution (Python):
N = int(input())
Si = [input() for _ in range(N)]
old = Si[0][-1]

if len(Si) != len(set(Si)):
    print('No')
    quit()

for i in range(1, N):
    if Si[i][0] != old:
        print('No')
        quit()
    old = Si[i][-1]

print('Yes')

Solution (Python):
n = int(input())
w = [input() for i in range(n)]
re = 'Yes'
if len(w) != len(set(w)):
  re = 'No'
for i in range(n-1):
  if w[i][-1] != w[i+1][0]:
    re = 'No'
print(re)

Solution (Python):
N=int(input())
W=[]
for _ in range(N):
    W.append(input())
c=1
for i in W:
    d=W.count(i)
    if d>1:
        c=0
        break
for i in range(N-1):
     if W[i][-1]!=W[i+1][0]:
            c=0
            break
if c:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
w_list = [input() for _ in range(n)]
if len(w_list) != len(set(w_list)):
    print('No')
else:
    f = True
    tail = w_list[0][0]
    for w in w_list:
        if w[0] != tail:
            f = False
        else:
            tail = w[-1]
            pass
    print('Yes' if f else 'No')

Solution (Python):
N = int(input())
W = [input() for i in range(N)]
Flag = True
for i in range(1,N):
    if W[i-1][-1] != W[i][0]:
        Flag = False
    for j in range(i):
        if W[j] == W[i]:
            Flag = False
if Flag == True:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
W = [input() for _ in range(n)]
if (len(set(W)) != len(W)):
  print('No')
  exit()

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

print('Yes')

Solution (Python):
import sys
import collections

N = int(input())
List = [list(input())]
for i in range(1,N):
    tmp = list(input())
    if (tmp in List) == True:
        print('No')
        sys.exit()
    List.append(list(tmp))
    
    if tmp[0] != List[i-1][-1]:
        print('No')
        sys.exit()


print('Yes')

Solution (Python):
import sys

N=int(input())
s=set()

w=input()
s.add(w)
tmp=w[-1]

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

    if w in s or tmp!=w[0]:
        print("No")
        sys.exit()
    else:
        s.add(w)
        tmp=w[-1]

print("Yes")

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

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

if len(W) != len(set(W)):
    print('No')
else:
    i = 0
    while i < N - 1:
        if W[i][-1] == W[i + 1][0]:
            i += 1
        else:
            print('No')
            break
    if i == N - 1:
        print('Yes')

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


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


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

print("Yes")

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

wo = [input()]
st = 0
for i in range(1,n):
	inl = input()
	if ((inl in wo) or (wo[-1][-1] != inl[0])):
		st = 1
		break
	else:
		wo.append(inl)
	



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

Solution (Python):
N=int(input())
W=list(input() for i in range(N))
p=W[0][0]
res=0
for w in W:
  if W.count(w)<2:
    if w[0]==p:
      res+=1
    else:
      break
  else:
    break
  p=w[-1]
if res==N:
  print("Yes")
else:
  print("No")

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

if len(set(Wn)) != N:
    print("No")
else:
    bw = Wn[0]
    for W in Wn[1:]:
        if W[0] != bw[-1]:
            print("No")
            break
        bw = W
    else:
        print("Yes")

Solution (Python):
def unique(S):
    new = []
    for i in S:
        if not i in new:
            new.append(i)
    return new

def solve(S):
    if not len(unique(S)) == len(S):
        return False
    for i in range(len(S)-1):
        if not S[i][-1] == S[i+1][0]:
            return False
    return True

N = int(input())
S = [input() for i in range(N)]
print("Yes" if solve(S) else "No")

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

w = str(input())
w_end = w[-1]

tmp = []
tmp.append(w)

for i in range(N - 1):
    w = str(input())
    if w[0] == w_end and w not in tmp:
        pass
    else:
        print("No")
        exit()
    w_end = w[-1]
    tmp.append(w)

print("Yes")

Solution (Python):
def is_obeid(x):
    for i in range(len(x)):
        if x.count(x[i]) > 1:
            return False
        if i != 0:
            if x[i][0] != x[i - 1][-1:]:
                return False
    return True

def main():
    w = []
    N = int(input())
    for i in range(N):
        w.append(input())
    if is_obeid(w):
        print('Yes')
    else:
        print('No')

main()

Solution (Python):
N = int(input())
prev_word = input()
count = {prev_word:1}
for i in range(1,N):
    cur_word = input()
    if cur_word in count:
        print("No")
        exit()
    count[cur_word] = 1
    if cur_word[0] == prev_word[-1]:
        prev_word = cur_word
        continue
    print("No")
    exit()
print("Yes")

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

if len(W) != len(sW):
    print('No')
else:
    for i in range(N):
        if i == N-1:
            print('Yes')
            break
        if W[i][-1] is not W[i+1][0]:
            print('No')
            break

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

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

Solution (Python):
N = int(input())
used = [input()]
flag = 1
for i in range(N-1):
  now = input()
  if now not in used and used[-1][-1] == now[0]:
    used.append(now)
  else:
      flag = 0

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

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

Solution (Python):
N=int(input())
S=set()
B=input()
S.add(B)
for i in range(N-1) :
  A=input()
  if A not in S and A[0]==B[-1]  :
    S.add(A)
    B=A
  else :
    print("No")
    break
else :
  print("Yes")

Solution (Python):



n = int(input())

l = []

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

print('Yes')

Solution (Python):


n = int(input())
w = [0] * n
for i in range(n):
    w[i] = input()

rule = True
for i in range(1,n):
    if w[i][0] != w[i-1][-1]:
        rule = False
        break

w.sort()

for i in range(1,n):
    if w[i] == w[i-1]:
        rule = False
        break

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

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

string_list=[input() for i in range(N)]
i = 0
string_list2 = list(set(string_list))
if(len(string_list2)==N):
    check = 1
else:
    check = 0

while(i < N-1):
    string1  = string_list[i]
    string2 = string_list[i+1]
    str1 = string1[-1]
    str2 = string2[0]
    if(str1 != str2):
        check = 0
    i +=1

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

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

ans = True
w = set([Ws[0]])
for i in range(1, N):
    if Ws[i - 1][-1] != Ws[i][0]:
        ans = False
        break
    if Ws[i] in w:
        ans = False
        break
    w.add(Ws[i])

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