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())
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")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os, sys, re, math

N = int(input())
flg = False
words = []
for _ in range(N):
    w = input()
    if w in words:
        flg = True
        break
    else:
        words.append(w)

prev = words[0]
cur = ''

if flg:
    print('No')
else:
    for i in range(1,len(words)):
        cur = words[i]
        if prev[-1] == cur[0]:
            prev = words[i]
        else:
            flg = True
            print('No')
            break
    if flg == False:
        print('Yes')

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()

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

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

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
s = set()
for i in range(n):
    w = input()
    c = len(s)
    s.add(w)
    if i > 0:
        if w0[len(w0)-1] != w[0] or c+1 != len(s):
            print("No")
            exit()
    w0 = w

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
result = True
ws = set()
last = ""
for a in range(n):
    w = input()
    top = w[0]
    if (a > 0):
        if (last != top):
            result = False
            break
    ws.add(w)
    last = w[len(w) - 1]
    
if (len(ws) != n):
    result = False

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

Submission status: Accepted

Solution code:
line = raw_input()
N = int(line)
W = [raw_input() for i in range(0, N)]
ret = True
if len(W) != len(set(W)):
    ret = False
else:
    last = W[0][0]
    for word in W:
        if last != word[0]:
            ret = False
            break
        last = word[-1]

print 'Yes' if ret else 'No'

Submission status: Accepted

Solution code:
import os, sys, re, math

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

result = 'Yes'
for i in range(N):
    w = input()
    if W and (w in W or W[-1][-1] != w[0]):
        result = 'No'
        break
    W.append(w)

print (result)

Submission status: Accepted

Solution code:
N = int(input())
As = []
ng = False
for i in range(N):
    t = input()
    if As.count(t) or (As and As[-1][-1] != t[0]):
        ng = True
    As.append(t)
print('No' if ng else 'Yes')

Submission status: Accepted

Solution code:
N=int(input())
l=[]
f=1
for n in range(N):
    s=input()
    if len(l)>0:
        if s in l or l[-1][-1] != s[0]:
            f=0
            print("No")
            break
    l.append(s)
if f:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
if __name__ == '__main__':
    N = int(input())
    words = defaultdict(int)
    before = ''
    flag = True
    for n in range(N):
        s = str(input())
        if words[s] == 0:
            if n == 0 or before[-1] == s[0]:
                words[s] += 1
                before = s
            else:
                flag = False
                break
        else:
            flag = False
            break
    if flag:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    W=[input() for _ in range(n)]
    for i in range(n):
        w=W.pop()
        if w in W:
            print("No")
            return
        if W:
            if not w[0]==W[-1][-1]:
                print("No")
                return
    print("Yes")
resolve()

Submission status: Accepted

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

ex_list = []
for i in range(N):
    if W[i] in ex_list:
        print('No')
        break
    elif i == 0 or (i > 0 and W[i-1][-1] == W[i][0]):
        ex_list.append(W[i])
        continue
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
l=[input() for x in range(n)]
ll=[]
cont=0
if len(l)==len(set(l)):
    for i in range(n):
        ll.append(list(l[i]))
    for i in range(n-1):
        if ll[i][-1]==ll[i+1][0]:
            cont+=1
    if n-1==cont:
        print("Yes")
    else:
        print("No")                

else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
w = []

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

w_count = Counter(w)
if max(w_count.values()) > 1:
    print("No")
    exit()

for i in range(n - 1):
    tmp1, tmp2 = w[i][-1], w[i + 1][0]

    if tmp1 != tmp2:
        print("No")
        break

    if i == n - 2:
        print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
words = []
before= input()
words.append(before)
flag = True
for _ in range(n-1):
  
  s = input()
  if before[-1] != s[0]:
    flag = False
  before = s
  words.append(s)

l = len(set(words))
if l != n:
  flag = False
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n = int(input())

w = [input() for i in range(n)]
if len(w) != len(set(w)):
    print("No")
    exit()

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

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(1, n):
    if w[i - 1][-1] != w[i][0]:
        print("No")
        exit()
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int((input()))
a = [str(input()) for _ in range(n)]

ans = "Yes"
b = []
c = a[0][0]
for i in a:
    if c == i[0] and i not in b:
        c = i[-1]
        b.append(i)
    else:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = input().strip()
