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())
flag = "Yes "
words = []
for i in range(n):
    words.append(input())
beforeW = ""
counter = 0
for w in words:
    if beforeW == "":
        beforeW = w
        continue
    else:
        tailChar = beforeW[-1:]
        headChar = w[0]
        if tailChar == headChar:
            if words.count(w) == 1:
                beforeW = w
                continue
            else:
                flag = "No "
                break
        else:
            flag = "No "
            break
print(flag)

Submission status: Accepted

Solution code:
import sys

N = int(input()) #1行目のNを取得する
s = [input() for i in range(N)] #複数行の数値の入力を取得
#print(s) #出力：['s_1', 's_2', 's_3', 's_N']

jud = ''
strlist = []
for string in s:
    pre = string[0]
    suf = string[-1]
    if string in strlist:
        print('No')
        sys.exit()

    if jud == '':
        jud = suf
    else:
        if pre != jud:
            print('No')
            sys.exit()
        else:
            jud = suf
    strlist.append(string)
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
list = []
bool = True

for i in range(N):
    list.append(input())
if len(set(list)) != len(list):
    bool = False
else:
    for i in range(N - 1):
        if list[i][-1] != list[i+1][0]:
            bool = False

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
w_list = [""]*N
is_cor = True
for i in range(N):
  w_list[i] = input()
for i in range(N-1):
  b = w_list.copy()
  b[i] = ""
  if w_list[i][len(w_list[i])-1] != w_list[i+1][0] or w_list[i] in b:
    print("No")
    is_cor = False
    break
if is_cor:
  print("Yes")

Submission status: Accepted

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

check = 0
for i in range(N-1):
    if M[i][-1] != M[i+1][0]:
        check = 1

if len(M) != len(set(M)):
    check = 1
if check == 1:
    print("No")
else :
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i, k in enumerate(W):
    if i == 0:
        continue
    
    if W.count(k) != 1:
        print('No')
        exit()
    elif k[0] != W[i-1][-1]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
N-=1
w=input()
f=w[-1]
word={w}
for i in range(N):
    w=input()
    ini=w[0]
    if w in word:
        print("No")
        quit()
    if ini!=f:
        print("No")
        quit()
    word.add(w)
    f=w[-1]
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
W = []
K = []
ans = "Yes"
for i in range(n):
    W.append(input())



for i in range(n-1):
    if W[i] in K:
        ans = "No"
        break

    K.append(W[i])

    if W[i][-1] != W[i+1][0]:
        ans = "No"
        break

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
new_w = input()
w = [new_w]
w_str = list(new_w)
f = False
k = False
final_w = w_str[-1]
for i in range(n - 1):
    new_w = input()
    for j in w:
        if new_w == j:
            k = True
    w.append(new_w)
    if k:
        f = True
    w_str = list(new_w)
    if final_w != w_str[0]:
        f = True
    else:
        final_w = w_str[-1]
if f:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

w.append(input())

ans = 'Yes'
for i in range(1,n,1):
  w.append(input())
  l = len(w[i-1])
  if w[i][0:1] != w[i-1][l-1:l]:
    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())
lists = []
flag = 0
for i in range(N):
    W = str(input())
    lists.append(W)
    if i == 0:
        last = W[-1]
    else:
        if W[0] == last:
            last = W[-1]
        else:
            flag = 1
    
if flag == 1:
    print("No")
    exit()
for i in range(N):
    for j in range(N):
        if i != j:
            if lists[i] == lists[j]:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

def set_str(l):
    return len(l) == len(set(l))
if set_str(l):
    occurrence_No = True
    for i in range(len(l)):
        call_l = l[i]
        if i != 0 and l[i-1][-1] != call_l[0] :
            print("No")
            occurrence_No = False
            break
    if occurrence_No:
        print("Yes")
else:
    print("No")

Submission status: Accepted

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

