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

Solution (Python):
N=int(input())
x=[input() for _ in range(N)]
flag=0

if len(x)!=len(list(set(x))):
  flag=1

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

Solution (Python):
n = int(input())
w = [input() for _ 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):
import sys

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

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

for i in range(len(items)):
  if(i != 0 and items[i][0] != items[i-1][-1]):
    print('No')
    sys.exit()

print('Yes')

Solution (Python):
def solve(W):
    set_W = set(W)
    if len(W) != len(set_W):
        return False

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

    return True


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

if solve(W):
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
ans='Yes'
S=[input() for i in range(n)]

if len(set(S))!=n:
  ans='No'

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

Solution (Python):
import sys
n=int(input())
d=[]
for i in range(n):
    w=input()
    if i>=1:
        if w[0]!=last:
            print('No')
            sys.exit()
    last=w[-1]
    d.append(w)
d=sorted(d)
for i in range(len(d)-1):
    if d[i]==d[i+1]:
        print('No')
        sys.exit()
print('Yes')

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

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

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

Solution (Python):
import collections

N = int(input())

lw = list()
for i in range(N):
    lw.append(input())

def check1(l):
    c = collections.Counter(l)
    lv = list(c.values())
    if lv == [1] * len(lv):
        return 1

def check2(l):
    c = 0
    for i in range(len(l)-1):
        if l[i][-1] == l[i+1][0]:
            c += 1
    if c == len(l) - 1:
        return 1

if check1(lw) == 1 and check2(lw) == 1:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
l = [input() for _ in range(n)]
s = set(l)
if(len(l) != len(s)):
    print('No')
    exit()
for i in range(1,n):
    if(l[i][0] != l[i-1][-1]):
        print('No')
        exit()
print('Yes')

Solution (Python):
n = int(input())
p = []
for i in range(n):
    p.append(input())
    
for i in range(n):
    if p.count(p[i]) != 1:
        print("No")
        exit()
for i in range(1,n):
    mae = p[i-1]
    ato = p[i]
    if mae[-1] != ato[0]:
        print("No")
        exit()
print("Yes")

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

r=set(w)
o=''
m=''
if len(r) != len(w):
    
    print('No')
    sys.exit()

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

Solution (Python):
n = int(input())
w = [input() for i in range(n)]
ok = "Yes"
e = w[0][-1]
double = [w[0]]
for i in range(1, n):
    if double.count(w[i]) != 0:
        ok = "No"
        break
    double.append(w[i])
    s = w[i][0]
    if s != e:
        ok = "No"
        break
    e = w[i][-1]
print(ok)

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

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

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

print("Yes")

Solution (Python):
n = int(input())
w = [0]*n
r = [0]*n
for i in range(n):
    r[i] = input()
    w[i] = list(r[i])
    
ans = 1
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        ans = 0
        break
q = set(r)
if len(q) != n:
    ans = 0
if ans == 1:
    print("Yes")
else:
    print("No")

Solution (Python):

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

Solution (Python):
import numpy as np
import sys
import math

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

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

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

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

print(ans)

Solution (Python):
MOD = 10 **9 + 7
INF = 10 ** 10

def main():
    N = int(input())
    w = input()
    W = {w}
    before = w
    flag = True
    for _ in range(N - 1):
        w = input()
        if w in W:
            flag = False
            break
        else:
            if before[-1] != w[0]:
                flag = False
                break
            before = w
            W.add(w)
    print('Yes' if flag else 'No')
if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

n=I()
words=[input().rstrip() for i in range(n)]
u=len(list(set(words)))
if u!=n:
    print("No")
    sys.exit()
for i in range(n-1):
    if words[i][-1]!=words[i+1][0]:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
n = int(input())
W = []
flag = True
for i in range(n):
    w = input()
    if w in W:
        flag = False
    if i > 0 and W[i-1][-1] != w[0]:
        flag = False
    W.append(w)

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

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

Solution (Python):


n = int(input())

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

pre = words[0]
done = set([pre])
for i in range(1, n):
    w = words[i]
    if pre[-1] == w[0] and w not in done:
        pre = w
        done.add(w)
    else:
        print('No')
        break
else:
    print('Yes')

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

if len(set(l)) < n:
    print("No")
    sys.exit()

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

print("Yes")

Solution (Python):


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

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

Solution (Python):
n = int(input())
l = [input() for i in range(n)]
n_l = [l[0]]
ans = "Yes"
for i in range(1,n):
    if l[i] not in n_l:
        n_l.append(l[i])
    else:
        ans = "No"
        break

    if l[i-1][-1] == l[i][0]:
        continue
    else:
        ans = "No"

print(ans)

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

jdg = True

