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 i in range(n)]
d={}
for i in range(n):
  if w[i] not in d:
    d[w[i]]=1
  else:
    print('No')
    exit()
for i in range(n-1):
  if w[i][len(w[i])-1]!=w[i+1][0]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

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

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

print(judge)

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = "Yes"

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


    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

is_good = True

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

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

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

Submission status: Accepted

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

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import collections


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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8

# input高速化のpythonのおまじない
import sys
input = sys.stdin.readline

# Nの取得とint変換
N = int(input())

# Wiを取得
# Wを初期化
W = [None]*N
# N回入力を取得
for i in range(N):
    # 入力を配列に追加（rstripは改行文字の削除）
    W[i] = input().rstrip()
    
# 同じ単語を発言していないかのチェック
#  setを使用した後にリスト変換すると、
#  リスト中の重複要素がなくなるので、
#  重複要素が存在するとサイズが変わる
if not len(W) == len(list(set(W))):
    print('No')
else:
    # 重複してないので、しりとりが成立してるかチェックしていく
    shiritoreteru = True
    for i in range(N-1):
        # pythonは文字列をリストのように扱える
        # インデックス-1は後ろから見て１つ目の要素＝最後の文字
        if not W[i][-1] == W[i+1][0]:
            # 最後の文字と頭の文字が違うのでダメ
            shiritoreteru = False
            # ループを終える
            break
    
    # 結果判定
    if shiritoreteru:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    W = [input() for _ in range(n)]

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

Submission status: Accepted

Solution code:
from sys import exit

N = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = [input() for i in range(n)]
last = l[0][-1]
old = [l[0]]
check = True
for i in range(1, n):
    if l[i][0] != last or l[i] in old:
        check = False
    else:
        old.append(l[i])
        last = l[i][-1]
if check:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def q11(W):
    s = W.pop(0)
    deplicate = []
    deplicate.append(s)
    for w in W:
        if not w.startswith(s[-1]):
            return 'No'
    
        if w in deplicate:
            return 'No'
    
        deplicate.append(w)
        s = w
    return 'Yes'

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

print(q11(W))

Submission status: Accepted

Solution code:
def q11(W):
    s = W.pop(0)
    deplicate.append(s)
    for w in W:
        if not w.startswith(s[-1]):
            return 'No'
    
        if w in deplicate:
            return 'No'
    
        deplicate.append(w)
        s = w
    return 'Yes'

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

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

print(q11(W))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    W = [input() for j in range(N)]

    D = []
    ans = 'Yes'
    for i in range(N - 1):
        if W[i] in D:
            ans = 'No'
            break
        elif W[i][-1] != W[i + 1][0]:
            ans = 'No'
            break
        else:
            D.append(W[i])

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

    print(ans)


main()

Submission status: Accepted

Solution code:
n = int(input())

before = str(input())
use = [str(before)]
check = 0
for i in range(n-1):
    w = str(input()) 
    if w in use or before[-1] != w[0]:
        check = 1
        break
    use.append(w)

    before = w

if check == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
w=list(list(input()) for i in range(n))
f=True
c=0
for i in range(n):
    for j in range(n):
        if w[i]==w[j]:
            c+=1
    if (i!=n-1 and w[i+1][0]!=w[i][-1]) or c>n:
        f=False
if f:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
li=[str(input())]
for i in range(n-1):
    x=str(input())
    y=li[-1]
    if x in li or y[-1]!=x[0]:
        print("No")
        exit()
    else:
        li.append(x)
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
a=int(input())
c=0
z=[]
y=[]
b=[]
for i in range(a):
    x=str(input())
    z.append(x[0])
    y.append(x[-1])
    if i==0:
        b.append(x)
    if x not in b and z[i]==y[i-1]:
        b.append(x)
        c+=1
if c==a-1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main():
  import collections
  N, *W = open(0).read().split()
  N = int(N)

  if max(collections.Counter(W).values()) != 1:
    print("No")
    exit()
  else:
    for i in range(len(W)-1):
      if W[i][-1] != W[i+1][0]:
        print("No")
        exit()
    print("Yes")
  
if __name__ == "__main__":
    main()

