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())
l = [input() for _ in [0]*n]
if len(set(l)) != n:
    print('No')
else:
    for i in range(n-1):
        if l[i][-1] != l[i+1][0]:
            print('No')
            break
        else:
            continue
    else:
        print('Yes')

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

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

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

Solution (Python):
def main():
    N = int(input())
    words = []
    success = True
    for _ in range(N):
        word = input()
        if word in words:
            success = False
        if not words == []:
            if not words[-1][-1] == word[0]:
                success = False
        words.append(word)
    if success:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
words = [input() for _ in range(n)]
use = [words[0]]
for i in range(1, n):
    if words[i] in use:
        print('No')
        exit()

    if use[-1][-1] != words[i][0]:
        print('No')
        exit()

    use.append(words[i])

print('Yes')

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

Solution (Python):
import sys

n=int(input())
word=[]
for i in range(n):
	w=input()
	if w in word:
		print("No")
		sys.exit()
	if i>=1 and w[0]!=word[-1][-1]:
		print("No")
		sys.exit()
	word.append(w)
print("Yes")

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

Solution (Python):
n = int(input())
w = list(input() for i in range(n))
s = True

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

ws = set(w)
if s and len(ws)==len(w):
  print("Yes")
else:
  print("No")

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

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

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

back = w[0][-1]

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

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

print("No")

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

words = set()

flag = True
for i in range(N):
    word = input()
    if i == 0:
        words.add(word)
        prev_word = word
    else :
        if prev_word[-1] != word[0]:
            flag = False
        else :          
            words.add(word)
            prev_word = word
            
if flag:
    if len(words) == N :
        print('Yes')
    else :
        print('No')
else :
    print('No')

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

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

Solution (Python):
def solve(n, W):
    last = ''
    d = {}
    for w in W:
        if last and last != w[0] or w in d:
            return 'No'
        last = w[-1]
        d[w] = None
    return 'Yes'

_n = int(input())
_W = [input() for _ in range(_n)]
print(solve(_n, _W))

Solution (Python):

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
w = [input() for _ in range(n)]
s = sorted(w)
flag = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        flag = 1
for i in range(n-1):
    
    if w[i+1][0] != w[i][-1]:flag = 1
if flag:print("No")
else: print("Yes")

Solution (Python):
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')
      exit()
   else:
    for j in range(i+1,n):
      if w[i] == w[j]:
        print('No')
        exit()
print('Yes')

Solution (Python):
from collections import defaultdict


def solve():
    N = int(input())
    w_dict = defaultdict(int)
    pw = input()
    w_dict[pw] = 1
    for _ in range(N - 1):
        cw = input()
        if cw[0] != pw[-1] or w_dict[cw] == 1:
            print('No')
            exit()
        w_dict[cw] = 1
        pw = cw
    print('Yes')


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
W = [input() for i in range(N)]
dic = {W[0]:1}
rev = W[0][len(W[0])-1:]
for w in W[1:]:
    if w not in dic:
        dic[w] = 1
        if rev != w[0]:
            print("No")
            exit()
        rev = w[len(w)-1:]
        continue
    print("No")
    exit()
print('Yes')

Solution (Python):
N = int(input())
A = [input() for _ in range(N)]
pre = A[0]
for a in A[1:]:
  if A.count(pre) >= 2:
    print("No")
    exit()
  if pre[-1] == a[0]:
    pre = a
  else:
    print("No")
    exit()
print("Yes")

Solution (Python):
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys




read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
W = read().decode('utf8').split()
temp = W[0][-1]
Ws = set(W)
f = True
if len(Ws) != N:
    f = False

else:
    for w in W[1:]:
        if temp == w[0]:
            temp = w[-1]
        else:
            f = False
            break
print("Yes" if f else "No")

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    W=[input() for i in range(N)]
    tmp=None
    s=set()
    for w in W:
        if tmp:
            if tmp[-1]!=w[0] or w in s:
                print('No')
                exit()
            else:
                tmp=w
                s.add(w)
        else:
            tmp=w
            s.add(w)
    print('Yes')
    

if __name__ == '__main__':
    main()

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

Solution (Python):
N = int(input())
prev = input()
history = set()
history.add(prev)
ans = "Yes"
for _ in range(N-1):
    now = input()
    if now in history or prev[-1] != now[0]:
        ans = "No"
        break
    history.add(now)
    prev = now
print(ans)

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

Solution (Python):
N = int(input())
words = [input() for _ in range(N)]
w_prev = words[0]
wordlist = [w_prev]
flag = True