s_last = w[0][-1]
ss = [w[0]]

for s in w[1:]:
    if s in ss:
        jdg = False
        break
    if s[0] != s_last:
        jdg = False
        break
    s_last = s[-1]
    ss.append(s)
print('Yes' if jdg else 'No')

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
if len(set(s)) < n:
	print("No")
else:
	flag = True
	for i in range(1,n):
		if s[i-1][-1] != s[i][0]:
			flag = False
	print("Yes" if flag else "No")

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


YES = "Yes"  
NO = "No"  


def solve(N: int, W: "List[str]"):
    print(YES if len(set(W)) == N and all(
        W[i][-1] == W[i + 1][0]
        for i in range(N - 1)
    ) else NO)


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):
import numpy as np
import sys

input = sys.stdin.readline

N = int(input())

x = []

res = True
for i in range(N):
    w = input()
    w = w[:(len(w)-1)]
    if w in x:
        res = False
    x.append(w)
    if i > 0: 
        if w[0] != x[i-1][-1]:
            res = False
        

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

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

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

Solution (Python):
import collections
n = int(input())
li = [input() for _ in range(n)] 
ans = 'Yes'
lw = li[0][0]
for s in li:
    if lw != s[0]:
        ans = 'No'
        break
    else:
        lw = s[-1]

c = collections.Counter(li)
if c.most_common()[0][1] != 1:
    ans = 'No'
print(ans)

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

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

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(n-1):
    temp = w[i]
    temp2 = w[i+1]
    if temp[-1] != temp2[0] or has_duplicates(w) == True :
        print("No")
        exit()
print("Yes")

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

isok = True

for a in range(0, N-1):
    w1 = words[a]
    w2 = words[a+1]

    if w1[-1] != w2[0]:
        isok = False
        break

if isok and len(list(set(words))) == N:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
s_1 = input()
word_list = [s_1]
target = s_1[-1]
frag = "Yes"
for i in range(n-1):
  s = input()
  if s in word_list :
    frag = "No"
  if target == s[0]:
    target = s[-1]
  else:
    frag = "No"
 
  word_list.append(s)
    
print(frag)

Solution (Python):
N=int(input())
S=['0']*N
for i in range(0,N):
    S[i]=input()
for i in range(1,N):
    if S.count(S[i])>1:
        print('No')
        exit()
    elif S[i-1][-1]!=S[i][0]:
        print('No')
        exit()
print('Yes')

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

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

W = []

ans = 0
W.append(input())

for i in range(N-1):
  Wi = input()
  WL = W[i]
  if Wi in W:
    ans = 1
    break
  if Wi[0] != WL[len(WL)-1]:
    ans = 1
    break

  W.append(Wi)

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

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

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

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


def solve(N: int, W: "List[str]"):
    already = []
    for n in range(N-1):
        if W[n] in already:
            print(NO)
            exit()
        already.append(W[n])
        if W[n][-1] != W[n+1][0]:
            print(NO)
            exit()
    if W[-1] in already:
        print(NO)
        exit()
    print(YES)
    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())
W = [input() for i in range(N)]
count = 0
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        count += 1

count += len(W)- len(set(W))

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

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


def has_duplicates(x):
    return len(x) == len(set(x))


if (has_duplicates(W)):
    s = ''
    for i, v in enumerate(W):
        if (i == 0):
            s = v[-1]
            continue
        elif(i > 0 and i < len(W) - 1):
            if (s == v[0]):
                s = v[-1]
            else:
                print('No')
                exit()
        else:
            if (s == v[0]):
                print('Yes')
            else:
                print('No')
else:
    print('No')

Solution (Python):




n = int(input())
d = dict()


ans = 'Yes'
wkc = 9
for i in range(n):
    w = input()
    if d.get(w) == None:
        d[w] = 1
    else:
        ans = 'No'
        break

    if i > 0 and wkc != w[0]:
        ans = 'No'
        break
    
    wkc = w[len(w)-1]


print(ans)

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

Solution (Python):
N = int(input())
W = [input() for i in range(N)]
if all(W[i][0]==W[i-1][-1] and W[i] not in W[:i] for i in range(1, N)):
    print('Yes')
else:
    print('No')

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

a = []
pre = W[0]
a.append(pre)
flag = False
for wi in W[1:]:
    if wi in a or pre[-1] != wi[0]:
        flag = True
        break
    pre = wi
    a.append(wi)
        
if flag:
    print('No')
else:
    print('Yes')

Solution (Python):
n=int(input())
now=input()
s=set()
s.add(now)
for i in range(n-1):
    now2=input()
    if now[-1]!=now2[0]:
        print("No")
        break
    now=now2
    s.add(now)