Submission status: Accepted

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

X  =[list(W[i]) for i in range(N)]
Y  = set(W)

ans = 0

if len(W) != len(Y):
    print('No')
else:
    for i in range(1,N):
        if X[i-1][-1] == X[i][0] :
            ans += 1
            #print(ans)
    if ans == N-1:  
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N=int(input())
W=[0]*N
for i in range(N):
    W[i] = input()
cnt = 0
for i in range(N-1):
    moji=len(W[i])
    if W[i][moji-1] == W[i+1][0]:
        cnt +=1
    else:
        print('No')
        break
if cnt == N-1:
    if len(set(W)) == len(W):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
words = []
for i in range(N):
    w = input()
    if i == 0:
        words.append(w)
    else:
        if w[0] == l and w not in words:
            words.append(w)
        else:
            print("No")
            exit()
    l = w[-1]
print("Yes")

Submission status: Accepted

Solution code:
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

n = int(input())

l = []

l = [str(input()) for i in range(n)]

ans = 0

for i in range(n):
	if i == n-1:
		pass
	else:
		if l[i][len(l[i])-1] == l[i+1][0]:
			ans = ans + 1

print('Yes' if ans==n-1 and len(l)==len(set(l)) else 'No')

Submission status: Accepted

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

for i in range(n-1):
    if (ls_w[i][-1:] != ls_w[i+1][:1]) or (ls_w[i] in ls_w[i+1:]):
        print("No")
        break
    elif i == n - 2:
        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()
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())
wa=[] # 既に出たワード
wp="" # 前のワード
NGflag=False # だめフラグ

# 各ワードについて
for _ in range(N):
    w=input() # 現在のワード

    if wp!="": # 2回目以降の場合
        if wp[-1]!=w[0] or (w in wa): # しりを取っていないか、既に出たワードの場合
            NGflag=True
            break

    wa.append(w) # 既に出たワードのリストに追加
    wp=w # 次は今のワードを見る

if NGflag==False: # ルールを守れたなら
    print("Yes")
else: # 守れなかった。。。
    print("No")

Submission status: Accepted

Solution code:
N=int(input())
W=[input() for i in range(N)]
flag=True
def has_duplicates(seq):
    return len(seq) == len(set(seq))

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

Submission status: Accepted

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

cnt_A=0
cnt_B=0

for i in range(N-1):
    if not list_aaa[i][-1:] ==list_aaa[i+1][:1]:
        cnt_A +=1
    if list_aaa.count(list_aaa[i]) >=2 or list_aaa.count(list_aaa[i]) >=2 :
        cnt_B +=1


if cnt_A >=1 or cnt_B>=1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A=int(input())
B = [input() for _ in range(A)]
count = 0
if len(set(B)) != len(B):
  print('No')
else:
  for b in B:
    if count == 0:
      k = b[-1]
      count += 1
    else:
      if k == b[0]:
        k = b[-1]
      else:
        print('No')
        exit()
  print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
now = list(input())
already = [now]
Flag = False
for _ in range(N - 1):
    next_word = list(input())
    if next_word in already or now[-1] != next_word[0]:
        Flag = True
    already.append(next_word)
    now = next_word

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

Submission status: Accepted

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

ans = 'Yes'
tmp = ws.pop(0)
a = [tmp]

for w in ws:
    if w in a:
        ans = 'No'
        break
        
    if tmp[len(tmp)-1] != w[0]:
        ans = 'No'
        break
        
    a.append(w)
    tmp = w
        
print(ans)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
V = set()
prev = -1
for S in W:
    if S in V:
        print('No')
        exit()
    V.add(S)
    if prev == -1 or S[0] == prev:
        prev = S[-1]
    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-1][-1] != w[i][0]:
        print("No")
        exit()
if len(set(w)) == n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

end = None
for w in w_list:
  if end == None:
    end = w[-1]
    continue
  if w_list.count(w) > 1:
    print('No')
    break
  if w[0] != end:
    print('No')
    break
  end = w[-1]
else:
  print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
w = [input()]
flg = 0
pre = list(w[0])[-1]
for i in range(N-1):
    s = input()
    if s in w or pre != list(s)[0]:
        flg = 1
    pre = list(s)[-1]
    w.append(s)
