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

Submission status: Accepted

Solution code:
ss = []
for i in range(int(input())):
  s = input()
  if len(ss) == 0:
    ss.append(s)
  elif not s in ss and s[0] == ss[-1][-1]:
    ss.append(s)
  else:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict
dd = defaultdict(bool)
n = int(input())
w = [input() for _ in range(n)]
pre = w[0][0]
for s in w:
    if dd[s] or (pre[len(pre) - 1] != s[0]):
        print("No")
        exit()
    dd[s] = True
    pre = s
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
w=[]
ws=[]
count=1
for i in range(n):
    w.append(input())
    ws.append(list(w[i]))
for i in range(n):
    if (w.count(w[i]))>1:
        count-=1
for j in range(n-1):
    if (ws[j][len(w[j])-1])==(ws[j+1][0]):
        count+=1
if count==int(n):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import collections
N= int(input())
n=[]
for i in range(N):
	n.append(input())
c = collections.Counter(n)
if len(c) !=len(n):
	print("No")
	exit()
for i in range(N-1):
	if n[i+1][0] != n[i][len(n[i]) -1]:
		print("No")
		exit()

print("Yes")

Submission status: Accepted

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

if len(set(w)) != n:
  c = 101
else:
  for i in range(n-1):
    if w[i][-1] == w[i+1][0]:
      c += 1

print("Yes" if c == n-1 else "No")

Submission status: Accepted

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

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

print("Yes" if c == n-1 else "No")

Submission status: Accepted

Solution code:
n=int(input())
cur=input()
past=[cur]
ans=True
for i in range(n-1):
  s=input()
  if cur[-1:]==s[0] and s not in past:
    past.append(s)
    cur=s
  else:
    ans=False
    break

print(("No","Yes")[ans])

Submission status: Accepted

Solution code:
#B - Shiritori(ABC109)
N=int(input())
s=True
w1=input()
W=[w1]
for i in range(N-1):
    w2=input()
    W.append(w2)
    if len(set(W))==len(W) and w1[-1]==w2[0]:
        w1=w2
    else:
        s= False
if s:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#B - Shiritori(ABC109)
N=int(input())
W=[]
s=True
for i in range(N):
    W.append(input())
if len(set(W))==N:
    for i in range(N-1):
        if W[i][-1]!=W[i+1][0]:
            print("No")
            s=False
            break   
else:
    print("No")
    s=False
if s:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w0 = input()
word_set = set([w0])
ans = True

for i in range(1, n):
    w = input()
    if ans and w not in word_set and w[0] == w0[-1]:
        word_set.add(w)
        w0 = w
    else:
        ans = False

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

Submission status: Accepted

Solution code:
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:
def takahashi():
    N = int(input())
    L = [input() for _ in range(N)]
    if len(L) != len(set(L)):
        print("No")
        return
    for i in range(N - 1):
        if L[i][-1] != L[i + 1][0]:
            print("No")
            return
    print("Yes")


takahashi()

Submission status: Accepted

Solution code:
N = int(input())
se = set()
ans = 'Yes'
s = input()
se.add(s)
c = s[-1]
for i in range(N-1):
    s = input()
    if s in se or s[0] != c:
        ans = 'No'
        break
    c = s[-1]
    se.add(s)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = []
for i in range(n):
    s = input()
    if i==0:
        text = s
        lst.append(s)
        continue
    else:
        if s in lst or text[-1] != s[0]:
            print('No')
            exit()
        else:
            text = s
            lst.append(s)
print('Yes')

Submission status: Accepted

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

flg = False
if len(L) != len(set(L)): flg = True
for i in range(1, N):
  if flg: break
  if i != 0:
    if L[i][0] != L[i-1][-1]:
      flg = True
print ("No" if flg else "Yes")

Submission status: Accepted

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

prev = w[0][0]
for x in w:
  if not(w.count(x) == 1 and x[0] == prev):
    print('No')
    exit(0)
  prev = x[-1]

print('Yes')

Submission status: Accepted

Solution code:
n,*w=open(0);n=int(n);print("No"if len(set(w))<n else" YNeos"[all(w[i][-2]==w[i+1][0]for i in range(n-1))::2])

Submission status: Accepted

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

for i in range(n-1):
    if li[i][-1] == li[i+1][0]:
        flag = True
    elif li[i][-1] != li[i+1][0]:
        flag = False
        break
