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())
lst = [input() for i in range(N)]
for i in range(N-1):
    n = lst[i]
    m = lst[i+1] 
    if lst[i+1] in lst[:i+1] or n[-1] != m[0]:
        print('No')
        exit()
print('Yes')

Solution (Python):
n=int(input())
L=[input()]
for i in range(n-1):
    l=input()
    if l not in L and str(L[i])[-1]==l[0]:
        L.append(l)
    else:
        break
print('Yes' if len(L)==n else 'No')

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

Solution (Python):





def main():
    N = int(input())
    W = [None] * N
    for i in range(N):
        W[i] = input()
    
    app = [W[0]]
    for i in range(1, N):
        w = W[i]
        if w in app or w[0] != app[-1][-1]:
            return "No"
        app.append(w)
    
    return "Yes"


print(main())

Solution (Python):
N=int(input())
l=list()
W=input()
l.append(W)
w=list(W)
X=w[-1]
for i in range(N-1):
  Y=input()
  l.append(Y)
  y=list(Y)
  if X!=y[0]:
    print('No')
    exit()
  else:
    X=y[-1]
    
if len(l)!=len(set(l)):
  print('No')
  exit()
  
print('Yes')

Solution (Python):
s = int(input())
l = []    
a = input()
l.append(a)
i = 1
for i in range(s-1):
    b = input()
    if l[-1][-1] != b[0]:
        break
    l.append(b)

ans = set(l)
if len(ans) == s:
    print('Yes')
else:
    print('No')

Solution (Python):
n=int(input())
w=list(input()for _ in range(n))
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')
            exit()
    print('Yes')

Solution (Python):

def inp():
    return(int(input()))



def inlist():
    return(list(map(int, input().split())))



def instr():
    s = input()
    return(list(s[:len(s)]))



def invr():
    return(map(int, input().split()))


N = inp()
S = []
f = "Yes"
for i in range(N):
    s = input()
    if i > 0:
        prev = S[i-1]
        if s in S or s[0] != prev[-1]:
            f = "No"
    S.append(s)
print(f)

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

last = ""
s = set()

for i in range(n):
    if i != 0:
        if (last != w[i][0]) or w[i] in s:
            print("No")
            exit()
    s.add(w[i])
    last = w[i][-1]


print("Yes")

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

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

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

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

Solution (Python):
n=int(input())
temp=str(input())
templ=list(temp)
tempb=templ[len(templ)-1]
w=[0]*n
w[0]=temp
for i in range(0,n-1):
  temp=str(input())
  templ=list(temp)
  if temp in w or tempb!=templ[0]:
    print("No")
    break
  tempb=templ[len(templ)-1]
  w[i+1]=temp
else:
  print("Yes")

Solution (Python):
from collections import defaultdict

n = int(input())
words_count = defaultdict(int)

last_word = input()
words_count[last_word] += 1
for _ in range(n - 1):
    word = input()
    if word[0] != last_word[-1]:
        print("No")
        exit()
    if words_count[word] > 0:
        print("No")
        exit()
    words_count[word] += 1
    last_word = word

print("Yes")

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

ans = "Yes"

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

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

print(ans)

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

d = dict()
pre = input()
d[pre] = 1
for _ in range(N - 1):
    w = input()
    if w in d or pre[len(pre) - 1] != w[0]:
        print("No")
        exit()
    d[w] = 1
    pre = w

print("Yes")

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

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

Solution (Python):






import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def Yes(): print("Yes"); return
def No(): print("No"); return


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count





N = inputI()
l = inputSLs(N)

if len(set(l))!=N:
  No()
  exit()
else:
  for i in range(N-1):
    if l[i][-1]!=l[i+1][0]:
      No()
      exit()
Yes()

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

flag = True

before = w[0][0]
for i in w:
    if before != i[0]:
        flag = False
    before = i[-1]
    
if len(set(w))!=n:
    flag = False
    
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
import math
import re
import copy

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

Solution (Python):
import sys

N = int(input())

W = []
for i in range(N):
    w = str(input())
    if w in W:
        print("No")
        sys.exit()
    if i != 0 and w[0] != W[i-1][-1]:
        print("No")
        sys.exit()
    W.append(w)

print("Yes")

Solution (Python):
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
w = [input() for i in range(n)]

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

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

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    ans = 'Yes'
    N = int(input())
    wl = []
    wl.append(input().rstrip('\n'))
    for i in range(1,N):
        wl.append(input().rstrip('\n'))
        if wl[i-1][-1] != wl[i][0]:
            ans = 'No'
            break
    if len(wl) != len(set(wl)):
        ans = 'No'
    print(ans)