for idx,val in enumerate(W):
    if idx == 0:
        continue
    if W[idx-1][-1] != val[0] or W.count(val) > 1:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input())
a = [input() for i in range(n)]
count = 0

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

import collections
b = collections.Counter(a)

if b.most_common(1)[0][1] >= 2:
    count += 1

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

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]"):
    used = set()
    used.add(W[0])
    ret = YES
    for i in range(1, N):
        if W[i][0] != W[i - 1][-1] or W[i] in used:
            ret = NO
            break
        used.add(W[i])
    print(ret)
    return


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:
#109 B

N=int(input())
start=[]
for i in range(N):
    start.append(input())
cnt=0
for i in range(N):
    if i!=0 and start[i][0]==start[i-1][-1]:
        cnt+=1
        
if len(start)==len(set(start)) and cnt==N-1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())

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

def alg1(W):
  list = [W[0],]
  point = W[0]
  for i in range(1,N):
    if W[i] not in list and W[i][0] == point[-1]:
      list.append(W[i])
      point = W[i]
    else:
      return 'No'
  return 'Yes'

print(alg1(W))

Submission status: Accepted

Solution code:
N = int(input())
Mylog = []
cnt = 0
x = list(input())
Mylog.append(x)
for i in range(1,N):
  x = list(input())
  Mylog.append(x)
  if (x in Mylog[:-1]) or (Mylog[i-1][-1] != Mylog[i][0]):
    cnt += 1