for i in range(1, N):
    w = words[i]
    if w_prev[-1] == w[0] and w not in wordlist:
        w_prev = w
        wordlist.append(w)
    else:
        flag = False
        break

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

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

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


for i in range(N-1):
    if W.count(W[i]) >= 2:
        print('No')
        sys.exit()
    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)]
ans='Yes'
for i in range(1,n):
  if w[i-1][-1]!=w[i][0]:
    ans='No'
    break
  for j in range(i):
    if w[i]==w[j]:
      ans='No'
      break
print(ans)

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

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

Solution (Python):
from __future__ import print_function

import sys



import fractions

from fractions import gcd







import collections
















from operator import mul


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return



















def main():
    n = int(input().strip())
    s_old = input().strip()
    C = collections.Counter()
    C[s_old] += 1

    s_new = ""

    for i in range(n - 1):
        s_new = input().strip()
        C[s_new] += 1
        if C[s_new] > 1 or s_new[0] != s_old[-1]:
            print("No")
            return
        s_old = s_new
    print("Yes")
    eprint("debug")
    pass
    return


if __name__ == '__main__':
    main()

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

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

for i in sList:
  if sList.count(i) > 1:
    print("No")
    exit(0)

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

print("Yes")

Solution (Python):
import sys
from collections import defaultdict

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    W = INPUT()

    l = defaultdict(bool)
    l[W] = True
    for i in range(N-1):
        next_W = INPUT()
        if l[next_W] or next_W[0] != W[-1]:
            print("No")
            sys.exit()
        l[next_W] = True
        W = next_W

    print("Yes")


if __name__ == '__main__':
    main()

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

Solution (Python):

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

count = n
for i in range(n - 1):
    for j in range(i + 1, n):
        if w[i] == w[j]:
            count = 0

for i in range(n - 1):
    s1 = list(w[i])
    s2 = list(w[i + 1])
    
    
    if s1[len(s1) - 1] != s2[0]:
        
        count = 0

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

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

l_f = [x for x in set(l) if l.count(x) > 1]
if len(l_f) != 0:
    print('No')
    sys.exit()
for i in l:
    
    last = i[-1]
    try:
        first = l[count][0]
        count+=1
        if last == first:
            continue
        else:
            print('No')
            sys.exit()
    except IndexError:
        print('Yes')

