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

word_set=set()
last_tail=""
for i in range(N):
  W=input()
  if W in word_set:
    print("No")
    break
  else:
    word_set.add(W)
    
  if len(word_set)>1 and last_tail!=W[0]:
    print("No")
    break
  else:
    last_tail=W[-1]
    
else:
  print("Yes")

Submission status: Accepted

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

shi = []
t = w[0][-1]
shi.append(w[0])
#print(t)
for i in range(1,n):
	if shi.count(w[i]) == 1:
		print("No")
		exit()
	else:
		if t == w[i][0]:
			t = w[i][-1]
			shi.append(w[i])
		else:
			print("No")
			exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
import collections

n=int(input())
be=""
ls=[]

for _ in range(n):
  w=input()
  if _==0:
    pass
  else:
    if be[-1]==w[0]:
      pass
    else:
      print("No")
      sys.exit()
  be=w
  ls.append(w)
  
dic=collections.Counter(ls)
count=0

for j in range(n):
  if dic[ls[j]]==1:
    count+=1
  
if count==n:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

siri = wordlist[0][0]
wordpool = []
import sys

for word in wordlist:
    if word[0] == siri and word not in wordpool:
        siri = word[-1]
        wordpool.append(word)
    else:
        print("No")
        sys.exit()
        
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=[input() for _ in range(n)]
ans="Yes"
if n!=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:
n = int(input())
w = [input() for i in range(n)]

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')

Submission status: Accepted

Solution code:
import collections
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:
from collections import defaultdict 

n = int(input())
dic = defaultdict(int)
s = [""] * n
flag = True
for i in range(n):
    s[i] = input()
    if i != 0:
        if s[i - 1][len(s[i - 1]) - 1] != s[i][0]:
            flag = False
    
    if dic[s[i]] != 0:
        flag = False
    dic[s[i]] += 1
print("Yes" if flag == True else "No")

Submission status: Accepted

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

n = int(input())
w = [''] * n
for i in range(n):
    w[i] = input().rstrip('\n')
for i in range(1, n):
    if w[i - 1][-1] != w[i][0]:
        print('No')
        exit()
if len(set(w)) == len(w):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう

N=3
M=3
i=0
j=0
k=0



N=int(input())
array=[input().split()for i in range(N)]

#for i in range(N):
#    c.append(array[i][0])

c=list(itertools.chain.from_iterable(array))
#c.sorted

for i in range(N-1):
    #s=input()
    a=[i for i in array[i][0]]
    b=[j for j in array[i+1][0]]
    "str型の2次元文字列分割入力もパターンに入れとくか"
    #print(a[-1],b[0])
    if a[-1]!=b[0]:
        print("No")
        sys.exit()

#print(c)
for i in range(N-1):
    #for j in reversed(range(N-i-2)):
    for j in (range(N-i-1)):
        #print(c[i],c[i+j+1])
        if c[i]==c[i+j+1]:
            print("No")
            sys.exit()
print("Yes")

#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ

#print(array[1][0])
"[行][列]の順番であることに注意"
#print(array)
"正方行列にstr型の値を入力"

#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ

'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"




#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

out = [input()]
f = 0
for i in range(n-1):
  in_str = input()
  if in_str[0] != out[-1][-1]:
    f = 1
    break
  if in_str in out :
    f = 1
    break
  out.append(in_str)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
W=[]

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

ans="Yes"
for j in range(1,N):
  if W[j] in W[:j]:
    ans="No"
    break
  else:
    if W[j][0]!=W[j-1][-1]:
      ans="No"
      break
      
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = []
flag = True
tmp = input()
lst.append(tmp)
for i in range(n-1):
    w = input()
    if w in lst:
        flag = False
    if tmp[-1] != w[0]:
        flag = False
    lst.append(w)
    tmp = w

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

Submission status: Accepted

Solution code:
n = int(input())
lst = [0] * n
for i in range(n):
    lst[i] = input()

flag = True
for i in range(n-1):
    if lst[i][-1] != lst[i + 1][0]:
        flag = False

print('Yes' if flag == True and len(set(lst)) == n else 'No')

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
W=[input() for i in range(n)]
cnt=0
for i in range(1,n):
    if W[i-1][-1]==W[i][0] and W[i] not in W[:i]:
        cnt+=1