if flag == True and len(li) == len(set(li)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
words = [input() for x in range(n)]

A = 'Yes'

last_word = words[0][-1:]

# there is duplicated word
if len(words) != len(list(set(words))):
    A = 'No'

for i in range(1, n):
    if last_word == words[i][:1]:
        last_word = words[i][-1:]
        continue

    else:
        A = 'No'
        break

print(A)

Submission status: Accepted

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

ans = True
for i in range(N):
    for j in range(N):
        if i != j and W[i] == W[j]:
            ans = False

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

if ans == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

used=[w[0]]
last_chr=w[0][-1]

for word in w[1:]:
    if (word[0]==last_chr) and (word not in used):
        used.append(word)
        last_chr=word[-1]
    else:
        print("No")
        exit()
print('Yes')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    used = set()
    prev = input()
    used.add(prev)
    for i in range(1, N):
        w = input()
        if w in used or w[0] != prev[-1]:
            return "No"
        used.add(w)
        prev = w
    return "Yes"

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

Submission status: Accepted

Solution code:
N = int(input())

W, OK = ["-"], True
for i in range(N):
    W.append(input())
    if W[-1] in W[:-1] or (W[-2][-1] != W[-1][0] and W[-2] != "-"):
        OK = False

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

Submission status: Accepted

Solution code:
n=int(input())

word=[input() for _ in range(n)]
if len(word)!=len(set(word)):
    print("No")
else:
    isOK=True
    for i,j in zip(word[:-1], word[1:]):
        if i[-1]!=j[0]:
            isOK=False
    print("Yes") if isOK else print("No")

Submission status: Accepted

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

    W = [""] * N

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

    set_W = set(W)

    if len(set_W) != N:
        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')


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

last = input()
s = set()
s.add(last)

for i in range(1, n):
    word = input()
    if last[len(last) - 1] != word[0] or word in s:
        print("No")
        exit(0)
    else:
        last = word
        s.add(word)
print("Yes")

Submission status: Accepted

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

for i in range(1,n):
	if wl[i-1][-1] == wl[i][0]:
		if wl[i] in saidl:
			print("No")
			quit()
		else:
			saidl.append(wl[i])
	else:
		print("No")
		quit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
ald = set()
start = input()
ald.add(start)
flag = True
for i in range(1,n):
    nword = input()
    if nword not in ald and start[-1] == nword[0]:
        ald.add(nword)
        start = nword
    else:
        flag = False

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

Submission status: Accepted

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

Submission status: Accepted

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

Ws = set([W[0]])
for i in range(1, N):
    if not W[i - 1][-1] == W[i][0] or W[i] in Ws:
        print("No")
        exit()
    else:
        Ws.add(W[i])

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    L = []
    e = ""
    for i in range(N):
        S = sys.stdin.readline().rstrip()
        if S in L:
            print("No")
            exit()
        L.append(S)
        if i > 0:
            if e != S[0]:
                print("No")
                exit()
        e = S[::-1][0]

    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
w = []
ans = "Yes"
for i in range(N):
  s = str(input())
  if(i>0):
    if(s[0]==w[-1][-1]):
      None
    else:
      ans = "No"
      break
  w.append(s)
j = set(w)
l = len(list(j))
if(N==l):
  None
else:
  ans="No"
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

flag = True

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

if len(set(words)) != n:
    flag = False

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

Submission status: Accepted

Solution code:
n = int(input())
w = []

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

ans = True

for i in range(1, n):
    if w.count(w[i]) > 1 or w[i-1][-1] != w[i][0]:
        ans = False
        break

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

Submission status: Accepted

Solution code:
# -*-coding: utf-8 -*-
N = int(input())
W = [0] * N
for i in range(N):
    W[i] = input()

flag = True
if N != len(set(W)):
    flag = False
if flag:
    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())
hist = [input()]
res = 'No'
s = hist[0][-1]
for _ in range(N-1):
  w = input()
  if w in hist or w[0] != s:
    break
  s = w[-1]
  hist.append(w)
else:
  res = 'Yes'
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=input()
a=[]
Z=[]
for i in range(int(N)):
    A=input()
    Z.append(A)
    a.append(A[0])
    a.append(A[-1])

del a[-1],a[0]

if len(Z) != len(set(Z)):
    print("No")
elif a[0::2] != a[1::2]:
    print("No")
elif a[0::2] == a[1::2]:
    print("Yes")

Submission status: Accepted

Solution code:
import collections
n = int(input())
w = list(str(input()) for _ in range(n))
w2 = list(collections.Counter(w).values())
if max(w2) != 1:
    print('No')
else:
    for i in range(n-1):
        if w[i][-1] != w[i+1][0]:
            print('No')
            break
    else:
        print('Yes')

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    w = list(input() for _ in range(n))
    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"


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,*S = open(0).read().split()

F = True if len(S) == len(set(S)) else False
for i in range(int(N)-1):
  if S[i][-1] != S[i+1][0]:
    F = False
print("Yes" if F else "No")

Submission status: Accepted

Solution code:
n = int(input())
nlist = [input() for i in range(n)]
if len(nlist) != len(set(nlist)):
    print('No')
    exit()