ind = 0
hist = [a]
for _ in range(N-1):
    b = input().strip()
    if b in hist or a[-1]!=b[0]:
        ind = 1
        break
    hist.append(b)
    a = b
if ind==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
L = []
flag = True
for i in range(N):
    new = input()
    if new in L:
        flag = False
        break
    if L != []:
        if L[-1][-1] != new[0]:
            flag = False
            break
    L.append(new)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = set()
lst = []
for i in range(N):
    s = input()
    a.add(s)
    lst.append(s)
if len(a) != N:
    print('No')
    exit()
for i in range(N-1):
    if lst[i][-1] == lst[i+1][0]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for i in range(n)]
if len(s) != len(set(s)):
  print("No");exit()
for c,d in zip(s[0:],s[1:]):
  if c[-1] != d[0]:
    print("No");exit()
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for i in range(n)]
if (len(s) != len(set(s))):
  print("No");exit()
for c,d in zip(s[0:],s[1:]):
  if c[-1] != d[0]:
    print("No");exit()
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for i in range(n)]
if (len(s) == len(set(s))) == 0:
  print("No")
  exit()
for c,d in zip(s[0:],s[1:]):

  if c[-1] == d[0]:
    pass
  else:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
List=list(input() for i in range(N))

if len(set(List))!=len(List):
  print("No")

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[input() for i in range(n)]
s=0
for i in range(n-1):
    if a[i][-1]!=a[i+1][0]:
        s+=1
a.sort()
for i in range(n-1):
    if a[i]==a[i+1]:
        s+=1
if s==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = [input() for _ in range(N)]
b=A[0][0]
for i in range(N):
  if b==A[i][0]:
    b=A[i][-1]
  else:
    print("No")
    exit()
A.sort()
for i in range(N-1):
  if A[i]==A[i+1]:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
A = [input()]
C = 0
for i in range(N-1):
    B = input()
    if A[i][-1] == B[0]:
        A.append(B)
    else:
        C +=1
        break
A = set(A)
if C == 1:
    print("No")
elif len(A) == N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys


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

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

Submission status: Accepted

Solution code:
n=int(input())
word=[]
flag=0

for i in range(n):
  word.append(list(input()))
  
for i in range(n-1):
  if word[i][-1]!=word[i+1][0]:
    flag+=1
  word[i]=''.join(word[i])
word[-1]=''.join(word[-1])

for i in range(n):
  count=0
  for k in range(n):
    if word[i]==word[k]:
      count+=1
  if count>=2:
    flag+=1
    
if flag==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1, n):
  if a[i-1][-1]!=a[i][0] or a[i] in a[:i-1]:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC109b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
words = set()
lastWord = ''
for i in range(n):
    word = input()[:-1]
    if (i != 0 and word[0] != lastWord[-1] or word in words):
        print('No')
        exit()
    lastWord = word
    words.add(word)
print('Yes')

Submission status: Accepted

Solution code:
# ABC109B - Shiritori
def main():
    N, *W = open(0).read().split()
    cur, used = W[0], {W[0]}
    for i in W[1:]:
        if cur[-1] == i[0] and i not in used:
            cur = i
            used.add(i)
        else:
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input()); W = [input() for _ in range(N)]; t = W[0][0]
for i in range(N):
  if W.count(W[i]) > 1:
    print("No")
    exit(0)
  if W[i][0] != t:
    print("No")
    exit(0)
  t = W[i][-1]
print("Yes")

Submission status: Accepted

Solution code:
import sys
n = int(input())
src = [input() for _ in range(n)]
tmp = ''
for i,s in enumerate(src):
    if i == 0:
        tmp = s[-1]
    else:
        if s[0] != tmp:
            print('No')
            sys.exit()
        tmp = s[-1]
if len(src) != len(set(src)):
    print('No')
    sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from math import sin, cos, radians

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

    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())

a=[]
ans=0
for i in range(N):
  s=input()
  
  if i>=1:
    if s[0]!=a[-1][-1]:
      ans=1
      break
   
  if a.count(s)>0:
    ans = 1
    break
  
  a.append(s)

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

Submission status: Accepted

Solution code:
n = int(input())
w = [input()]
ans = 'Yes'
for _ in range(n-1):
  s = input()
  if s in w:
    ans = 'No'
    break
  if w[-1][-1] != s[0]:
    ans = 'No'
    break
  w.append(s)