if __name__ == '__main__':
    main()

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

ans = ['']*n

ans[0] = input()

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

    ans[i] = w
print('Yes')

Solution (Python):
N = int(input())
prev = input()
said = {prev}
for _ in range(1, N):
    now = input()
    if now not in said and prev[-1] == now[0]:
        said.add(now)
        prev = now
        continue
    print("No")
    break
else:
    print("Yes")

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

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = input()
W = [s]
for i in range(n-1):
    s = input()
    if W[-1][-1] == s[0] and not s in W:
        W.append(s)
    else:
        print("No")
        break
else:
    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(1, n):
    if w[i][0] != w[i - 1][-1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18


n = I()
W = SR(n)
used = set()
last = W[0][0]
for w in W:
    if last != w[0] or w in used:
        print("No")
        exit()
    last = w[-1]
    used.add(w)
print("Yes")

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

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

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

print(ans)

Solution (Python):
import collections

N = int(input())
W = []
jud = 1

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

c = collections.Counter(W)
ct = len(c)

for i in range(N-1):
    fst = W[i]
    fnl = W[i+1]
    if fst[-1] != fnl[0]:
        jud = 0

if ct != N:
    print("No")
elif jud == 0:
    print("No")
else: print("Yes")

Solution (Python):
N = int(input())
ketu = ""
mozi = []
frag = 0
for i in range(N):
    stri = input()
    if (ketu != "" )and(ketu != stri[0]):
        frag = 1

    ketu = stri[-1]
    mozi.append(stri)

if frag == 1:
    print("No")
    exit()

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

print("Yes")

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

if len(list(set(W))) == N:
    first = W[0]
    for i in W[1:]:
        if first[-1] != i[0]:
            print("No")
            exit()
        first = i
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
w = [input() for _ in range(n)]
flag = True
used = []
used.append(w[0])
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        flag = False
    elif w[i][-1] == w[i+1][0]:
        if w[i+1] not in used:
            used.append(w[i+1])
        else:
            flag = False
if flag:
    print("Yes")
else:
    print("No")

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

ans = 'Yes'

for i in range(1, n):
    s = input()
    if s in l:
        ans = 'No'
        break
    else:
        if l[-1][-1].endswith(s[0]):
            l.append(s)
        else:
            ans = 'No'
            break

print(ans)

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

Solution (Python):
import collections
a = int(input())
words = [input() for i in range(a)]
c = collections.Counter(words)
key = len(c.keys())
tmp = 0
for i in range(len(words)-1):
	if len(words) == key:
		if words[i][-1] == words[i+1][0]:
			tmp += 1
		else:
			tmp = 0
	else:
		break
if tmp == len(words)-1:
	print("Yes")
else:
	print("No")

Solution (Python):
import sys
import math
import bisect

def solve():
    n = int(input())
    my_set = set()
    for i in range(n):
        if i == 0:
            s = input()
            my_set.add(s)
        else:
            pre, s = s, input()
            if pre[-1] != s[0]:
                return False
            if s in my_set:
                return False
            my_set.add(s)
    return True

def main():
    if solve():
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import defaultdict

N = int(input())

memo = defaultdict(int)

for i in range(N):
    tmp = input()
    memo[tmp] += 1
    if i==0:
        last = tmp[-1]
        continue
    if memo[tmp]==2:
        print("No")
        sys.exit()
    else:
        if last != tmp[0]:
            print("No")
            sys.exit()
        last = tmp[-1]
else:
    print("Yes")

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

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


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

Solution (Python):
n=int(input())
w=[input() for _ in range(n)]
yn=0
for i in range(1,n):
    if w.count(w[i])!=1:
        yn=1
        break
if yn==1:
    print("No")
else:
    for i in range(n-1):
        if w[i][len(w[i])-1]!=w[i+1][0]:
            yn=1
            break
    if yn==1:
        print("No")
    else:
        print("Yes")

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

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

Solution (Python):
from collections import Counter

N = int(input())
words = [input() for _ in range(N)]
counts = Counter(words)

if max(counts.values()) > 1:
    print('No')
else:
    for i in range(1, len(words)):
        if words[i][0] != words[i - 1][-1]:
            print('No')
            break
    else:
        print('Yes')

Solution (Python):
import sys
import bisect
import heapq  

inf = 10 ** 15
mod = 10 ** 9 + 7
n = int(input())
judge = []
w = input()
pre = w[-1]
judge.append(w)
for i in range(n-1):
    w = input()
    if w[0] == pre and (not w in judge):
        pre = w[-1]
        judge.append(w)
    else:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
n = int(input())
L = []
last_letter = 0
for i in range(n):
    w = str(input())
    L.append(w)
    if (i != 0 and w[0] != last_letter) or L.count(w) != 1:
        print('No')
        exit()
    last_letter = w[-1]
print('Yes')

Solution (Python):
N = int(input())
List = []
for i in range(N):
  if(i == 0):
    W1 = input()
    List.append(W1)
  else:
    W2 = input()
    if(W1[-1] != W2[0] or W2 in List):
      print("No")
      exit()
    else:
      W1 = W2
      List.append(W2)
print("Yes")

Solution (Python):
import collections

N = int(input())

W = []

ns = ""
tflag = False
for count in range(N):
    W.append(str(input()))
    if ns == "":
        ns = W[count]
    else:
        if ns[len(ns)-1] != W[count][0]:
            tflag = True
        else:
            ns = W[count]


ls = collections.Counter(W)

for ccount in ls.values():
    if ccount > 1:
        tflag = True
        break
if tflag == True:
    print("No")
else:
    print("Yes")

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

Solution (Python):
n = int(input())
flg = 0
arr = []*n
arr.append(input())
for i in range(n-1):
  tmp = input()
  if arr[-1][-1] != tmp[0]:
    flg = 1
  if tmp in arr:
    flg = 1
  arr.append(tmp)
if flg == 0:
  print('Yes')
else:
  print('No')

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

Solution (Python):
A=int(input())
C=input()
B=set([C])
for i in range(A-1):
    D=input()
    if D in B or C[-1] != D[0]:
        print("No")
        exit()
    else:
        B.add(C)
        C=D
print("Yes")

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

from collections import Counter
def resolve():
    N,=pin()
    s=set()
    prev=""
    for i in range(N):
        temp=input()
        if temp in s:
            print("No")
            return
        if i>0 and temp[0]!=prev[-1]:
            print("No")
            return
        s.add(temp)
        prev=temp
    print("Yes")

resolve()

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

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

said = []
prev = ""
safe = True
for w in words:
    if prev == "":
        prev = w
        said.append(w)
        continue
    else:
        if prev[-1] != w[0]:
            safe = False
            break
        else:
            if w in said:
                safe = False
                break
            else:
                prev = w
                said.append(w)

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

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

words = [input()]

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

Solution (Python):
import fileinput

n = int(input())

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

print("Yes")

Solution (Python):
from sys import exit

n=int(input())
w=input()

a=set()
a.add(w)
w=w[-1]
cnt=0

for _ in range(n-1):
	x=input()
	if x in a or w!=x[0]:
		cnt=1
	w=x[-1]
	a.add(x)

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

Solution (Python):
n=int(input())
lst=[str(input()) for i in range(n)]
flag = False
if len(set(lst))==n:
  if all([lst[j][-1]==lst[j+1][0] for j in range(0, n-1)]):
    flag=True
print("Yes" if flag==True else "No")

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

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

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

Solution (Python):
import collections

n = int(input())
words = [input() for _ in range(n)]
words_count = collections.Counter(words)
first_word = words[0]
word_end = first_word[0]
not_siritori = 0

for i in words_count.values():
  if i > 1:
    not_siritori += 1

for word in words:
  if word_end != word[0]:
    not_siritori += 1
  word_end = word[-1]

if not_siritori != 0:
  print("No")
else:
  print("Yes")

Solution (Python):
N = int(input())
W = [input() for _ in range(N)]
ans = 'Yes'
if len(set(W)) != N:
    ans = 'No'
prev = W[0]
for w in W[1:]:
    if w[0] != prev[-1]:
        ans = 'No'
    prev = w
print(ans)

Solution (Python):
import sys

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

for i in range(1, N):
    word = words[i]
    if word in after or after[-1][-1] != word[0]:
        print('No')
        sys.exit()  
    after.append(word)
    
print('Yes')

Solution (Python):


import sys






















def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    words = [input() for _ in range(n)]
    appeared = []
    for i in range(n):
        s = words[i]
        if i != 0:
            if s in appeared or s[0] != appeared[-1][-1]:
                print('No')
                exit()
        appeared.append(s)
    print('Yes')

if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    W = [""] * N
    for i in range(N):
        W[i] = input().rstrip()

    condition_1 = True
    for i in range(N - 1):
        if W[i][-1] != W[i + 1][0]:
            condition_1 = False

    c = Counter(W)
    values = c.values()
    condition_2 = all(v == 1 for v in values)

    if condition_1 and condition_2:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)