if cnt==n-1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    W = [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')
                return
    
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            print('No')
            return
    
    print('Yes')

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import defaultdict
def solve():
    N = int(input())
    d = defaultdict(int)
    prev = []

    for i in range(N):
        w = input()
        if d[w] == 1:
            print('No')
            return
        d[w] += 1
        w_list = list(w)
        if i != 0 and w_list[0] != prev[-1]:
            print('No')
            return

        prev = w_list 
    else:
        print('Yes')

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

    if n != len(set(w)):
        print('No')
        return
    last_c = w[0][-1]
    for i, top_c in enumerate(w):
        if i == 0:
            continue
        
        if last_c == top_c[0]:
            last_c = top_c[-1]
        else:
            print('No')

            return
    print('Yes')
if __name__ =='__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
c = '?'
S = set()
for i in range(N):
    s = input()
    S.add(s)
    if i>0 and s[0] != c:
        print("No"); exit(0)
    c = s[-1]
print("Yes" if len(S) == N else "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:
if __name__ == "__main__":
    n = int(input())
    w = list()
    for i in range(n):
        w.append(input())

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

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

    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
used = []
pre = ""
for _ in range(n):
  cur = input()
  if pre != "" and (pre[-1] != cur[0] or cur in used):
    print("No")
    exit()
  used.append(cur)
  pre = cur
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W = []
flag = True
for i in range(N):
    Wi = input()
    W.append(Wi)
    if 1<= i:
        if W[i-1][-1] == Wi[0]:
            pass
        else:
            flag = False
if len(set(W))==len(W):
    pass
else:
    flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input().strip())
W_list = [input().strip() for _ in range(N)]
#-----

for i in range(len(W_list)-1):
    if W_list[i+1] not in W_list[:(i+1)]  and  W_list[i][-1]==W_list[i+1][0]:
        continue
    else:
        print("No")
        break

else:
    print("Yes")

Submission status: Accepted

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

def puts(s): # 個人的にこのほうが解りやすいので。。。
    print(s)

ans = 'Yes'

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

W.sort()

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

puts(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def solve():
    input = sys.stdin.readline
    N = int(input())
    used = set()
    w = input().strip("\n")
    lastw = w[len(w) - 1]
    used |= {w}
    for _ in range(N - 1):
        w = input().strip("\n")
        if w[0] != lastw or w in used:
            print("No")
            break
        else:
            lastw = w[len(w) - 1]
            used |= {w}
    else: print("Yes")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

s = W[0][0]

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

s = set(W)
if len(s) != len(W):
    print("No")
    exit()
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())
a = [input() for _ in range(n)]
a0 = a[0]
for i in range(1,n):
    if a[i][0] == a0[-1]:
        flag = True
    else:
        flag = False
        break
    a0 = a[i]
if len(set(a)) == len(a) and flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

now_word = words[0]

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

Submission status: Accepted

Solution code:
N=int(input())
L=[]
count=0
for i in range(N):
	L.append(input())
M=len(set(L))
for i in range(N-1):
	if L[i][-1]==L[i+1][0]:
		count+=1
if M==N and count==N-1:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc109/tasks/abc109_b

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]: continue
    print('No')
    exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

from collections import defaultdict

used = defaultdict(bool)

prev = W[0][0]

flag = True
for w in W:
    if not used[w] and w[0] == prev:
        used[w] = True
        prev = w[-1]
    else:
        flag = False

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

Submission status: Accepted

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

if len(set(W)) != N:
    print("No")
    exit(0)

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

print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = []
for i in range(n):
    a.append(str(input()))

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

Submission status: Accepted

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

def isOk():
    if len(set(A)) < N:
        return False

    for a, b in zip(A, A[1:]):
        if a[-1] != b[0]:
            return False
    return True

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

Submission status: Accepted

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

s = set([W[0]])
p = W[0]
for w in W[1:]:
    if w in s or p[-1] != w[0]:
        print('No')
        exit()
    s.add(w)
    p = w
print('Yes')

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
pw = STR()
wlist = [pw]
for _ in range(n - 1):
    w = STR()
    if pw[-1] != w[0] or w in wlist:
        print('No')
        exit()
    wlist.append(w)
    pw = w
print('Yes')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [input() for i in range(N)]
    As = set(A)
    if len(A) != len(As):
        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())

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