for i, j in enumerate(nlist):
    if i + 1 < len(nlist):
        if nlist[i][-1] != nlist[i + 1][0]:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:

from collections import defaultdict

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

dd = defaultdict(int)
before = ''
for c in W:
    if dd[c] == 0 and (before == '' or before[-1] == c[0]):
        dd[c] += 1
        before = c
    else:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
n,*words=list(open(0).read().split())

ans='Yes'
if len(set(words)) != int(n):
  ans='No'
else:
  for a,b in zip(words, words[1:]):
    if not a[-1] == b[0]:
      ans='No'
      break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import copy
import sys

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputb = input().split()
# inputbList = [int(n) for n in inputb]
#
inputList = []
inputNumList = []
for i in range(a):
    inputNum = input().split()
    inputNumList = list(inputNum[0])
    inputList.append(inputNumList)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

flg = True
for i in range(a):
    if i == 0:
        continue
    else:
        if inputList[i][0] != inputList[i-1][-1]:
            flg = False
            break

        for j in range(i):
            if "".join(inputList[i]) == "".join(inputList[j]):
                flg = False
                break

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys

def input():
    return sys.stdin.readline().rstrip()

N = int(input())
a = []
tmp, head, tail = "", "", ""

for i in range(N):
    tmp = input()
    if tmp in a:
        print("No")
        exit()
    else:
        a.append(tmp)
        if i != 0:
            tail = (a[i-1])[-1]
            head = (a[i])[0]
            if tail != head:
                print("No")
                exit()
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
for i in w:
    if w.count(i) > 1:
        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_lis = []
ans = "Yes"
for i in range(n):
    w = input()
    if i == 0:
        w_lis.append(w)
    elif w in w_lis:
        ans = "No"
        break
    elif w not in w_lis and w[0] != w_lis[i-1][-1]:
        ans = "No"
        break
    else:
        w_lis.append(w)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
w = list(input())
fin = w[-1]
lst = [w]
for i in range(N-1):
    w = list(input())
    head = w[0]
    if  w[0] != fin or w in lst:
      print("No")
      exit()
    else:
      fin = w[-1]
      lst.append(w)
print("Yes")

Submission status: Accepted

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

hantei = 0

for i in range(N):
    for j in range(i+1,N):
        if W[i] == W[j]:
            hantei = 1
            break

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = []
for i in range(n):
    w.append(input())
if len(list(set(w))) != 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())
w = [input() for i in range(n)]
for i in w:
  if w.count(i) > 1:
    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())

used_word = []
ans = "Yes"


for i in range(N):
  word = input()
  
  if i == 0:
    used_word.append(word)
  elif i >= 1:  
    if word in used_word:
      ans = "No"
    elif word[0] != used_word[-1][-1]:
      ans = "No"
    else:
      used_word.append(word)
      continue

print(ans)

Submission status: Accepted

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

n = int(input())
a = []
for i in range(n):
    s = input().strip()
    if len(a) > 0:
        if s in a:
            print("No")
            exit()
        elif a[-1][-1] == s[0]:
            a.append(s)
        else:
            print("No")
            exit()
    else:
        a.append(s)
        
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
s=input()
a=[]
last=s[-1]
a.append(s)

for i in range(n-1):
  s=input()
  a.append(s)
  if s[0]!=last:
    print('No')
    break
  last=s[-1]
  if i==n-2 and len(a)==len(set(a)):
    print('Yes')
  elif i==n-2:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
w = []
for i in range(n):
    w.append(input())
for i in range(n):
    for j in range(i+1,n):
        if w[i] == w[j]:
            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 sys


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

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

prev = W[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:
#!/usr/bin/env python3
import sys

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

def solve(N: int, W: "List[str]"):
    already_spoken = []
    flag = True
    for i, w in enumerate(W):
        if w in already_spoken:
            flag = False
        if i > 0:
            if not W[i-1][-1] == W[i][0]:
                flag = False
        already_spoken.append(w)
    if flag == True:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 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:
n = int(input())
w = [input() for _ in range(n)]

ans = 'Yes'
if n!=len(set(w)):
  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())
w = [input() for i in range(n)]
se = set()
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        break
    else:
        se.add(w[i])
        se.add(w[i+1])
print('Yes') if len(se) == n else print('No')

Submission status: Accepted

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

def end():
    print("No")
    exit()

if len(w)!=len(set(w)):
    end()

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

print("Yes")

Submission status: Accepted

Solution code:

import sys
n = int(input())
w = input()
www = [w]
for i in range(n-1):
  w = input()
  if not www[-1][-1] == w[0]:
    print("No")
    sys.exit()
  if w in www:
    print("No")
    sys.exit()
  www.append(w)
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

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

print('Yes')

Submission status: Accepted

Solution code:
import collections

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


