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



Sample input:
4
hoge
english
hoge
enigma


Sample output:
No

Submission status: Accepted

Solution code:
n = int(input())
ans = True
already = set()
memory = 0
for i in range(n):
    w = input()
    if (memory == 0 or memory == w[0]) and not w in already:
        memory = w[len(w)-1]
        already.add(w)
    else:
        ans = False
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())

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

flag=1
for i in range(N-1):
  #print(W[i],W[i][-1],W[i+1],W[i+1][0])
  if W[i][-1]!=W[i+1][0]:
    flag=0
    break
  if W.count(W[i])>=2:
    flag=0
    break
    
print('Yes' if flag==1 else 'No')

Submission status: Accepted

Solution code:
n=int(input())
wl=[input() for i in range(n)]
f=0
if len(wl)==len(set(wl)):
  for i in range(n):
    if i==0:
      pass
    else:
      if wl[i][0]==wl[i-1][-1]:
        pass
      else:
        f=1
else:
  f=1
print("Yes" if f==0 else "No")

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

check = set([W[0]])
flag = True
before = W[0][-1]
for i in range(1, N):
    if before != W[i][0] or W[i] in check:
        flag = False
        break
    else:
        before = W[i][-1]
        check.add(W[i])

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

Submission status: Accepted

Solution code:
n=int(input())
l=[input() for  i in range(n)]
if len(set(l))!=n:print("No");exit()
h=l[0][0]
for i in l:
  if h==i[0]:h=i[-1]
  else:print("No");exit()
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
ans="Yes"
dic={}
w=input()
last=w[-1]
dic[w]=dic.get(w,0)+1
for i in range(n-1):
    w=input()
    if dic.get(w,0)==1 or w[0]!=last:
        ans="No"
        break
    dic[w]=dic.get(w,0)+1
    last=w[-1]

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
X = [str(input()) for i in range(N)]
ans = 'Yes'
for i in range(1,N):
    if X[i][0] == X[i-1][-1]:
        pass
    else:
        ans = 'No'
count = set(X)
if len(count) != len(X):
    ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
wl = [input()]
rule = True
for i in range(1,n):
    s = input()
    if s in wl or s[0] != wl[-1][-1]:
        rule = False
    wl.append(s)

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

Submission status: Accepted

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

if len(set(W)) != N:
  print('No')
  exit()
  
for i in range(1,N):
  b = W[i-1]
  a = W[i]
  if b[len(b)-1] != a[0]:
    print('No')
    exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys
N = int(input())
W = [input() for _ in range(N)]