if __name__ == "__main__":
    main()

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

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

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

temp=w[0][0]

for item in w:
    if temp!=item[0]:
        print("No")
        exit()
    else:
        temp=item[-1]

print("Yes")

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

word_list = []
f = 0
for i, n in enumerate(range(N)):
  s = input()
  if i == 0:
    pre = s[-1]
    word_list.append(s)
    continue
  if s in word_list:
    f = 1
    break
  if s[0] != pre:
    f = 1
    break
  pre = s[-1]
  word_list.append(s)
if f == 1:
  print("No")
else:
  print("Yes")

Solution (Python):
n = int(input())
w = input()
temp_set = {w}
c = w[-1]
ans = "Yes"
for _ in range(n - 1):
    w = input()
    if w[0] != c or w in temp_set:
        ans = "No"
        break
    temp_set.add(w)
    c = w[-1]
print(ans)

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

memo = [W[0]]
OK = True
pre = W[0]
for word in W[1:]:
    if word in memo or pre[-1] != word[0]:
        OK = False
        print("No")
        break
    memo.append(word)
    pre = word
if OK:
    print("Yes")

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

Solution (Python):
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

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

if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())
Word = []
tail = ""
for i in range(N):
    W = list(input())
    head = W[0]
    W = ''.join(W)
    if i != 0:
        if tail != head or (W in Word):
            print("No")
            exit()
    tail = W[-1]
    Word.append(W)
