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

judge0 = 1
judge1 = 1

if len(set(W)) < len(W):
    judge0 = 0
    
W = list(map(list, W))
    
for n in range(N-1):
    if W[n][-1] != W[n+1][0]:
        judge1 = 0
        break

if judge0 == 1 and judge1 == 1:
    print('Yes')
else:
    print('No')

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

s = set()
last = ""
ans = "Yes"

for i in range(N):

    w = input()

    if i == 0:
        last = w
        s.add(w)

    elif (w[0] == last[-1]) and (w not in s):

        last = w
        s.add(w)

    else:
        ans = "No"
        break

print (ans)

Submission status: Accepted

Solution code:
N = int(input())

W = [None] * N

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

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

last = W[0][-1]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
word = [input() for i in range(n)]
used = set()
end = word[0][0]


for w in word:
    if w in used or end != w[0]:
        print("No")
        exit()
    else:
        used.add(w)
        end = w[-1]
print("Yes")

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
W = [sys.stdin.readline().rstrip() for _ in range(N)]
i = 0
ok = True
while i < N - 1:
    j = i + 1
    ok &= W[i][-1] == W[j][0]
    i+=1
if ok and len(set(W)) == N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

tmp = []
tmp.append(W[0])
for i in range(N-1):
    if W[i][-1] == W[i+1][0] and W[i+1] not in tmp:
        tmp.append(W[i+1])
        if i == N-2:
            print('Yes')
    else:
        print('No')
        break

Submission status: Accepted

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

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
words = []
N = int(input())
flag = True

words.append(input())

for _ in range(N-1):
    w = input()
    if w not in words and words[-1][-1] == w[0]:
        words.append(w)
    else:
        flag = False
        break

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

Submission status: Accepted

Solution code:
n = int(input())
w = []
f = True
for i in range(n):
    wcur = input()
    if wcur in w:
        f = False
    if i >= 1 and w[i-1][-1] != wcur[0]:
        f = False
    w.append(wcur)
if f:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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



def solve(n,ls):
    if n == 0:
        return "Yes"
    else:
        if ls[n-1][-1] == ls[n][0]:
            return solve(n-1,ls)
        else:
            return "No"


flg = solve(n-1,w)
if flg == "No":
    pass
else:
    if not len(w) == len(list(set(w))):
        flg ="No"

print(flg)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

l = []
for i in range(N):
    l.append(input())

#重複チェック
if len(set(l)) != N:
    print("No")
    exit()

#しりとりチェック
for i in range(N-1):
    if l[i][-1] != l[i+1][0]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:

s = int(input())
last = str(input())
wordlist = [last]
ans = "Yes"

for i in range(s-1):
    word = str(input())

    if last[-1] != word[0]:
        ans = "No"
        break
    
    elif word in wordlist:
        ans = "No"
        break

    last = word
    wordlist.append(word)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ans="Yes"
w=[input() for _ in range(n)]
for  i in range(n):
    a=w[max(0,i-1)]
    b=w[max(1,i)]
    if a[len(a)-1]!=b[0]:
        ans="No"
if len(set(w))!=len(w):
    ans="No"
print(ans)

Submission status: Accepted

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

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

else:
    for i in range(1, n):
        if list_w[i - 1][-1] == list_w[i][0]:
            list_ok.append(list_w[i])
            i += 1
    if len(list_ok) == len(list_w):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

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

print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
d={}
flag=True
before=None
for z in range(N):
  s=input()
  if before==None:
    before=s[-1]
  else:
    if before==s[0]:
      before=s[-1]
    else:
      flag=False
  if not(s in d):
    d[s]=True
  else:
    flag=False

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
# PROXY

N = int(input())
list = [input() for i in range(N)]
def has_duplicates(seq):
    return len(seq) != len(set(seq))    
if has_duplicates(list):
    print("No")
else:
    i = 1
    while i < N:
        if list[i-1][-1] != list[i][0]:
            print("No")
            break
        else:
            i += 1
    else:
        print("Yes")

Submission status: Accepted

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

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

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

        for j in range(i-1):
            if w[i] == w[j]:
                print('No')
                exit()

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# 入力
n=int(input())

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

# 重複がある場合はアウト
if len(set(l))!=n:
  print('No')
  exit()