if len(set(W)) != len(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')

Submission status: Accepted

Solution code:
n=int(input())
words=[]
def siritori(word):
    global words
    if words==[]:
        words.append(word)
        return True
    if (word not in words) and words[-1][-1]==word[0]:
        words.append(word)
        return True
    return False

ans=0
for i in range(n):
    if not siritori(input()):
        ans+=1
if ans==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
check = set()
p = ''
for i in range(n):
  now = input()
  if i == 0:
    p = now
    check.add(now)
    continue
  if p[-1] != now[0] or now in check:
    print('No')
    exit()
  check.add(now)
  p = now
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b_list =[]
for i in range(a):
    b = input()
    b_list.append(b)
def again(p,q):
    #p=a int
    #q= b_list list
    count = 0
    for i in range(p):
        if  q.count(q[i]) == 2:
            return False
            break
        else:
            count += 1
    if count == p:
        return True

def tail_head(p,q):
    count = 0
    for i in range(p-1):
        if q[i][len(q[i])-1]== q[i+1][0]:
            count += 1
        else:
            return False
            break
        if count == p-1:
                return True
                
if again(a,b_list) and tail_head(a,b_list):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
first = input()
shiritori = [first]
t = 0
for i in range(N-1):
  lastword = shiritori[-1]
  nextword = input()
  lastchara = list(lastword)[-1]
  nextchara = list(nextword)[0]
  if lastchara == nextchara:
    shiritori.append(nextword)
    if shiritori.count(nextword) > 1:
      t += 1
  else:
    t += 1
if t == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
from sys import exit
N = int(input())
w = [input()]
for i in range(N - 1):
  last = w[i] 
  word = input()
  if word in w or word[0] != last[len(last) - 1]: 
    print("No")
    exit()
  w.append(word)  
print("Yes")

Submission status: Accepted

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

def checkDuplication(wordList):
    if len(set(wordList)) == n:
        return True
    else :
        return False

def checkMatch(wordList):
    checkCount = 0
    for i in range(n-1):
        if wordList[i][-1] == wordList[i+1][0]:
            pass
        else:
            checkCount += 1
    
    if checkCount:
        return False
    else: 
        return True

if checkMatch(w) and checkDuplication(w):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:

def Shiritori(n , wli):

    ans = "Yes"

    if len(set(wli)) != len(wli):
        ans = "No"
    else:
        last = (wli[0])[0]
        for i in wli:
            if last != i[0]:
                ans = "No"
                break
            last = i[-1]

    return ans

def main():
    n = int(input())
    wli = [str(input()) for i in range(n)]
    print(Shiritori(n , wli))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
count = 0
for i in range(n):
     if len(set(sorted(w))) != n:
          count += 2
for i in range(n-1):
     if w[i][-1] == w[i+1][0]:
          count += 1
if count == n-1:
     print("Yes")
else:
     print("No")

Submission status: Accepted

Solution code:
n = int(input())
check = True
ss = ''
str_set = set()

for i in range(n):
  s = input()
  str_set.add(s)
  if ss != '':
    if ss[-1] != s[0]:
      check = False
      break  
  ss = s  
  
if len(str_set)!=n: check = False
  
if check:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
history = set()
prev = W[0][::-1]
for w in W:
    #print(w in history, w[0], prev[-1])
    if w in history or w[0] != prev[-1]:
        print('No')
        break

    history.add(w)
    prev = w
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
ans = "No"
l=0
t = w[0]
i=0
while(True):
    if len(set(w))!=n:
        break
    for s in w:
        if i==0:
            i+=1
        else:
            if t[len(t)-1:]==s[0]:
                l+=1
            t=s
    break
if l+1==n:
    ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
n, *l = open(0).read().split()
print("Yes" if len(set(l)) == len(l) and all(l[i][-1] == l[i+1][0] for i in range(int(n)-1)) else "No")

Submission status: Accepted

Solution code:
n=int(input())
B=[]
S = 0
for i in range(0,n):
    B.append((input()))
C = set(B)
if len(B) != len(C):
    print("No")
else:
    for m in range(n-1):
        if B[m][-1] == B[m+1][0]:
            S += 1
    if S == n-1:
        print("Yes")
    else: 
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
lst = [input() for i in range(n)]
if all([lst[i][-1] == lst[i+1][0] for i in range(n-1)]) and len(set(lst)) == n:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
#ABC-109-B
N = int(input())
ans = "Yes"
memo = {}
word = input()
memo[word] = None
last_char = word[-1]

for _ in range(N-1):
    word = input()
    if word in memo:
        ans = "No"
        break
    if word[0] != last_char:
        ans = "No"
        break
    memo[word] = None
    last_char = word[-1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Dict = {}
flag = 0 

first_f = input()
Dict[first_f]=1
last_f = first_f[-1]

for _ in range(N-1):
  f = input()
  if f[0]!=last_f:
    flag=1
    break
  else:
    if f in Dict:
      Dict[f]+=1
    else:
      Dict[f]=1
  last_f = f[-1]
      
l = [i for i in list(Dict.values()) if i>=2]
if len(l)>=1:
  flag=1
if flag==1:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w_list = [input() for _ in range(n)]
for i in range(1, n):
    if w_list[i - 1][-1] != w_list[i][0] or w_list[i] in w_list[:i]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = defaultdict(lambda : False)
flag = True
for i in range(n):
    w = input()
    if i == 0:
        tmp = w
        d[w] = True
        continue
    if tmp[-1] != w[0]:
        flag = False
    if d[w]:
        flag = False
    d[w] = True
    tmp = w
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
W = [input() for _ in range(n)]
L = [""] * n
ans = "Yes"

for i in range(n - 1):
    if W[i][-1] == W[i + 1][0] and W[i] not in L:
        L[i] = W[i]
    else:
        ans = "No"
        break

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
k=0
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]:k+=1
    if k==n-1:print('Yes')
    else:print('No')

Submission status: Accepted

Solution code:
n = int(input())
w=[]
w.append(input())
a = False
for i in range(n-1):
    w.append(input())
    if not(w[i][-1]==w[i+1][0] and sorted(w)==sorted(set(w))):
        print('No')
        a = True
        break
if a==False:
    print('Yes')

Submission status: Accepted

Solution code:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

#ここから書き始める
n = int(input())
a = []
yes = True
for i in range(n):
    w = input()
    if i != 0 and a[i - 1][-1] != w[0]:
        yes = False
    a.append(w)
# print(a)
a_set = set(a)
if len(a_set) != n:
    yes = False
if yes:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a=int(input())
b=[]
c=""
for i in range(a):
    b.append(str(input()))
for j in range(a-1):
    if b[j][-1]==b[j+1][0]:
        if len(set(b))==a:
            c="Yes"
        else:
            c="No"
            break
    else:
        c="No"
        break
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

w=set(W)
answer="Yes"

if len(w)==len(W):
    for i in range(1,N):
        if W[i-1][len(W[i-1])-1]==W[i][0]:
            pass
        else:
            answer="No"
            break
    print(answer)
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
w = nsn(n)

flag = True
dic = dict()
last = w[0][0]
for i in range(n):
    if dic.get(w[i], False):
        flag = False
    if last != w[i][0]:
        flag = False
    last = w[i][-1]
    dic[w[i]] = True

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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
S = set()
ans = 'Yes'
for i in range(N-1):
    if W[i] in S:
        ans = 'No'
        break
    else:
        S.add(W[i])
    
    if W[i][-1] != W[i+1][0]:
        ans = 'No'
        break 

if W[N-1] in S:
    ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
S=[]
for i in range(n):
  s=input()
  S.append(s)
flg=True
for i in range(1,n):
  if S[i][0]!=S[i-1][-1]:
    print('No')
    exit()

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

Submission status: Accepted

Solution code:
N = int(input())
word = []
flag = 0
for i in range(N):
    S = input()
    if i == 0:
        word.append(S)
    else:
        if S in word:
            print("No")
            flag += 1
            break
        else:
            if word[i-1][len(word[i-1])-1] == S[0]:
                word.append(S)
            else:
                print("No")
                flag += 1
                break
if flag == 0:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
used = set()
used.add(W[0])
prev = W[0][-1]
for w in W[1:]:
    if prev != w[0] or w in used:
        print('No')
        exit()
    prev = w[-1]
    used.add(w)
print('Yes')

Submission status: Accepted

Solution code:
st = set()
cant = False
prev = "-"
for i in range(int(input())):
        s = input()
        if (prev!="-" and prev!=s[0]) or s in st: cant = True
        prev = s[-1]
        st.add(s)
print("YNeos"[cant::2])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
word = []
flag = 1
for i in range(N):
  st = input()
  if i > 0 :
    if final != st[0]:
      flag = 0
    elif st in word:
      flag = 0
    else:
      final = st[-1]
      word += [st]
  else:
    final = st[-1]
    word += [st]
if flag:
  print("Yes")
else :
  print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
w = [input() for _ in range(n)]

tmp = []
ans = "Yes"
for i in range(n-1):
    if w[i] in tmp:
        ans = "No"
        break
    if not w[i] in tmp:
        tmp.append(w[i])
    if w[i][-1] != w[i + 1][0]:
        ans = 'No'
        #print('B')
#print(tmp)
if w[-1] in tmp:
    ans = "No"
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
wlst = [input() for i in range(N)]
wset = set(wlst)
if len(wset) != N:
    print('No')
    exit()

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

print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = [input() for _ in range(n)]
ok = True
if len(a) != len(set(a)):
    ok = False
for i in range(n-1):
    if a[i][-1] != a[i+1][0]:
        ok = False
print('Yes' if ok else 'No')

Submission status: Accepted

Solution code:
N = int(input())
s = set()

flag = True
for i in range(N):
    S = input()
    if S in s:
        flag = False
    if i > 0 and S[0] != prev:
        flag = False
    s.add(S)
    prev = S[-1]
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
w=[str(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")
        break
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    w = [input() for i in range(n)]
    d = defaultdict(lambda : 1)
    p = w[0][0]
    for i in w:
        if not d[i]:
            print("No")
            return
        d[i] = 0
        if p != i[0]:
            print("No")
            return
        p = i[-1]
    print("Yes")
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [input() for i in range(N)]
    if len(A) != len(set(A)):
        return print("No")
    pre = A[0][-1]
    for a in A[1:]:
        if pre != a[0]:
            return print("No")
        pre = a[-1]
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
word = [input() for _ in range(n)]
count=0
for i in range (0,n):
    for j in range (i+1,n):
        if (word[i] == word[j]):
            count += 1
for k in range (0,n-1):
    if (word[k][len(word[k])-1] != word[k+1][0]):
        count += 1
if (count == 0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    w = list()
    for i in range(n):
        w.append(input())

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

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

    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
l = []
ans = 'Yes'
ps = 'a'
for i in range(n):
  s = input()
  if s in l:
    ans = 'No'
  l.append(s)
  if i != 0 and ps[-1] != s[0]:
    ans = 'No'
  ps = s

print(ans)

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
n=int(input())
w=[]
w.append(input())
for i in range(n-1):
    s=input()
    if  s[0]!=w[-1][-1]:
        pass
    else:
        w.append(s)

l=len(list(set(w)))

if l!=n:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# Problem B - Shiritori

# input
N = int(input())

# initialization
last = input()
word_list = []
word_list.append(last)
is_ok = True

# search
for i in range(N-1):
    tmp = input()
    if tmp in word_list or not last[-1]==tmp[0]:
        is_ok = False
        break
    else:
        last = tmp
        word_list.append(tmp)

# output
if is_ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
w=list()
for i in range(n):
    w.append(input())
ws=set(w)
if len(ws)!=n:
    print("No")
    exit()
x=0
for i in range(n-1):
    x=i+1
    if w[i][-1]!=w[x][0]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
def has_duplicates(words):
    return len(words) != len(set(words))

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

def shiritori(shiritori_words):
    ans = []
    word = shiritori_words[0]
    end_word = word[len(word) -1]
    for j in range(1, len(shiritori_words)):
        word = shiritori_words[j]
        first_word = word[0]
        if has_duplicates(shiritori_words) or end_word != first_word:
            ans.append("No")
        else:
            ans.append("Yes")
        end_word = word[len(word) - 1]
    return ans
            
        

n = int(input())
shiritori_words = words(n)
ans = shiritori(shiritori_words)
if "No" in ans:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

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

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = [input().strip() for _ in range(N)]

# 重複があると前者を満たさない。後者を満たさないとしりとりになっていない
if len(W) == len(set(W)) and all(W[i + 1][0] == W[i][-1] for i in range(N - 1)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
s = set()
word = input()
s.add(word)
last = word[-1]
for i in range(N-1):
  word = input()
  if word in s or word[0] != last:
    print('No')
    quit()
  else:
    s.add(word)
    last = word[-1]

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
W = [input().strip() for _ in range(N)]

already_used = set()
current_word = W[0][0]

ans = 'Yes'
for word in W:
    if word in already_used or current_word[-1] != word[0]:
        ans = 'No'
        break
    already_used.add(word)
    current_word = word
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
w = input()
s = set()
s.add(w)
ans = "Yes"
for i in range(n - 1):
    tmp = w[len(w)-1]
    w = input()
    if (w[0] == tmp) and not (w in s):
        s.add(w)
    else:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    word_lst = []
    previous_word = input()
    word_lst.append(previous_word)
    ok = True
    for i in range(1,n):
        now_word = input()
        if not (now_word[0] == previous_word[-1]):
            ok = False
            break
        if now_word in word_lst:
            ok = False
            break
        word_lst.append(now_word)
        previous_word = now_word
    if len(word_lst) != len(set(word_lst)):
        ok = False

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






if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#B - Shiritori
N = int(input())
S = list(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]:
            pass
        else:
            print("No")
            exit()
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
A = [input() for _ in range(N)]
if(len(set(A)) != len(A)):
  print("No")
  exit()

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

Submission status: Accepted

Solution code:
n = int(input())
word = []
cnt = None
for i in range(n):
    w = input()
    if w in word:
        print("No")
        exit()
    word.append(w)
cnt = word[0]
for i in range(1,n):
    if cnt[-1] != word[i][0]:
        print("No")
        exit()
    cnt = word[i]
print("Yes")

Submission status: Accepted

Solution code:

n = int(input())
w = []
status = True

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

x = list(set(w))

if len(w) != len(x):
    status = False
else:
    for i in range(n-1):
        a = ""
        b = ""
        a = w[i]
        b = w[i+1]
        if a[-1] == b[0]:
            pass
        else:
            status = False
            break

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

Submission status: Accepted

Solution code:
n = int(input())
W = list(str(input()) for _ in range(n))
W_s = set(W)
if len(W) != len(W_s):
    print("No")
    exit()

for i in range(n):
    w = W[i]
    if i == 0:
        end = w[-1]
        continue

    if w[0] == end:
        end = w[-1]
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

N = int(input())

words = []

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

ans = 'Yes'
c = collections.Counter(words)    

if c.most_common()[0][1] != 1:
    ans = 'No'
else:
    for i in range(N-1):
        tail = words[i][-1]
        head = words[i+1][0]
        if tail != head:
            ans = 'No'
            break
            
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
list_W = [input() for _ in range(n)]
list_S = [list_W[0]]
ans = "Yes"
for i in range(1, n):
    a = list(list_W[i-1])
    b = list(list_W[i])
    if a[-1] != b[0] or list_W[i]  in list_S:
        ans = "No"
    list_S.append(list_W[i])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = []
A.append("shiritori")
for i in range(N):
  t = input()
  if t in A or i != 0 and t[0] != A[i][-1]:
    print('No')
    exit()
  else:
    A.append(t)
print('Yes')

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
N = int(input())
w = [0]*N
for i in range(N):
    w[i] = input()
c = Counter(w)
if len(list(c.keys())) != N:
    print("No")
    exit()
for i in range(1,N):
    if w[i][0] != w[i-1][-1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

N = int(input())
jdg = 0

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

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    before = ''
    words = set()

    for i in range(n):
        w = input()
        if w not in words:
            words.add(w)
        else:
            print('No')
            return

        if before == '':
            before = w
            continue

        if before[-1] != w[0]:
            print('No')
            return
        before = w

    print('Yes')


main()