print("Yes")

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

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

Solution (Python):
n = int(input())
resl = "Yes"
wrds = set()
for i in range(n):
  sng = input()
  if i==0:
    lst = sng[len(sng)-1]
    wrds.add(sng)
  elif sng[0]==lst and (sng not in wrds):
    lst = sng[len(sng)-1]
    wrds.add(sng)
  else:
    resl = "No"
print(resl)

Solution (Python):
n = int(input())
words = set()
lastWord = None
for _ in range(n):
  word = input()
  if word in words:
    print('No')
    break
  words.add(word)
  
  if lastWord and lastWord[-1] != word[0]:
    print('No')
    break
  lastWord = word
else:
  print('Yes')

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

S = [input() for _ in range(n)]

buf = set()

target = S[0][0]
for s in S:
    if s in buf:
        print("No")
        exit()
    else:
        if s[0] != target:
            print("No")
            exit()

        buf.add(s)
        target = s[-1]

print("Yes")

Solution (Python):

n = int(input())
w = [input() for i in range(n)]
wset = set(w)
flag = True
if len(wset) != n:
  flag = False

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

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

Solution (Python):
n = int(input())
words = []
for i in range(n):
    word = input()
    words.append(word)
    if i != 0:
        if last != word[0]:
            print('No')
            exit()
    last = word[-1]

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

Solution (Python):
import sys
n = int(input())
ls = [str(input()) for i in range(n)]
if len(ls) != len(list(set(ls))):
    print("No")
    sys.exit()
for i in range(n):
    if i == 0:
        a = ls[0]
    else:
        if ls[i-1][-1] == ls[i][0]:
            continue
        else:
            print("No")
            sys.exit()
print("Yes")

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

  if len(W) == 0 or (W.count(w) == 0 and l == w[0]):
    W.append(w)
    l = w[-1]
  else:
    print("No")
    exit()    

print("Yes")

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

for i in range(1, N):
  if W.count(W[i]) != 1 or W[i - 1][-1] != W[i][0]:
    flag = False
    break

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[input() for i in range(n)]
    ll=[]
    ans='Yes'
    if len(set(l))!=n:
        ans='No'
    else:
        for j in range(n-1):
            if l[j][-1]==l[j+1][0]:
                ll.append(l[j])
            else:
                ans='No'
                break
    print(ans)
resolve()

Solution (Python):
n = int(input())
w_list = [input() for i in range(n)]
dum = w_list[0][-1]

for i in range(1,n):
    if w_list[i][0] != dum:
        print("No")
        exit()
    dum = w_list[i][-1]
w_list_len = len(w_list)
w_set = set(w_list)
w_set_len = len(w_set)
if w_set_len != w_list_len:
    print("No")
else:
    print("Yes")

Solution (Python):


def main():
    N, *W = map(str, open(0).read().split())
    
    if not int(N) == len(set(W)):
        print('No')
    else:
        for i in range(1, int(N)):
            if not W[i][0] == W[i -1][-1]:
                print('No')
                exit()
        print('Yes')


main()

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

Solution (Python):
n = int(input())
w_list = [input() for nesya in range(n)]
a = len(set(w_list))
t = 1
c = 0
while t < n:
  if (w_list[t-1])[-1] != (w_list[t])[0]:
    print('No')
    c += 1
    break
  t +=1
if c == 0:
  if a == n:
    print('Yes')
  else:
    print('No')

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

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