for i in range(n-1):
  # しりとりのルールを満たしていない場合はアウト
  if l[i][-1]!=l[i+1][0]:
    print('No')
    exit()

# 全てのチェックを通過できればセーフ
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

for i  in w:
    if w.count(i) > 1:
        answer = 'No'
        break

if answer == 'No':
    print(answer)
else:
    for i in range(N-1):
        if w[i][-1] != w[i+1][0]:
            answer = 'No'
            break
    print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

number = int(input())
word = [input() for i in range(number)]

for i in range(number-1):
    if word[i][-1] == word[i+1][0]:
        continue
    else:
        print("No")
        exit()

word = collections.Counter(word)

if word.most_common()[0][1] != 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
f=0
l=[]
a=list(input())
l.append(a)
for i in range(n-1):
    b=list(input())
    if b in l:
        f+=1
    l.append(b)
    if a[len(a)-1]!=b[0]:
        f+=1
    a=b
    
if f>0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
def f(W):
    if len(W) != len(set(W)):
        return False
    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            return False
    return True


N = int(input())
W = [input() for _ in range(N)]
print('Yes' if f(W) else 'No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = []
i = 1
while i <= n:
  if i == 1:
    s = input()
    l.append(s)
    i += 1
  else:
    s = input()
    if s in l or s[0] != l[-1][-1]:
      print('No')
      quit()
    else:
      l.append(s)
      i += 1
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
words = [input() for _ in range(n)]
print("Yes" if all([y[0] == x[-1] for x, y in zip(words, words[1:])]) and len(set(words)) == n else "No")

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:
n = int(input())
dic = [input() for _ in range(n)]
ans = "Yes"
for i in range(1,n):
    if dic[i] in dic[:i] or dic[i][0] != dic[i-1][-1]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = []
S.append(input())
ans = 'Yes'

for i in range(N - 1):
	s = input()
	S.append(s)

	# 重複した単語の場合はNG
	if S.count(s) != 1:
		ans = 'No'
		break

	# しりとりになっていない場合はNG
	if S[i][-1] != S[i + 1][0]:
		ans = 'No'
		break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = []
S.append(input())
ans = 'Yes'

for i in range(N - 1):
	s = input()
	S.append(s)

	# 重複した単語の場合はNG
	if S.count(s) != 1:
		ans = 'No'
		break

	# しりとりになっていない場合はNG
	S1 = S[i]
	S2 = S[i + 1]
	if S1[-1] != S2[0]:
		ans = 'No'
		break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
W = [[] for _ in range(N)]
seen = []
for i in range(N):
    W[i] = input()
judge = 0
for tango in W:
    if tango not in seen:
        seen.append(tango)
    else:
        judge = 1
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        judge = 1
if judge == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:

N = int(input())

lst_W = []
for i in range(N):
    lst_W.extend(input().split())

ans = "Yes"

for i in range(N - 1):
    if (lst_W[i])[-1:] != (lst_W[i+1])[:1]:
        ans = "No"
        break

if len(lst_W) != len(set(lst_W)):
    ans = "No"

print(ans)

Submission status: Accepted

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

used = set()
flag = True
old_w = words[0]
used.add(old_w)
for word in words[1:] :
	if word in used :
		flag = False
		break
	else :
		used.add(word)
	#print(used)
	if old_w[-1] != word[0] :
		flag = False
		break
	old_w = word
print("Yes" if flag else "No")

Submission status: Accepted

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

dic = True

for i in range(N-1):
    ss = input()
    if ss in S:
        dic = False
        break
    elif S[i][-1] != ss[0]:
        dic = False
        break
    else:
        S.append(ss)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if ans == 'Yes':
    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())
words =[]
words.append(input().rstrip())
 
for _ in range(1, n):
  s = input().rstrip()
  if s[0] != words[-1][-1] or s in words:
    print('No')
    break
  words.append(s)
else:
  print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
s = [str(input()) for i in range(n)]
t = [s[0]]
alpha = s[0][-1]
a = True
for i in range(n-1):
    if s[i+1] not in t and alpha == s[i+1][0]:
        t.append(s[i+1])
        alpha = s[i+1][-1]
    else:
        a = False
        break
 
if a:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
s = [str(input()) for i in range(n)]
t = [s[0]]
alpha = s[0][-1]
a = True
for i in range(n-1):
    if s[i+1] not in t and alpha == s[i+1][0]:
        t.append(s[i+1])
        alpha = s[i+1][-1]
    else:
        a = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