print(ans)

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(1,n):
    if w[i][0]!=w[i-1][-1]:
      print("No")
      exit()
      
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
swi = "Yes"
for i in range(n - 1):
    if w.count(w[i]) > 1 or w[i][-1] != w[i + 1][0]:
        swi = "No"
print(swi)

Submission status: Accepted

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

if len(set(w)) is not n:
    print('No')
    exit()

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

Submission status: Accepted

Solution code:
n=int(input())

bk=input()
word=[bk]
for _ in range(1,n):
  s=input()
  if s[0]!=bk[-1] or s in word:
    print("No")
    exit()
  else:
    word.append(s)
    bk=s

print("Yes")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

import copy

N=int(input())
W = [input().split() for _ 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(N):
    W[i] = list(W[i][0])

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


print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = []
for i in range(n):
  w.append(input())
k = 0
for i in range(n-1):
  if w[i][-1] == w[i+1][0]:
    k += 1

print('Yes' if k == n-1 and len(set(w)) == n else 'No')

Submission status: Accepted

Solution code:
N = int(input())
WList = []
wrongflag = False
lastword = ''

for _ in range(N):
    word = input()
    if word in WList:
        wrongflag = True
    if lastword != '' and lastword != word[0]:
        wrongflag = True

    WList.append(word)
    lastword = word[-1]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
W=[input() for i in range(N)]
Ws=sorted(W)
for i in range(1,N):
  if Ws[i-1]==Ws[i] or W[i-1][-1]!=W[i][0]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
import collections

n = int(input())
ws = [input().strip() for _ in range(n)]

counter = collections.Counter()
ok = True
prev = ws[0][0]
for w in ws:
    counter[w] += 1
    if counter[w] > 1 or w[0] != prev:
        ok = False
        break
    prev = w[-1]
if ok:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
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()
    elif W[i] in W[i+1:]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

flag = True
tmp = []
for i in range(N):
    W = str(input())
    if i == 0:
        tmp.append(W)
    else:
        if W in tmp:
            flag = False
        else:
            if tmp[-1][-1] != W[0]:
                flag = False
            tmp.append(W)

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

Submission status: Accepted

Solution code:
import sys

N=int(input())

flag=0

word=[]

for i in range(N):
    buf=input()
    if word.count(buf)==0:
        word.append(buf)
    else:
        flag=1

if flag!=1:
    for i in range(N-1):
        #print(word[i][-1])
        #print(word[i+1][0])
        if word[i][-1]!=word[i+1][0]:
            print('No')
            sys.exit()
    print('Yes')
else:
    print('No')
    sys.exit()

Submission status: Accepted

Solution code:
N=int(input())
ls=[input() for i in range(N)]
flag="Yes"
for i in range(1,N):
  if ls[i][0]!=ls[i-1][-1]:
    flag="No"
    break
x=len(set(ls))
if x<N:
  flag="No"
print(flag)

Submission status: Accepted

Solution code:
N = int(input())
word_list = []
word_old = input()
word_list.append(word_old)
flag = 0
for i in range(1, N):
    word = input()
    if word[0] != word_old[-1] or word in word_list:
        print("No")
        flag = 1
        break
    word_old = word
    word_list.append(word_old)

if flag == 0:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
w=[]
ans='Yes'
for i in range(n):
    w.append(input())
for i in range(1,n):
    if w[i][0]==w[i-1][-1] and w.count(w[i])==1:
        continue
    else:
        ans='No'
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

w = list(input() for i in range(N))
a = {}
a[w[0]] = 1
flag = 0
for i in range(1,N):
    if w[i-1][-1] != w[i][0]:
        flag = 1
        break
    if w[i] in a:
        flag = 1
        break
    a[w[i]] = 1
if flag == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import collections
N=int(input())
siritori=collections.defaultdict(int)
prev=" "
for i in range(N):
  word = input()
  if word in siritori:
    print("No")
    exit(0)
  elif prev[-1]!=word[0] and i != 0:
    print("No")
    exit(0)
  siritori[word]+=1
  prev=word
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(raw_input())
W = []
ans = True
for i in range(N):
    W.append(raw_input())
    
for i in range(0,len(W)):
    if W.count(W[i]) != 1:
        ans = False
        break

for i in range(0,len(W)-1):
    A = W[i]
    B = W[i+1]
    if A[-1] != B[0]:
        ans = False
        break

if ans:
    print "Yes"
else:
    print "No"

Submission status: Accepted

Solution code:
#ABC109B
n = int(input())
w = [0]*n
for i in range(n):
    w[i] = input() #文字列なのでintはいらない
    
flag = False
for i in range(n-1):
    if w[i][len(w[i])-1] != w[i+1][0]:
        flag = True

s = set()
for i in range(n):
    if w[i] in s:
        flag = True
    else:
        s.add(w[i])

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

Submission status: Accepted

Solution code:
N = int(input())

used_word_list = []
for n in range(N):
  if n == 0:
    pre_word = input()
    used_word_list.append(pre_word)
    pre_word = pre_word[-1]
    continue
  else:
    word = input()
    word_first = word[0]
    
    if (pre_word != word_first) or (word in used_word_list):
      print('No')
      exit()
    
    pre_word = word[-1]
    used_word_list.append(word)

print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())