if flg:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys

N = int(input())
word = list()
for i in range(N):
	word.append(input())

word_set = set(word)
if len(word) != len(word_set): # 同じ単語が使われた時
	print('No')
	sys.exit()

for i in range(N):
	alphabet = list(word[i])
	if i != 0 and last != alphabet[0]:
		print('No')
		sys.exit()	
	last = alphabet[-1]
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

words = set()

for n in range(N):
  w = input()
  if n > 0 and (w[0] != pre or w in words):
    print('No')
    exit()
  else:
    words.add(w)
    pre = w[-1]

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
check = {}
word = input()
check[word] = 1
last = word[-1]

for i in range(n-1):
    word = input()
    if word in check:
        print('No')
        exit()

    check[word] = 1
    if word[0] == last:
        last = word[-1]
    else:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

word_L = []
for val in range(n):
    new_word = input()
    word_L.append(new_word)

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

for val in range(1,n):

    if word_L[val-1][-1] != word_L[val][0]:
        print("No")
        exit()
    #print(word_L[val-1][-1],word_L[val][0])

print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
Ws=[]
W1=input()
Ws.append(W1)
kotae="Yes"
for i in range(1, N):
    W=input()
    if W not in Ws and W[0]==W1[-1]:
        Ws.append(W)
        W1=W
    else:
        kotae="No"
print(kotae)

Submission status: Accepted

Solution code:
N = int(input())
words = set()
for n in range(N):
  w = input()
  if n > 0 and (w[0] != prev or w in words):
    print('No')
    exit()
  else:
    words.add(w)
    prev = w[-1]

print('Yes')

Submission status: Accepted

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

def is_shiritori():
  if len(set(w)) != n:
    return 'No'
  for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
      return 'No'
  return 'Yes'

print(is_shiritori())

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, W: "List[str]"):
    ans = YES
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            ans = NO
            break
    for i in range(N):
        if W[i] in W[:i]:
            ans = NO
            break
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, W)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
n = int(input())


wl = []
end = ""
for _ in range(n):
    w = input()
    wl.append(w)
    if end == "" or w[0] == end:
        end = w[-1]
    else:
        print("No")
        sys.exit()
    
if len(wl) != len(set(wl)):
    print("No")
    sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
l = [W[0]]
for i in range(N - 1):
  if W[i][-1] == W[i + 1][0] and not W[i + 1] in l:
    l.append(W[i + 1])
  else:
    break
print("Yes" if len(l) == N else "No")

Submission status: Accepted

Solution code:
def main(n: int, w: list) -> None:
    if len(set(w)) != n:
        print("No")
        return

    last_letter = ""

    for w_n in w:
        if last_letter == "":
            last_letter = w_n[-1]
            continue

        if last_letter != w_n[0]:
            print("No")
            return

        last_letter = w_n[-1]

    print("Yes")


if __name__ == "__main__":
    n = int(input())
    w = [input() for _ in range(n)]

    main(n, w)

Submission status: Accepted

Solution code:
n = int(input())
w1 = input()
used = [w1]

for _ in range(n-1):
    w2 = input()
    if w2 in used:
        print("No")
        quit()
    if w1[-1] != w2[0]:
        print("No")
        quit()
    used.append(w2)
    w1 = w2
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
A=[]
hantei = True
for i in range(N):
  A+=[str(input())]
L=[A[0]]
for i in range(1,N):
  if A[i] in L:
    hantei = False
    break
  if A[i-1][-1]!=A[i][0]:
    hantei= False
    break
  L +=[A[i]]
print('Yes' if hantei else'No')

Submission status: Accepted

Solution code:
n = int(input())
s = ['']*n
ans='Yes'

for i in range(n):
    instr = str(input())
    if i!=0:
        if s[i-1][len(s[i-1])-1]!=instr[0]:
            ans = 'No'
        if instr in s:
            ans = 'No'
    s[i]=instr
print(ans)

Submission status: Accepted

Solution code:
# ABC 109: B – Shiritori
n = int(input())
w = [input() for _ in range(n)]

is_satisfied = 'Yes'