print("Yes" if cnt==0 else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N = int(input())
	W = []
	for _ in range(N):
		tmp = input()
		if tmp in W:
			print("No")
			sys.exit()
		W.append(tmp)
		
	for i, val in enumerate(W):
		if i > len(W)-2:
			print("Yes")
			sys.exit()
		
		if val[len(val)-1] != W[i+1][0]:
			print("No")
			sys.exit()
	
	print("No")
		
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

if ng > 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import copy
n = int(input())
w = [input() for i in range(n)]
flag = True
count = 0
for i in range(n):
    w_temp = copy.deepcopy(w)
    w_temp.pop(i)
    if w[i] in w_temp:
        print('No')
        exit()
for i in range(1, n):
    if w[i][0] != w[i-1][-1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
d = {}
alp = W[0][-1]
d[W[0]] = True
for i in range(1, N):
    if W[i] in d:
        print("No")
        exit()
    if alp != W[i][0]:
        print("No")
        exit()
    d[W[i]] = True
    alp = W[i][-1]
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
W=[input() for _ in range(N)]
his=set()
ok=True
lc=W[0][0]
for w in W:
	if w in his or lc != w[0]:
		ok=False
		break
	his.add(w)
	lc=w[len(w)-1]
print("Yes" if ok else "No")

Submission status: Accepted

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

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

if f and N==len(set(W)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

n = int(input())
a = [input() for i in range(n)]
count = 0

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

import collections
b = collections.Counter(a)

if b.most_common(1)[0][1] >= 2:
    count += 1

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	said = set()
	first = input()
	said.add(first)
	last = first[-1]
	is_shiritori = True
	for _ in range(n-1):
		word = input()
		if word in said or word[0] != last:
			is_shiritori = False
		said.add(word)
		last = word[-1]

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
judge = []
for i in range(N):
    W = input()
    if W in judge:
        print('No')
        sys.exit()
    else:
        if not judge:
            judge.append(W)
        else:
            if judge[-1][-1] != W[0]:
                print('No')
                sys.exit()
            else:
                judge.append(W)

print('Yes')

Submission status: Accepted

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

tmp = True

N = int(input())
w = [input() for i in range(N)]
if len(set(w)) != N:
    tmp = False
for i in range(N-1):
    if w[i][-1] != w[i+1][0]:
        tmp = False
print('Yes'if tmp else 'No')

Submission status: Accepted

Solution code:
_,*l=open(0);print('YNeos'[any(a[-2]!=b[0]*l.count(a)for a,b in zip(l,l[1:]))::2])

Submission status: Accepted

Solution code:
n = int(input())
done = set()
start = input()
done.add(start)
status = True
for i in range(n-1):
    x = input()
    if x in done:
        status = False
    if x[0] != start[-1]:
        status = False
    done.add(x)
    start = x
if status:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())

before = []
answer = 'Yes'

for i in range(N):
    s = input()
    if s in before:
        answer = 'No'
    if len(before) > 0:
        if before[-1][-1] != s[0]:
            answer = 'No'

    before.append(s)

print(answer)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = Counter(w_list).most_common(1)[0][1]
if cnt > 1:
    print('No')
else:
    for i in range(0,N - 1):
        if w_list[i][-1] != w_list[i + 1][0]:
            print('No')
            break
    else:
        print('Yes')

Submission status: Accepted

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

for i, w in enumerate(words):
    if i == 0:
        continue
    if words.count(w) > 1:
        print('No')
        break
    if w[0] != words[i - 1][-1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

flag = False
for i in range(N-1):
  if words[i][-1] != words[i+1][0]:
    flag = True
  else:
    continue

if len(words) != len(set(words)):
  print("No")
elif flag == True:
  print("No")
else:
  print("Yes")

Submission status: Accepted

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

print("Yes")

Submission status: Accepted

Solution code:
import sys
n = int(raw_input())
w0 = str(raw_input())
wlist = [w0]
for i in range(1,n):
	w = str(raw_input())
	wlist.append(w)
	if (wlist.count(w)>=2) | (w0[-1] != w[0]):
		print 'No'
		sys.exit()
	else:
		w0 = w
print 'Yes'

Submission status: Accepted

Solution code:
n = int(input())
last = ""
flg = 0
li = []
for i in range(n):
    s = input()
    str = list(s)  # 一文字ずつ格納
    if last == "":
        last = str[-1]
        li.append(s)
        continue

    if str[0] != last or s in li:
        flg = 1

    last = str[-1]
    li.append(s)


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

Submission status: Accepted

Solution code:
N = int(input())

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

yes = 0

for i in range(N-1):
  if (word.count(word[i]) > 1 or word.count(word[-1]) > 1):
    break
  if word[i][-1] == word[i+1][0]:
    yes += 1
    continue
  else:
    break

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

Submission status: Accepted

Solution code:
N = int(input())
Si = [input() for _ in range(N)]
old = Si[0][-1]

if len(Si) != len(set(Si)):
    print('No')
    quit()

for i in range(1, N):
    if Si[i][0] != old:
        print('No')
        quit()
    old = Si[i][-1]

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
W=[]
for _ in range(N):
    W.append(input())
c=1
for i in W:
    d=W.count(i)
    if d>1:
        c=0
        break
for i in range(N-1):
     if W[i][-1]!=W[i+1][0]:
            c=0
            break
if c:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
w_list = [input() for _ in range(n)]
if len(w_list) != len(set(w_list)):
    print('No')
else:
    f = True
    tail = w_list[0][0]
    for w in w_list:
        if w[0] != tail:
            f = False
        else:
            tail = w[-1]
            pass
    print('Yes' if f else 'No')

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
Flag = True
for i in range(1,N):
    if W[i-1][-1] != W[i][0]:
        Flag = False
    for j in range(i):
        if W[j] == W[i]:
            Flag = False
if Flag == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
W = [input() for _ in range(n)]
if (len(set(W)) != len(W)):
  print('No')
  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:
import sys
import collections

N = int(input())
List = [list(input())]
for i in range(1,N):
    tmp = list(input())
    if (tmp in List) == True:
        print('No')
        sys.exit()
    List.append(list(tmp))
    
    if tmp[0] != List[i-1][-1]:
        print('No')
        sys.exit()


print('Yes')

Submission status: Accepted

Solution code:
import sys

N=int(input())
s=set()

w=input()
s.add(w)
tmp=w[-1]

for i in range(N-1):
    w=input()

    if w in s or tmp!=w[0]:
        print("No")
        sys.exit()
    else:
        s.add(w)
        tmp=w[-1]

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
fouls = 0
for i in range(N):
    W = input()
    if i == 0:
        words = ['0' + W[:1]]
    if W in words:
        fouls += 1
    if W[:1] != words[i][-1:]:
        fouls += 1
    words.append(W)
if fouls >= 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

if len(W) != len(set(W)):
    print('No')
else:
    i = 0
    while i < N - 1:
        if W[i][-1] == W[i + 1][0]:
            i += 1
        else:
            print('No')
            break
    if i == N - 1:
        print('Yes')

Submission status: Accepted

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

# 重複
if len(set(w))!=n:
    print("No")
    exit()

# 前の末尾が次の先頭
for i in range(1,n):
    if w[i-1][-1]!=w[i][0]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

wo = [input()]
st = 0
for i in range(1,n):
	inl = input()
	if ((inl in wo) or (wo[-1][-1] != inl[0])):
		st = 1
		break
	else:
		wo.append(inl)
	



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

Submission status: Accepted

Solution code:
N=int(input())
W=list(input() for i in range(N))
p=W[0][0]
res=0
for w in W:
  if W.count(w)<2:
    if w[0]==p:
      res+=1
    else:
      break
  else:
    break
  p=w[-1]
if res==N:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

if len(set(Wn)) != N:
    print("No")
else:
    bw = Wn[0]
    for W in Wn[1:]:
        if W[0] != bw[-1]:
            print("No")
            break
        bw = W
    else:
        print("Yes")

Submission status: Accepted

Solution code:
def unique(S):
    new = []
    for i in S:
        if not i in new:
            new.append(i)
    return new

def solve(S):
    if not len(unique(S)) == len(S):
        return False
    for i in range(len(S)-1):
        if not S[i][-1] == S[i+1][0]:
            return False
    return True

N = int(input())
S = [input() for i in range(N)]
print("Yes" if solve(S) else "No")

Submission status: Accepted

Solution code:
N = int(input())

w = str(input())
w_end = w[-1]

tmp = []
tmp.append(w)

for i in range(N - 1):
    w = str(input())
    if w[0] == w_end and w not in tmp:
        pass
    else:
        print("No")
        exit()
    w_end = w[-1]
    tmp.append(w)

print("Yes")

Submission status: Accepted

Solution code:
def is_obeid(x):
    for i in range(len(x)):
        if x.count(x[i]) > 1:
            return False
        if i != 0:
            if x[i][0] != x[i - 1][-1:]:
                return False
    return True

def main():
    w = []
    N = int(input())
    for i in range(N):
        w.append(input())
    if is_obeid(w):
        print('Yes')
    else:
        print('No')

main()

Submission status: Accepted

Solution code:
N = int(input())
prev_word = input()
count = {prev_word:1}
for i in range(1,N):
    cur_word = input()
    if cur_word in count:
        print("No")
        exit()
    count[cur_word] = 1
    if cur_word[0] == prev_word[-1]:
        prev_word = cur_word
        continue
    print("No")
    exit()
print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
used = [input()]
flag = 1
for i in range(N-1):
  now = input()
  if now not in used and used[-1][-1] == now[0]:
    used.append(now)
  else:
      flag = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=set()
B=input()
S.add(B)
for i in range(N-1) :
  A=input()
  if A not in S and A[0]==B[-1]  :
    S.add(A)
    B=A
  else :
    print("No")
    break
else :
  print("Yes")

Submission status: Accepted

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


n = int(input())

l = []

w = [input() for i in range(n)]
if len(w) != len(set(w)):
    print('No')
    exit()
else:
    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:
# -*- coding: utf-8 -*-

n = int(input())
w = [0] * n
for i in range(n):
    w[i] = input()

rule = True
for i in range(1,n):
    if w[i][0] != w[i-1][-1]:
        rule = False
        break

w.sort()

for i in range(1,n):
    if w[i] == w[i-1]:
        rule = False
        break

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

Submission status: Accepted

Solution code:
N = int(input())

string_list=[input() for i in range(N)]
i = 0
string_list2 = list(set(string_list))
if(len(string_list2)==N):
    check = 1
else:
    check = 0

while(i < N-1):
    string1  = string_list[i]
    string2 = string_list[i+1]
    str1 = string1[-1]
    str2 = string2[0]
    if(str1 != str2):
        check = 0
    i +=1

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

Submission status: Accepted

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

ans = True
w = set([Ws[0]])
for i in range(1, N):
    if Ws[i - 1][-1] != Ws[i][0]:
        ans = False
        break
    if Ws[i] in w:
        ans = False
        break
    w.add(Ws[i])

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

Submission status: Accepted

Solution code:
#data input
n = int(input())
i = 0
str = [0] * n # str == 二次元配列
while i <  n: 
    str[i] = input()
    i += 1
    


i = 0
count = 0
x = ""
while i < n-1:
    if str[i][-1] == str[i+1][0]:
        i += 1
    else:
        print("No")
        count = 1
        break
i = 0
while i < n:
    x =  str.count(str[i])
    if x >= 2:
        print("No")
        count = 1
        break
    i += 1



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

Submission status: Accepted

Solution code:
import sys

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

y = set(w)

if n != len(y):
    print("No")
    sys.exit()

for i in range(n - 1):
    if not w[i].endswith(w[i + 1][0]):
        print("No")
        sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
last = W[0][0]
flag = True
for i in W:
    if(W.count(i)>1 or last!=i[0]):
        flag = False
        break
    else:
        last = i[-1]
if(flag):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n,*a=open(0).read().split()
if len(a)>len(set(a)):
    print("No")
    exit()
else:
    s=a[0][-1]
    for i in range(1,int(n)):
        if s==a[i][0]:
            s=a[i][-1]
        else:
            print("No")
            exit()
        #print(a[i][0])
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

memo = []
ans = "Yes"
for _ in range(N):
  W = input()
  if memo == []:
    memo.append(W)
  else:
    if W in memo:
      ans = "No"
      break
    if W[0] != memo[-1][-1]:
      ans = "No"
      break
    memo.append(W)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
w=input()
ww=[w]
ans="Yes"
for i in range(n-1):
  w1=input()
  if not w[len(w)-1]==w1[0]:
    ans="No"
    break
  if w1 in ww:
    ans="No"
    break
  w=w1
  ww+=[w]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
w = input()
w_list = set([w])
e = w[-1]
for i in range(1,N):
    w = input()
    if e != w[0]:
        print("No")
        break
    if w in w_list:
        print("No")
        break
    e = w[-1]
    w_list.add(w)
else:
    print("Yes")

Submission status: Accepted

Solution code:
n=int(input());w=[input()for i in range(n)]
def sortex(X):
  b=sorted(X)
  b.append("null")
  a=[]
  for i in range(len(X)):
    if b[i]!=b[i+1]:a.append(b[i])
  return a
if len(w)!=len(sortex(w)):
  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:
#coding: utf-8
N = int(input())
w = list(input())
wl = [w]
for i in range(N-1):
    nw = list(input()) 
    if w[-1] == nw[0] and nw not in wl:
        wl.append(nw)
        w = nw[:]
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ok_flag = 0
jufuku = 0
words = []
word_mae = input()
words.append(word_mae)
for i in range(N-1):
    word_ima = input()
    if(list(word_mae)[-1] == list(word_ima)[0]):
        ok_flag += 1
    if(word_ima in words):
        jufuku = 1
        break
    words.append(word_ima)
    word_mae = word_ima
if(jufuku == 1):
    print("No")
elif(ok_flag == N-1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())

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