Solution (Python):
N=int(input())
W=[input() for i 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 sys

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

s = set()

for a, i in enumerate(w):
    if a == 0:
        lastword = i[-1]
        s.add(i)
        continue
    if i[0] != lastword or i in s:
        print("No")
        sys.exit()
    lastword = i[-1]
    s.add(i)
print("Yes")

Solution (Python):
n=int(input())
li=[input() for i in range(n)]
li2=[li[0]]

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

Solution (Python):
import sys

N=int(input())
W=[list(input()) for i in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if W[i]==W[j]:
            print("No")
            sys.exit()
for i in range(1,N):
    if W[i][0]==W[i-1][-1]:
        continue
    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(n-1):
  if w[i][-1] != w[i+1][0]:
    print('No')
    exit()

print('Yes')

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

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

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

if (len(set(w)) < len(w)):
   print('No')
   exit()

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines









def main():
	n=int(input())
	w=[input().rstrip().decode('utf-8') for _ in range(n)]
	
	now=w[0][-1]
	
	ans="Yes"
	
	wset=set(w)
	if len(wset)!=n:
		ans="No"
		
	for i in range(1,n):
		if now!=w[i][0]:

			ans="No"
		now=w[i][-1]

	
	print(ans)
	




if __name__ == "__main__":
	main()

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

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

Solution (Python):
N = int(input())
W = [input() for _ in range(N)]
b = len(set(W))==len(W) and all(map(lambda s,t:s==t, (s[-1] for s in W[:-1]) ,(s[0] for s in W[1:])))
print("YNeos"[not b::2])

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

ok = True
for i in range(1, len(words)):
    w = words[i]
    if words[i-1][-1] != w[0] or w in exsited_words:
        ok = False
        break
    exsited_words.append(w)

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

Solution (Python):
N = int(input())
A = [input() for i in range(N)]
alr = []
flag = True
for i in range(N):
    if alr:
        if alr[-1][-1] != A[i][0] or A[i] in alr:
            flag = False
            break
    alr.append(A[i])
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys

n, *words = sys.stdin.read().split()
n = int(n)

def main():
    announced = set()
    last = words[0][0]
    for w in words:
        if w in announced:
            return 'No'
        elif w[0] != last:
            return 'No'
        announced.add(w)
        last = w[-1]
    return 'Yes'

if __name__ == '__main__':
    ans = main()
    print(ans)

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

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

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

l = []
ans = 'Yes'

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

    if l.count(w) >= 1:
        ans = 'No'
        break
    
    if i > 0:
        befor = l[i - 1]

        if w[0] != befor[-1]:
            ans = 'No'
            break

    l.append(w)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
W = [input().strip() for i in range(N)]
s = set(W)
flag = False
if len(list(s)) != N:
    print("No")
else:
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            flag = True
            break
    if flag:
        print("No")
    else:
        print("Yes")

Solution (Python):
import math
import heapq
import sys
from collections import Counter
import datetime
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN




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



for i in range(N-1):
    if W[i][-1]!=W[i+1][0] or W.count(W[i])>1:
        print('No')
        sys.exit()

print('Yes')

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

flag = True

for i in range(1, n):
    if w_list[i-1][-1] != w_list[i][0]:
        flag = False
    elif w_list[i] in w_list[:i-1]:
        flag = False
if flag == True:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
W = []
for _ in range(n):
    w = input()
    if w in W:
        print('No')
        exit()
    W.append(w)

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

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

Solution (Python):


n = int(input())
a = set()
temp = input()
end_char = temp[-1]
a.add(temp)
for i in range(n-1):
    temp = input()
    if temp in a or end_char != temp[0]:
        print('No')
        exit()
    end_char = temp[-1]
    a.add(temp)
print('Yes')

Solution (Python):
B = ""
L = []
N = int(input())
W1 = input()
L.append(W1)
for _ in range(N-1):
    W = input()
    if W in L:
        print("No")
        exit()
    L.append(W)
    if not W1[-1] == W[0]:
        print("No")
        exit()
    W1 = W
print("Yes")

Solution (Python):

 
import math
import itertools
import sys
import copy
 




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


wl = []
for i in range(N) :
  if W[i] not in wl :
    wl.append(W[i])
  else :
    print ("No")
    exit()
  if i > 0 :
    if W[i-1][-1] != W[i][0] :
      print ("No")
      exit()
print ("Yes")

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

words = [input() for i in range(0, n)]

shiritori = []

def solve():
  last_char = words[0][0]
  for i in range(0, n):
    
    if words[i] in shiritori:
      print('No')
      return
    
    
    if words[i][0] != last_char:
      print('No')
      return

    last_char = words[i][len(words[i])-1]
    shiritori.append(words[i])

  print('Yes')


def main():
  solve()


if __name__ == "__main__":
  main()

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N = int(sys.stdin.buffer.readline())
W = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(N)]

ok = len(set(W)) == len(W)
for s, t in zip(W, W[1:]):
    ok &= s[-1] == t[0]
if ok:
    print('Yes')
else:
    print('No')

Solution (Python):


log = []

count = int(input())

isValid = True
prev = ""
for i in range(count):
    word = input().rstrip()
    if len(prev) > 0:
        if word[0] != prev[-1]:
            isValid = False
    if word in log:
        isValid = False

    log.append(word)
    prev = word

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

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

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

Solution (Python):
m = {}
n = int(input())
prev = ""
ok = True
for i in range(n):
  s = input()
  if i != 0:
    if prev[-1] != s[0]:
      ok = False
  if s in m:
    ok = False
  prev = s
  m[s] = 1
print("Yes" if ok else "No")

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

A = []

for i in range(n):
    s = input()
    if i == 0:
        A.append(s)
    else:
        if A[-1][-1] == s[0] and A.count(s) == 0:
            A.append(s)
        else:
            break
if len(A) == n:
    print("Yes")
else:
    print("No")

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


for i in range(N-1):
    if W[i][-1:] != W[i + 1][:1]:
        flg = False
        break
    if W[i] in words or W[i+1] in words:
        flg = False
        break
    words.add(W[i])


print('Yes') if flg == True else print('No')

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

Solution (Python):
import sys

N = int(input())
S = input()
s_tail = S[len(S)-1]
A = []
A.append(S)
flg = 0

for i in range(N-1):
    S = input()
    s_head = S[0]
    if s_tail!=s_head:
        flg = 1
    elif not (S in A):
        A.append(S)
    else:
        flg = 1

    s_tail = S[len(S)-1]

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

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

if len(set(W)) < N:
    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):
n = int(input())
w = [str(input()) for _ in range(n)]
tmp = 0

for i in range(n-1):

    if w.count(w[i])==1 and str(w[i])[-1]==str(w[i+1])[0]:
        tmp += 1

if tmp==n-1:
    print('Yes')