def same_word_check(s):
    c = collections.Counter(s)
    l = sorted(list(c.values()), reverse=True)
    if l[0] >= 2:
        print('No')
        exit()


def shiritori_rule(s):
    for i in range(len(s)-1):
        if s[i][-1] != s[i+1][0]:
            print('No')
            exit()

same_word_check(s)
shiritori_rule(s)
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
sl = [input() for _ in [0]*n]
ans = 'Yes'
for i in range(1,n):
  if sl[i-1][-1] != sl[i][0] or sl.count(sl[i]) != 1 :
    ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    W = list(input() for _ in range(n))
    f = False
    if n==len(set(W)):
        if all(W[i][0] == W[i-1][-1] for i in range(1,len(W))):
            f = True
    print('Yes') if f else print('No')
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
yje = [input()]
for i in range(1,n):
    now = input()
    if now in yje:
        print('No')
        break
    if yje[-1][-1] != now[0]:
        print('No')
        break
    yje.append(now)
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for _ in range(n)]
ng = []
last = ""
for i in range(n):
    if i != 0:
        if w[i] not in ng:
            word = w[i]
            if word[0] == last:
                last = word[len(word)-1]
                ng.append(word)
            else:
                print("No")
                exit()
        else:
            print("No")
            exit()
    else:
        word = w[i]
        last = word[len(word) - 1]
        ng.append(word)
print("Yes")

Submission status: Accepted

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

ans="Yes"
for i in range(N):
  word=input()
  if word in word_list:
    ans="No"
    break
  else:
    word_list.append(word)
    if i>=1:
      if word_list[i-1][len(word_list[i-1])-1]!=word[0]:
        ans="No"
        break
      else:
        continue

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
W = list(input() for i in range(N))
f = True

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter

def main():
	n = int(input().strip())
	v = [0] * n
	for i in range(n):
		v[i] = input().strip()
	if len(set(v)) != n:
		print('No')
		return
	for i in range(n-1):
		if v[i][-1] != v[i+1][0]:
			print('No')
			return
	print('Yes')

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n = int(input())
yje = [input()]
for i in range(1,n):
  now = input()
  if now in yje:
    print('No')
    break
  if yje[-1][-1] != now[0]:
    print('No')
    break
  yje.append(now)
else:
  print('Yes')

Submission status: Accepted

Solution code:
stocker = []

N = int(input())
pastwd = input()
stocker.append(pastwd)

for i in range(1,N):
  curwd = input()
  if (pastwd[-1] != curwd[0]) or curwd in stocker:
    print("No")
    exit()
  stocker.append(curwd)
  pastwd = curwd

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
encodes = [input() for _ in range(n)]
ans = 'Yes'
if len(set(encodes)) < n:
    ans = 'No'
    print(ans)
    exit()
for i in range(n-1):
    if encodes[i][-1] != encodes[i+1][0]:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

pw =[]
no  = False
for i in range(n):
    if i == 0:
        wi = input()
        pw.append(wi)
    else:
        w = input()
        if wi[-1]!=w[0] or (w in pw):
            no = True
        pw.append(w)
        wi = w

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

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    W = inputs
    appeared = set()
    prev = ''
    for w in W:
        if w in appeared:
            return "No"
        appeared.add(w)
        if not (prev == '' or w[0] == prev):
            return "No"
        prev = w[-1]
    return "Yes"


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

Submission status: Accepted

Solution code:
def check(w1,w2):
  return w1[-1] == w2[0]

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

if len(set(w)) < n:
  print('No')
  exit()
for i in range(n-1):
  if not check(w[i],w[i+1]):
    print('No')
    exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
word = []
for i in range(n):
  word.append(input())
  
  
s_word = set(word)
ans = 'No' 
siri = word[0][-1]
s_size = len(s_word)
w_size = len(word)
del word[0]

if s_size == w_size:
  for i in word:
    if siri == i[0]:
      ans = 'Yes'
      siri = i[-1]
    else:
      ans = 'No'
      break
      
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

s = list(set(li))

if n != len(s):
    print("No")
    exit()
    
for i in range(n):
    t = li[i][-1]
    try:
        u = li[i+1][0]
        if t != u:
            print("No")
            break
    except:
        pass
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
for j in range(len(w)):
    if w.count(w[j]) > 1:
        print("No")
        exit()
for k in range(len(w)-1):
    if w[k][-1] != w[k+1][0]:
        print("No")
        exit()
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):

    for j in W[:i]:
        if j == W[i]:
            print('No')
            exit()


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

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

lst2 = []
lst2.append(lst[0])
ans = "Yes"
for i in range(1, N):
	if (lst[i] in lst2 or lst[i-1][-1] != lst[i][0]):
		ans = "No"
		break
	else:
		lst2.append(lst[i])

print(ans)