def solve(words):
  s = {words[0]}
  for p, w in zip(words, words[1:]):
    if p[-1] != w[0]:
      return "No"
    if w in s:
      return "No"
    s.add(w)
  return "Yes"

print(solve(words))

Submission status: Accepted

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

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

if len(list(set(word_list))) == n and ng == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

if len(s)!=n:
  print("No")
else:
  for j in range(n-1):
    if w[j][-1]!=w[j+1][0]:
      print("No")
      break
  else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

li = []
flag = True

for i in range(n):
  word = input()
  li.append(word)
  if i != 0:
    if li[i-1][-1] != li[i][0]:
      flag = False

for i in li:
  if li.count(i) >= 2:
    flag = False

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

Submission status: Accepted

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

answered = set([words[0]])
ans = "Yes"

for i in range(1, n):
    if words[i] in answered:
        ans = "No"
        break

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

    answered.update([words[i]])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
first = input()
told = set((first,)) 
win = True
for _ in range(N-1):
    second = input()
    if (not second in told) and (first[-1] == second[0]):
        told.add(second)
        first = second
    else:
        win = False
print('Yes' if win else 'No')

Submission status: Accepted

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

l = []
for i in range(N):
  if i == 0:
    l.append(w[i])
  elif not w[i] in l and w[i-1][-1] == w[i][0:1]:
    l.append(w[i])
  else:
    print("No")
    exit()

print("Yes")

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    w = [ input() for i in range(n)]

    ok = True
    if len(set(w))!= n:
        ok = False
    for i in range(1,n):
        if w[i][0]!= w[i-1][-1]:
            ok =False
    
    if ok:
        print('Yes')
    else:
        print('No')

    

solve()

Submission status: Accepted

Solution code:
N = int(input())

list = []

for _ in range(N):
  list.append(input())

if len(set(list)) != len(list):
  print('No')
  exit()
  
w_old = list[0]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(raw_input())
word = [raw_input()]
for i in range(1, N):
	newword = raw_input()
	if newword in word or newword[0] != word[-1][-1]:
		print 'No'
		break
	if i == N-1: print 'Yes'
	else: word.append(newword)

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")
    exit()
else:
  if len(W) != len(list(set(W))):
    print("No")
    exit()
  else:
    print("Yes")

Submission status: Accepted

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

N = int(input())
L = [input().strip() for _ in range(N)]

target = list(L[0])
s = set()
s.add(L[0])

for i in range(1, N):
    v = L[i]
    if v not in s:
        s.add(v)
        
        vv = list(v)
        if target[-1] != vv[0]:
            print("No")
            exit()
        else:
            target = vv
    else:
        print("No")
        exit()
        
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
W=[]
for i in range(N):
    w=input()
    W.append(w)
last=W[0][-1]
S=set()
S.add(W[0])
for i in range(1,N):
    if W[i][0]==last and not W[i] in S:
        pass
    else:
        print("No")
        exit()
    S.add(W[i])
    last=W[i][-1]
print("Yes")

Submission status: Accepted

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

S=set()
for i in range(N):
    w=input()
    W.append(w)

last=W[0][-1]
S.add(W[0])

for i in range(1,N):
    if W[i][0]==last and not W[i] in S:
        pass
    else:
        print("No")
        exit()
    S.add(W[i])
    last=W[i][-1] #ケツ追加した
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
W = []
for k in range(N):
    w = stdin.readline().rstrip()
    if k >= 1:
        if w[0] != W[k - 1][len(W[k - 1]) - 1] or len([x for x in W if x == w]) > 0:
            print('No')
            break
    W.append(w)
if len(W) == N:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a = []
re = "Yes"
for i in range(n):
        a.append(input())
        if a.count(a[i]) >= 2:
                re = "No"
        if i != 0:
                if a[i][0] != a[i-1][-1]:
                        re ="No"

print(re)

Submission status: Accepted

Solution code:
N = int(input())
W = []
for i in range (0,N):
    W.append(input())
ans = "Yes"
d = dict()
count = 0
for j in W:
    if j in d.keys():
        ans = "No"
    else:
        d[j] = 1
    if count != 0:
        if j[0] != W[count - 1][-1]:
            ans = "No"
    count += 1
print(ans)