else:
    if len(s)==n:
        print("Yes")
    else:
        print("No")

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

if len(set(W)) != len(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())
word_list = [input() for i in range(N)]
ans = "Yes"
def f(s1,s2):
  if s1[len(s1)-1] == s2[0] :
    return True

for i in range(0,N-1):
  if f(word_list[i],word_list[i+1]):
    pass
  else:
    ans = "No"

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

print(ans)

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

Solution (Python):
n = int(input())
w = []
while True:
  try:
    w.append(input())
  except:
    break

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

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

shiritori_set = set()

shiritori = input()
head = shiritori[len(shiritori) -1]

ans = "Yes"
shiritori_set.add(shiritori)
for i in range(N-1):
  shiritori = input()
  if shiritori[0] == head and shiritori not in shiritori_set:
    head = shiritori[len(shiritori)-1]
    shiritori_set.add(shiritori)
  else:
    ans = "No"
    break

print(ans)

Solution (Python):
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
MOD = 10**9+7

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

    prev = words[0]
    se = set([words[0]])

    bl = True
    for w in words[1:]:
        if w in se:
            bl = False
        if prev[-1] != w[0]:
            bl = False
        se.add(w)
        prev = w

    answer = 'Yes' if bl else 'No'
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

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

if __name__ == '__main__':
    main()

Solution (Python):

n = int(input())
w = [input() for _ in range(n)]
word_list = set(w)

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

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

print("Yes")

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

print("Yes")

Solution (Python):
n = int(input())
s = set([])
w = input()
s.add(w)
for i in range(n-1):
  w2 = input()
  s.add(w2)
  if w2[0] != w[-1]:
    print("No")
    quit()
  w = w2
if len(s) == n:
  print("Yes")
else:
  print("No")

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

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

print(ans)

Solution (Python):
n = int(input())
S = set()
ans = "Yes"

for i in range(n):
    str = input()

    if(len(S) != 0):
        if(str[0] != c or str in S):
            ans = "No"
    
    S.add(str)
    c = str[-1]

print(ans)

Solution (Python):
def main():
    N = int(input())
    words = [input()]
    ans = True
    for _ in range(N - 1):
        s = input()
        if words[-1][-1] != s[0] or s in words:
            ans = False
        else:
            words.append(s)

    if ans is True:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Solution (Python):

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

w_s = w.copy()
w_s = set(w_s)
w_s = list(w_s)

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

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

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

ans = 'Yes'
for i in range(1,n):
    if input_lines[i] not in input_lines[0:i] and input_lines[i][0]==input_lines[i-1][-1]:
        continue
    else:
        ans = 'No'
        break
print(ans)

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

words = set()
w = ''
ok = True
for i in range(n):
  nw = input()
  if nw in words:
    ok = False
    break
  words.add(w)
  if w and w[-1] != nw[0]:
    ok = False
  w = nw

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

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

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

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

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

print("Yes")

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

import sys
b = [input() for i in range(a)]
c=set(b)
if len(b)!=len(c):
    print('No')
    sys.exit()
for i in range(a-1):
    if b[i][-1]==b[i+1][0]:
        pass
    else:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
















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


lis = []
ans = "Yes"
for i,w in enumerate(arrW):
    
    if i == 0:
        lis.append(w)
    else:
        if arrW[i-1][-1] != arrW[i][0]:
            ans = "No"
            break
        if arrW[i] in lis:
            ans = "No"
            break
        lis.append(w)

print(ans)

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


if len(w) != len(set(w)):
    print('No')
    sys.exit()
else:
    for i, name in enumerate(w):

        try:
            if name[-1] != w[i+1][0]:
                print('No')
                sys.exit()

        except IndexError:
            print('Yes')

Solution (Python):
import sys

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

Solution (Python):
def h(seq):
    return len(seq)!=len(set(seq))
a=int(input())
t=['0']*a
hantei=0
for i in range(a):
    t[i]=input()
for i in range(a-1):
    if t[i][-1]!=t[i+1][0]:
        hantei=1
if h(t):
    hantei=1
if hantei==0:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
import math
n = int(input())
li = [n]
li[0] = input()
isGood=True
for i in range(n-1):
    tmp = input()
    if (not isGood):
        continue
    if (tmp not in li):
        if (li[i][-1] != tmp[0]):
            isGood = False
        else:
            li.append(tmp)
    else:
        isGood = False

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

Solution (Python):
n=int(input())
wordset=set()
pw=input()
wordset.add(pw)
ans='Yes'
for _ in range(n-1):
  w=input()
  if pw[-1] != w[0] or w in wordset:
    ans='No'
    break
  wordset.add(w)
  pw=w