else:
    print('No')

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

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

print(ans)

Solution (Python):
n= int(input())
words=[input() for i in range(n)]
flag="Yes"
if len(words)!=len(set(words)):
  print("No")

else:
  for i in range(n-1):
    if words[i][-1]==words[i+1][0]:
      pass
    else:
      flag="No"
      break
  print(flag)

Solution (Python):
N = int(input())
moji = input()
moji_len = []
moji_len.append(moji)
flag = "Yes"
for i in range(N-1):
	siri = input()
	if(siri in moji_len):
		flag = "No"
	if not(moji[-1]==siri[0]):
		flag = "No"
	moji_len.append(siri)
	moji = siri
print(flag)

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

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

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

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

W_set = set(W)

flag = 0

if len(W) != len(W_set):
    print("No")
else:
    for idx, w in enumerate(W[:-1]):
        if w[-1] == W[idx + 1][0]:
            continue
        else:
            flag = 1
            break
    if flag == 0:
        print("Yes")
    else:
        print("No")

Solution (Python):
n=int(input())
w=[input() for i in range(n)]
d={}
for i in range(n):
  if w[i] not in d:
    d[w[i]]=1
  else:
    print('No')
    exit()
for i in range(n-1):
  if w[i][len(w[i])-1]!=w[i+1][0]:
    print('No')
    exit()
print('Yes')

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

judge='Yes'
for index, word in enumerate(words):
    if index == 0:
        continue
    if word[0] != words[index-1][-1]:
        judge = 'No'
        break
    if words.count(word) > 1:
        judge = 'No'
        break

print(judge)

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

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

count = len(set(l))
flag = True
for i in range(len(l) -1 ):
    if l[i][len(l[i]) -1] != l[i+1][0]:
        flag = False
        break

if flag and count == n:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
w = []
ans = "Yes"
for i in range(n):
    _w = input()
    if i > 0:
        if l != _w[0] or _w in w:
            ans = "No"

    l = _w[-1]
    w.append(_w)

print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
W = [input().rstrip() for _ in range(N)]
for i in range(1,N):
    if W[i-1][-1] != W[i][0] or W[i] in W[:i]:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
n=int(input())
W=[]
S=set([])
flag=0
for i in range(n):
  w=input()
  W.append(w)
  S.add(w)
for i in range(n-1):
  if W[i][-1]!=W[i+1][0]:
    flag=1
if len(S)==n and flag==0:
  print('Yes')
else:
  print('No')

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

for a in range(N):
	shiritori.append(input())

ans = "Yes"

for i in shiritori:
    if shiritori.count(i) != 1:
        ans = "No"
        break
    
for k in range(N-1):
    first = shiritori[k]
    second = shiritori[k+1]
    if first[-1] != second[0]:
        ans = "No"
        break


    
print(ans)

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

Solution (Python):
N = int(input())
li = []
w = input()
li.append(w)
k = 0
ans = "Yes"
for i in range(N-1) :
    word = input()
    for j in range(len(li)) :
        if li[j] == word :
            k = 1
            break
    last_word = li[-1]
    if last_word[-1] != word[0] :
        k = 1
    if k == 1 :
        ans = "No"
        break
    li.append(word)
print(ans)

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

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

l = list([input() for _ in range(N)])

is_good = True

if len(set(l)) < N:
    is_good = False

for i in range(N-1):
    if l[i][-1] != l[i+1][0]:
        is_good = False
        break

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

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

tmp = [1 for i in range(n-1) if w[i][-1]!=w[i+1][0]]


if len(tmp)>0:
  print("No")
elif len(set(w))<len(w):
  print("No")
else:
  print("Yes")

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

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

Solution (Python):
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    d = collections.defaultdict(int)
    lstr = "1"
    for i in range(n):
        w = str(readline().rstrip().decode('utf-8'))
        if (w[0] == lstr or lstr == "1") and w not in d:
            d[w]
            lstr = w[-1]
        else:
            print("No")
            exit()
    print("Yes")


if __name__ == '__main__':
    solve()

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

Solution (Python):
N = int(input())
words = []
for i in range(N):
    w = list(input())
    words.append(w)
h = {}
p = words[0][0]
f = True
for i in range(N):
    b = words[i][0]
    l = words[i][-1]
    if b != p:
        f = False
        break
    p = l
    if h.get(''.join(words[i])) != None:
        f = False
        break
    h[''.join(words[i])] = 1

if f == True:
    print('Yes')
else:
    print('No')

Solution (Python):



import sys
input = sys.stdin.readline


N = int(input())



W = [None]*N

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




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

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