Submission status: Accepted

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

D = set()
ls = W[0][-1]
D.add(W[0])
for i in range(1, n):
    if ls == W[i][0] and not W[i] in D:
        D.add(W[i])
        ls = W[i][-1]
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
said = [input()]
prev = said[0][-1]
for _ in range(N - 1):
  s = input()
  if s in said or prev != s[0]:
    print('No')
    break
  prev = s[-1]
  said.append(s)
else:
  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]"):
    if len(W) != len(set(W)):
        print(NO)
        return

    for i in range(1,N):
        if W[i-1][-1] != W[i][0]:
            print(NO)
            return

    print(YES)

    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 i in range(N)]
s_W = list(set(W))

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

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

Submission status: Accepted

Solution code:
n = int(input())
f = True
history = []
lw = None
for i in range(n):
    w = input()
    if w in history:
        f = False
        break
    if lw is not None:
        if w[0] != lw:
            f = False
            break
    history.append(w)
    lw = w[-1]
if f:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
a = input()

def main():
    ed = []
    for i in range(int(a)):
        neww = input()
        if i != 0:
            if ed[i-1][-1] != neww[0] or neww in ed:
                return 'No'
        ed.append(neww)

    return 'Yes'
                

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

Submission status: Accepted

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


ans = 'Yes'
head = words[0][0]
memory = []
for w in words:
    if w[0] != head: 
        ans = 'No'
        break
    if w in memory:
        ans = 'No'
        break
    head = w[-1]
    memory.append(w)

print(ans)

Submission status: Accepted

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

l = [W[0]]

for i in range(1, N):
    if W[i - 1][-1] == W[i][0] and W[i] not in l:
        l.append(W[i])
    else:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
a = list([str(input())])

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

Submission status: Accepted

Solution code:
n = int(input())
s = ""
listW = []
flag = True
for i in range(n):
    if i == 0:
        w = input()
        listW.append(w)
        s = w[-1]
        continue
    else:
        w = input()
        if w in listW:
            print("No")
            flag = False
            break
        listW.append(w)
        if w[0] == s:
            s = w[-1]
            continue
        else:
            print("No")
            flag = False
            break
if flag:
    print("Yes")

Submission status: Accepted

Solution code:
W = [w.strip() for w in open(0).readlines()[1:]]

judge = [(W.count(w) == 1) and (w[-1] == W[i+1][0]) for i, w in enumerate(W[:-1])]

print('No' if (False in judge) else 'Yes')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

word = input()
prev_char = word[-1]
word_set = set()
word_set.add(word)
flag = True
for i in range(N-1):
    word = input()
    if word in word_set or word[0] != prev_char:
        flag = False
        
    word_set.add(word)
    prev_char = word[-1]
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Shiritori
https://atcoder.jp/contests/abc109/tasks/abc109_b

"""
import sys


def solve(words):
    seen = set()
    prev = words[0][0]
    for w in words:
        if w in seen or w[0] != prev[-1]:
            return 'No'
        prev = w
        seen.add(w)
    return 'Yes'


def main(args):
    N = int(input())
    words = [input() for _ in range(N)]
    ans = solve(words)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
import sys
n=int(input())
ws = set()
for _ in range(n):
    w = input()
    if w in ws:
        print('No')
        sys.exit()
    if ws and b != w[0]:
        print('No')
        sys.exit()
    ws.add(w)
    b = w[-1]
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
s_list=[]
shiritori_list=[]
for i in range(n):
  s=input()
  s_list.append(s)
  schar = list(s)
  schar_list=[]
  schar_list.append(schar[0])
  schar_list.append(schar[len(schar)-1])
  shiritori_list.append(schar_list)

unique_list=set(s_list)

if len(s_list) != len(unique_list):
  print('No')
else:
  judge='Yes'
  for j in range(n-1):
    if shiritori_list[j][1] != shiritori_list[j+1][0]:
      judge='No'
      break
  print(judge)

Submission status: Accepted

Solution code:
N = int(input())
A = []
cnt = []

for i in range(N):
    a = input()
    A.append(a)
for i in range(N):
    cnt.append(A.count(A[i]))
for i in range(N-1):
    if A[i][-1] == A[i+1][0]:
        cnt.append(1)
if cnt.count(1) == (N  + (N-1)):
    print('Yes')
else:
    print('No')