print(ans)

Solution (Python):
def main():
    n = int(input())
    str_list = [input() for _ in range(n)]

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

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

    print('Yes')

if __name__ == '__main__':
    main()

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

def main():
    n = int(readline())
    w1 = readline().rstrip()
    l = w1[-1]
    words = set()
    words.add(w1)
    for _ in range(n-1):
        w = readline().rstrip()
        if w[0] == l and w not in words:
            l = w[-1]
            words.add(w)
        else:
            print('No')
            return
    
    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    W = [iss() for _ in range(N)]
    s = W[0]
    r1 = True
    for i in range(1, N):
        if s[-1:] != W[i][0:1]:
            r1 = False
        s = W[i]

    print('Yes' if r1 and all([W.count(w) == 1 for w in W]) else 'No')


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = []
b = ''
flag = 0

for i in range(N):
    t, b = b, input()

    if i != 0:
        if t[-1] != b[0]:
            flag = 1
            break

    if b not in a:
        a.append(b)
    else:
        flag = 1
        break

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

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

Solution (Python):
N=int(input())
W=str(input())
w_list = [W]
OUT = False
for i in range(N-1):
  W=str(input())
  w_list.append(W)
  if W[0] != w_list[i][len(w_list[i])-1]:
    OUT = True
  n = len([1 for w in w_list if w==W])
  if n > 1:
    n = 0
    OUT = True
if OUT:
  print('No')
else:
  print('Yes')

Solution (Python):
n=int(input())
word_list=[]
last_word='aaaa'
for i in range(n):
    w=input()
    if 0<i and (w in word_list or last_word[len(last_word)-1]!=w[0:1]):
        print('No')
        exit()
    word_list.append(w)
    last_word=w
print('Yes')

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

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

Solution (Python):
N = int(input())
W = [input() for _ in range(N)]
print('Yes' if len(W) == len(set(W)) and all(i[-1] == j[0] for i, j in zip(W, W[1:])) else 'No')

Solution (Python):
n = int(input())
List = [input() for i in range(n)]
x = 0
ans = "Yes"

for i in range(1,n):
    if List[i-1][-1:] != List[i][:1]:
        ans = "No"
        
        
        break
if len(List) != len(set(List)):
    ans = "No"
print(ans)

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]
ans = 'Yes'
for i in range(1, N):
    if S[i-1][-1:] != S[i][:1]:
        ans = 'No'
        break
if len(S) != len(set(S)):
    ans = 'No'
print(ans)

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

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

Solution (Python):
N=int(input())
W=[input() for _ in range(N)]
flg=1
flg_1=1
for i in W:
    if W.index(i)!=0:
        if i[0]!=W[W.index(i)-1][-1]:
            flg=0
            break
if len(set(W))!=len(W):
    flg_1=0
    
print("Yes" if flg and flg_1 else "No")

Solution (Python):
icase=0
if icase==0:
    n=int(input())
    ww=set()
    w=[]
    for i in range(n):
        w.append(input())
    ww=set()
    ww.add(w[0])
    yn=""
    for i in range(n-1):
        if w[i][-1]!=w[i+1][0]:
            yn="No"
            print("No")
            break
        if w[i+1] in ww:
            yn="No"
            print("No")
            break
        else:
            ww.add(w[i+1])
    if yn!="No":
        print("Yes")

Solution (Python):
n = int(input())
f = True
w = []
w.append(input())
last = w[0][-1]

for i in range(1,n):
    w.append(input())
    
    if w[i][0] == last and not(w[i] in w[:i]):
        last = w[i][-1]
    else:
        f = False

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

Solution (Python):

N = int(input())
W = [input() for i in range(N)]
pre =""
for word in W:
    if W.count(word)>1 or (pre[-1:]!=word[0] and pre!=""):
        print('No')
        exit()
    pre = word
print('Yes')

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

if len(w) != len(set(w)):
    print('No')
    quit()
check = [w[0]]
siri = w[0][-1]
for i in range(1,n):
    if w[i][0] == siri:
        check.append(w[i])
        siri = w[i][-1]
    else:
        print('No')
        quit()
print('Yes')

Solution (Python):
n = int(input())
a = [input()]
for _ in [0]*(n-1):
    b = input()
    if a[-1][-1] != b[0] or b in a:
        print('No')
        break
    a += [b]
else:
    print('Yes')

Solution (Python):
n = int(input())
wordlist = [input()]
f = 0
i = 1
while i < n:
    w = input()
    if w[0] != wordlist[-1][-1]:
        f = 1
    if w in wordlist:
        f = 1
    wordlist.append(w)
    i += 1
if f == 0:
    print('Yes')
else:
    print('No')