print("Yes" if len(set(w)) == n and all([w[i][0] == w[i-1][-1] for i in range(1,n)]) else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    start_word = input()

    used_words = [start_word]
    result = 'Yes'
    for _ in range(n-1):
        word = input()
        if used_words[-1][-1] == word[0] and word not in used_words:
            used_words.append(word)
        else:
            result = 'No'
            break

    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(0, n-1):
    en = len(w[i]) - 1
    if w[i][en] != w[i+1][0]:
        result = 'No'

nw = set(w)

if len(nw) != n:
    result = 'No'
print(result)

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
sorted_W = sorted(W)
for i in range(len(sorted_W) - 1):
    if sorted_W[i] == sorted_W[i + 1]:
        print('No')
        exit()
for i in range(len(W) - 1):
    if W[i][-1] != W[i + 1][0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
ans = 1
A=[]
for i in range(N): 
    A.append(input())

for i in range(1, N):
    if A[i-1][-1] == A[i][0]:
        ans *= 1
    else:
        ans *= 0    
    
if all(A.count(i) == 1 for i in A):
    ans *= 1
else:
    ans *= 0  
    
print("Yes" if ans == 1 else "No")

Submission status: Accepted

Solution code:
import sys


def main():
    n = int(input())
    ws = [input() for _ in range(n)]

    for i in range(n-1):
        if ws.count(ws[i]) > 1:
            print('No')
            sys.exit(0)

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

    print('Yes')


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = [input()for _ in[0]*n]
f = 0
for i in range(1,n):
    f += s[i-1][-1] != s[i][0]
print("No"if f or len(set(s))<n else"Yes")

Submission status: Accepted

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

s=set(w)
if len(s)!=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:
N = int(input())
W = [input() for _ in range(N)]
if len(W) != len(set(W)):
  print("No")
  exit()
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 = [input() for _ in range(N)]
if len(W) != len(set(W)):
  print("No")
  exit()
else:
  for i in range(N-1):
    if W[i][-1:] != W[i+1][0:1]:
      print("No")
      exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
W = [str(input())for i in range(N)]
def has_duplicates(w):
  return len(w) != len(set(w))

if has_duplicates(W)==True:
  print('No')
  sys.exit()
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 = [tuple(input()) for _ in range(N)]

now = W[0][-1]
said = [W[0]]

for w in W[1:]:
    if not w in said and w[0] == now:
        now = w[-1]
        said.append(w)
        continue
    print("No")
    exit()

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(input())
tmp=[a[0]]
last = a[0][-1]
for word in a[1:]:
    if last != word[0] or word in tmp:
        print("No")
        exit()
    last = word[-1]
    tmp.append(word)
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
s = set()
word = input()
s.add(word)
tmp = word[-1]
is_ng = False
for i in range(N-1):
    word = input()
    if word[0] != tmp:
        is_ng = True
        break
    if word in s:
        is_ng = True
        break
    tmp = word[-1]
    s.add(word)
print('YNeos'[is_ng::2])

Submission status: Accepted

Solution code:
n = int(input())
s = [list(input())]
for _ in range(n - 1):
    w = list(input())
    t = s[len(s) - 1]
    if t[len(t) - 1] == w[0]:
        if not w in s:
            s.append(w)
if len(s) == n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
  W = input()
  if i == 0:
    words=[W]
  elif W in words or words[-1][-1]!=W[0]:
    print('No')
    exit()
  else:
    words.append(W)
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:
    ans = True
    for i in range(n - 1):
        if w[i][-1] != w[i + 1][0]:
            ans = False
            break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
w=[input() for i in range(N)]
s = w[0][-1]
if len(set(w)) < N:
    print('No')
    exit()
for i in w[1:]:
    if s!=i[0]:
        print('No')
        exit()
    s = i[-1]
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

w = []
for i in range(n):
    word = input()
    if i==0:
        before = word
    else:
        if before[-1] != word[0]:
            print('No')
            exit()
        else:
            before = word
    w.append(word)

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

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
w=input()
s={w}
for i in range(n-1):
  ww=input()
  if w[-1]!=ww[0] or ww in s:print("No");exit()
  w=ww
  s.add(w)
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
if len(set(s)) != n:
    print('No')
    exit()

cur = s[0][0]
for i in s:
    if cur != i[0]:
        print('No')
        exit()
    cur = i[-1]
print('Yes')

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    pre = input()
    said = set([pre])
    for _ in range(N - 1):
        W = input()
        if W in said or pre[-1] != W[0]:
            print('No')
            exit()
        pre = W
        said.add(W)
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
lst = [input() for _ in range(n)]
lstset = set(lst)

if len(lst) != len(lstset):
    print("No")
else:
    cnt = 0
    for i in range(n-1):
        if lst[i][-1] == lst[i + 1][0]:
            cnt += 1
        else:
            break
    if cnt + 1 == len(lst):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

for w in W[1:]:
    if w[0] == current[-1] and w not in used:
        current = w
        used.append(w)
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
#abc 109 b
n=int(input())
w=[]
for i in range(n):
    word=input()
    w.append(word)

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

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

Submission status: Accepted

Solution code:
n = int(input())
l = [input() for i in range(n)]
f = True
if len(set(l)) != len(l):
  f = False
else:
  for i in range(n-1):
    if l[i][-1] != l[i+1][0]:
      f = False
      break

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