if len(w) != len(set(w)):
    is_satisfied = 'No'
else:
    for i in range(1, len(w)):
        if w[i][0] != w[i - 1][-1]:
            is_satisfied = 'No'
            break

print(is_satisfied)

Submission status: Accepted

Solution code:
N = int(input())
used = set()
for i in range(N):
    s = input()
    if (i!=0 and s[0]!=p[-1]) or s in used:
        print("No")
        exit()
    used.add(s)
    p = s
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
words = []
s = input()
words.append(s)
ans = True
for i in range(N-1):
    t = input()
    if(t[0] == s[-1] and (t in words) == False):
        words.append(t)
        s = t
    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)]
last=""
wl=[]
ans="Yes"
for x,i in enumerate(w):
    if x==0:
        last=i[-1]
        wl.append(i)
        continue
    if i in wl:
        ans="No"
    if i[0]!=last:
        ans="No"
    last=i[-1]
    wl.append(i)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
W = []
dic = dict()
yes = 1

for _ in range(N):
	char = str(input())
	W.append(char)
	if not char in dic:
		dic[char] = 1
	else:
		yes = 0

tale = W[0][0]
		
for i in range(N):
	if tale != W[i][0]:
		yes = 0
		break
	else:
		tale = W[i][-1]
		
if yes:
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

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

for i in range(N):
  if W.count(W[i]) != 1:
    f = 0
    break
    
if f == 1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-10 12:28:14(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, *w = sys.stdin.read().split()
    n = int(n)
    for i in range(1, n):
        if w[i][0] == w[i-1][-1] and not w[i] in w[:i]:
            continue
        else:
            print('No')
            exit()
    
    print('Yes')


if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

Solution code:
N = int(input())

words = [input() for _ in range(N)]
prev = words[0]
se = set([words[0]])

bl = True
for w in words[1:]:
    if w in se:
        bl = False
    if prev[-1] != w[0]:
        bl = False
    se.add(w)
    prev = w

answer = 'Yes' if bl else 'No'
print(answer)

Submission status: Accepted

Solution code:
n = int(input())

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

spoken = {words[0]}

for x, y in zip(words, words[1:]):
    if y[0] != x[-1]:
        print("No")
        exit()
    if y in spoken:
        print("No")
        exit()
    spoken.add(y)
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

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

t = len(list(set(word)))

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

Submission status: Accepted

Solution code:
from sys import stdin
import fractions

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

li = [stdin.readline().rstrip() for _ in range(n)]
k = len(li)
lin = list(set(li))

if len(lin) != k:
    print("No")
    exit()

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

Submission status: Accepted

Solution code:
n=int(input())
w=[]
ans='Yes'
for i in range(n):
    w.append(list(input()))
    if i==0:
        continue
    if w[i][0]!=w[i-1][len(w[i-1])-1]:
            ans='No'
            break
    for j in range(i):
        if w[i]==w[j]:
            ans='No'
            break
print(ans)

Submission status: Accepted

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

count = 0

for n in range(1,N):
    if W[n-1][-1] != W[n][0] or W[n] in W[:n]:
        break
    else:
        count += 1

if count == N-1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
words = []
ans = True
for i in range(N):

    word = input()
    if i >= 1:
        if words[-1][-1] != word[0]:
            ans = False
        if word in words:
            ans = False
    words.append(word)
print("Yes" if ans else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = []
w.append(input())
for i in range(1, n):
	W = input()
	if W in w or W[0] != w[i-1][len(w[i-1])-1]:
		print("No")
		exit(0)
	w.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')
    exit(0)

prev = W[0]
for w in W[1:]:
    if prev[-1] != w[0]:
        print('No')
        exit(0)
    prev = w
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
list = []
list.append(input())
c = 0

for i in range(n - 1):
    old = list[-1]
    new = input()
    if old[-1] != new[0]:
        c += 1
    for j in list:
        if j == new:
            c += 1
    list.append(new)

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
string_list=[input() for i in range(n)]
for i in range(n):
	for k in range(n):
		if i!=k:
			if string_list[i]==string_list[k]:
				print('No')
				sys.exit()

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

print('Yes')