w = stdin.readline().rstrip()
w_lst = [w]
prev = w[-1]
f = True

for _ in range(n-1):
  w = stdin.readline().rstrip()
  if(w[0] != prev or w in w_lst):
    f = False
    break
  else:
    w_lst.append(w)
    prev = w[-1]
    
if f: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
"""#################################################################
【ABC109】
B_Shiritori
#################################################################"""

#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N = II()
txt = []
good = True
txt = [IS() for i in range(N)]
for s in txt:
    if txt.count(s) > 1:
        good = False
for i in range(N-1):
    if txt[i][-1] != txt[i+1][0]:
        good = False
if good == True:
    print("Yes")
else:
    print("No")

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')
      exit()
  print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
w = []
for i in range(n):
    item = str(input())
    if i == 0:
        w.append(item)
    elif i!=0:
        if w[i-1][-1]==item[0]:
            w.append(item)
        elif w[i-1][-1]!=item[0]:
            print("No")
            exit()
l = set(w)
if len(l)==len(w):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
"""#################################################################
【ABC109】
B_Shiritori
#################################################################"""

#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N = II()
txt = []
good = True
for i in range(N):
    txt += [IS()]
for s in txt:
    if txt.count(s) > 1:
        good = False
for i in range(N-1):
    if txt[i][-1] != txt[i+1][0]:
        good = False
if good == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

W0 = input()
W = []
W.append(W0)
for i in range(N - 1):
    W1 = input()
    if W0[-1] != W1[0] or W1 in W:
        print("No")
        exit()
    W.append(W1)
    W0 = W1
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

ini = W[0][0]
for i in W:
    if i[0] == ini:
        ini = i[-1]
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

before = L[0]
words = set([before])
for i in range(1, N):
    if before[-1] is not L[i][0] or L[i] in words:
        print("No")
        exit()
    before = L[i]
    words.add(before)

print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
S=[input() for _ in range(n)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = input()
words = set([w])
e = w[-1]
for _ in range(n - 1):
	w = input()
	if w in words or e != w[0]:
		print('No')
		break
	e = w[-1]
	words.add(w)
else:
	print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
W=[input() for i in range(N)]
result='Yes'
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        result='No'
        break
W_unique=list(set(W))
if len(W) != len(W_unique):
    result='No'
print(result)

Submission status: Accepted

Solution code:
def main():
    N = int(input())

    ok = True
    said = set()
    pre = input()
    said.add(pre)
    for i in range(1, N):
        w = input()
        if w in said:
            ok = False
            # print("double:", w)
        elif pre[-1] != w[0]:
            ok = False
            # print("invalid word:", w)
        else:
            pre = w
            said.add(w)
    
    if ok:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC109 B - Shiritori 
n = int(input())
L = [input() for i in range(n)]
ans = "Yes"
if len(L) != len(set(L)):
    ans = "No"
for i in range(n-1):
    if L[i][-1] !=L[i+1][0]:
        ans ="No"
print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
word = input()
li = [word]
end = word[-1]
ans = 'Yes'
for i in range(n-1):
    word = input()
    if word[0] != end or word in li:
        ans = 'No'
        break
    end = word[-1]
    li.append(word)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
li = [input() for _ in range(N)]
se = set(li)

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

if len(li) != len(se):
    Flag = False
        
if Flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if n != 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")