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())
words = []
for a in range(0, N):
    words.append(input())

isok = True

for a in range(0, N-1):
    w1 = words[a]
    w2 = words[a+1]

    if w1[-1] != w2[0]:
        isok = False
        break

if isok and len(list(set(words))) == N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
s_1 = input()
word_list = [s_1]
target = s_1[-1]
frag = "Yes"
for i in range(n-1):
  s = input()
  if s in word_list :
    frag = "No"
  if target == s[0]:
    target = s[-1]
  else:
    frag = "No"
 
  word_list.append(s)
    
print(frag)

Submission status: Accepted

Solution code:
N=int(input())
S=['0']*N
for i in range(0,N):
    S[i]=input()
for i in range(1,N):
    if S.count(S[i])>1:
        print('No')
        exit()
    elif S[i-1][-1]!=S[i][0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

W = []

ans = 0
W.append(input())

for i in range(N-1):
  Wi = input()
  WL = W[i]
  if Wi in W:
    ans = 1
    break
  if Wi[0] != WL[len(WL)-1]:
    ans = 1
    break

  W.append(Wi)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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


def solve(N: int, W: "List[str]"):
    already = []
    for n in range(N-1):
        if W[n] in already:
            print(NO)
            exit()
        already.append(W[n])
        if W[n][-1] != W[n+1][0]:
            print(NO)
            exit()
    if W[-1] in already:
        print(NO)
        exit()
    print(YES)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
count = 0
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        count += 1

count += len(W)- len(set(W))

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

Submission status: Accepted

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


def has_duplicates(x):
    return len(x) == len(set(x))


if (has_duplicates(W)):
    s = ''
    for i, v in enumerate(W):
        if (i == 0):
            s = v[-1]
            continue
        elif(i > 0 and i < len(W) - 1):
            if (s == v[0]):
                s = v[-1]
            else:
                print('No')
                exit()
        else:
            if (s == v[0]):
                print('Yes')
            else:
                print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
# 2020/04/27
# AtCoder Beginner Contest 109 - B

# Input
n = int(input())
d = dict()

# Check
ans = 'Yes'
wkc = 9
for i in range(n):
    w = input()
    if d.get(w) == None:
        d[w] = 1
    else:
        ans = 'No'
        break

    if i > 0 and wkc != w[0]:
        ans = 'No'
        break
    
    wkc = w[len(w)-1]

# Output
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
if all(W[i][0]==W[i-1][-1] and W[i] not in W[:i] for i in range(1, N)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

a = []
pre = W[0]
a.append(pre)
flag = False
for wi in W[1:]:
    if wi in a or pre[-1] != wi[0]:
        flag = True
        break
    pre = wi
    a.append(wi)
        
if flag:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
now=input()
s=set()
s.add(now)
for i in range(n-1):
    now2=input()
    if now[-1]!=now2[0]:
        print("No")
        break
    now=now2
    s.add(now)
else:
    if len(s)==n:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

if len(set(W)) != len(W):
	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())
word_list = [input() for i in range(N)]
ans = "Yes"
def f(s1,s2):
  if s1[len(s1)-1] == s2[0] :
    return True

for i in range(0,N-1):
  if f(word_list[i],word_list[i+1]):
    pass
  else:
    ans = "No"

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = []
while True:
  try:
    w.append(input())
  except:
    break

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

Submission status: Accepted

Solution code:
N = int(input())

shiritori_set = set()

shiritori = input()
head = shiritori[len(shiritori) -1]

ans = "Yes"
shiritori_set.add(shiritori)
for i in range(N-1):
  shiritori = input()
  if shiritori[0] == head and shiritori not in shiritori_set:
    head = shiritori[len(shiritori)-1]
    shiritori_set.add(shiritori)
  else:
    ans = "No"
    break

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
MOD = 10**9+7

def main():
    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)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    w = input().rstrip()
    a = [w]
    for i in range(1, n):
        w = input().rstrip()
        if w in a:
            print('No')
            break
        if a[-1][-1] != w[0]:
            print('No')
            break
        a.append(w)
    else:
        print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding:utf-8
n = int(input())
w = [input() for _ in range(n)]
word_list = set(w)

if len(word_list) != len(w):
    print("No")
    exit()
else:
    for i in range(1, n):
        tail = w[i - 1][-1]
        if tail != w[i][0]:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
w_set = set(w)
key = 0
if len(w) != len(w_set):
    print("No")
    quit()
else:
    for i in range(1,n):
        key = w[i][0]
        if w[i-1][-1] != key:
            print("No")
            quit()

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
s = set([])
w = input()
s.add(w)
for i in range(n-1):
  w2 = input()
  s.add(w2)
  if w2[0] != w[-1]:
    print("No")
    quit()
  w = w2
if len(s) == n:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = set()
ans = "Yes"

for i in range(n):
    str = input()

    if(len(S) != 0):
        if(str[0] != c or str in S):
            ans = "No"
    
    S.add(str)
    c = str[-1]

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    words = [input()]
    ans = True
    for _ in range(N - 1):
        s = input()
        if words[-1][-1] != s[0] or s in words:
            ans = False
        else:
            words.append(s)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

w_s = w.copy()
w_s = set(w_s)
w_s = list(w_s)

if len(w) != len(w_s):
    print("No")
    exit()

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

Submission status: Accepted

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

ans = 'Yes'
for i in range(1,n):
    if input_lines[i] not in input_lines[0:i] and input_lines[i][0]==input_lines[i-1][-1]:
        continue
    else:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

words = set()
w = ''
ok = True
for i in range(n):
  nw = input()
  if nw in words:
    ok = False
    break
  words.add(w)
  if w and w[-1] != nw[0]:
    ok = False
  w = nw

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

Submission status: Accepted

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

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

for i in range(n - 1):
    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:
a=int(input())

import sys
b = [input() for i in range(a)]
c=set(b)
if len(b)!=len(c):
    print('No')
    sys.exit()
for i in range(a-1):
    if b[i][-1]==b[i+1][0]:
        pass
    else:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrW = [input() for _ in range(N)]
# arrA = np.array(input().split(),dtype=np.int64)

lis = []
ans = "Yes"
for i,w in enumerate(arrW):
    # print(lis , w)
    if i == 0:
        lis.append(w)
    else:
        if arrW[i-1][-1] != arrW[i][0]:
            ans = "No"
            break
        if arrW[i] in lis:
            ans = "No"
            break
        lis.append(w)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

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()
else:
    for i, name in enumerate(w):

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

        except IndexError:
            print('Yes')

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(n - 1):
    if w[i][-1] != w[i + 1][0]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
def h(seq):
    return len(seq)!=len(set(seq))
a=int(input())
t=['0']*a
hantei=0
for i in range(a):
    t[i]=input()
for i in range(a-1):
    if t[i][-1]!=t[i+1][0]:
        hantei=1
if h(t):
    hantei=1
if hantei==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import math
n = int(input())
li = [n]
li[0] = input()
isGood=True
for i in range(n-1):
    tmp = input()
    if (not isGood):
        continue
    if (tmp not in li):
        if (li[i][-1] != tmp[0]):
            isGood = False
        else:
            li.append(tmp)
    else:
        isGood = False

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

Submission status: Accepted

Solution code:
n=int(input())
wordset=set()
pw=input()
wordset.add(pw)
ans='Yes'
for _ in range(n-1):
  w=input()
  if pw[-1] != w[0] or w in wordset:
    ans='No'
    break
  wordset.add(w)
  pw=w
print(ans)

Submission status: Accepted

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

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

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

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    n = int(readline())
    w1 = readline().rstrip()
    l = w1[-1]
    words = set()
    words.add(w1)
    for _ in range(n-1):
        w = readline().rstrip()
        if w[0] == l and w not in words:
            l = w[-1]
            words.add(w)
        else:
            print('No')
            return
    
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


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

    N = ii()
    W = [iss() for _ in range(N)]
    s = W[0]
    r1 = True
    for i in range(1, N):
        if s[-1:] != W[i][0:1]:
            r1 = False
        s = W[i]

    print('Yes' if r1 and all([W.count(w) == 1 for w in W]) else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = []
b = ''
flag = 0

for i in range(N):
    t, b = b, input()

    if i != 0:
        if t[-1] != b[0]:
            flag = 1
            break

    if b not in a:
        a.append(b)
    else:
        flag = 1
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
W=str(input())
w_list = [W]
OUT = False
for i in range(N-1):
  W=str(input())
  w_list.append(W)
  if W[0] != w_list[i][len(w_list[i])-1]:
    OUT = True
  n = len([1 for w in w_list if w==W])
  if n > 1:
    n = 0
    OUT = True
if OUT:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
word_list=[]
last_word='aaaa'
for i in range(n):
    w=input()
    if 0<i and (w in word_list or last_word[len(last_word)-1]!=w[0:1]):
        print('No')
        exit()
    word_list.append(w)
    last_word=w
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
List = [input() for i in range(n)]
x = 0
ans = "Yes"

for i in range(1,n):
    if List[i-1][-1:] != List[i][:1]:
        ans = "No"
        #print(List[i-1][-1:])
        #rint(List[i][:1])
        break
if len(List) != len(set(List)):
    ans = "No"
print(ans)
#print(List[i-1][-1:])
#print(List[i][:1])
#print(len(set(List)))

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
ans = 'Yes'
for i in range(1, N):
    if S[i-1][-1:] != S[i][:1]:
        ans = 'No'
        break
if len(S) != len(set(S)):
    ans = 'No'
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
W=[input() for _ in range(N)]
flg=1
flg_1=1
for i in W:
    if W.index(i)!=0:
        if i[0]!=W[W.index(i)-1][-1]:
            flg=0
            break
if len(set(W))!=len(W):
    flg_1=0
    
print("Yes" if flg and flg_1 else "No")

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    n=int(input())
    ww=set()
    w=[]
    for i in range(n):
        w.append(input())
    ww=set()
    ww.add(w[0])
    yn=""
    for i in range(n-1):
        if w[i][-1]!=w[i+1][0]:
            yn="No"
            print("No")
            break
        if w[i+1] in ww:
            yn="No"
            print("No")
            break
        else:
            ww.add(w[i+1])
    if yn!="No":
        print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
f = True
w = []
w.append(input())
last = w[0][-1]

for i in range(1,n):
    w.append(input())
    
    if w[i][0] == last and not(w[i] in w[:i]):
        last = w[i][-1]
    else:
        f = False

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

Submission status: Accepted

Solution code:
# abc109_b.py
N = int(input())
W = [input() for i in range(N)]
pre =""
for word in W:
    if W.count(word)>1 or (pre[-1:]!=word[0] and pre!=""):
        print('No')
        exit()
    pre = word
print('Yes')

Submission status: Accepted

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

if len(w) != len(set(w)):
    print('No')
    quit()
check = [w[0]]
siri = w[0][-1]
for i in range(1,n):
    if w[i][0] == siri:
        check.append(w[i])
        siri = w[i][-1]
    else:
        print('No')
        quit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a = [input()]
for _ in [0]*(n-1):
    b = input()
    if a[-1][-1] != b[0] or b in a:
        print('No')
        break
    a += [b]
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

isShiritori = 'Yes'

for i in range(len(w) - 1):
    if w.count(w[i]) > 1 or w[i][-1] != w[i + 1][0]:
        isShiritori = 'No'
        break

print(isShiritori)

Submission status: Accepted

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

flag = True
mem = [x[0]]
for i in range(1, n):
  if x[i-1][-1] != x[i][0] or x[i] in mem:
    flag = False
    break
    
  mem.append(x[i])
      
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    words = list()
    rule = True
    for _ in range(N):
        word = input()
        if len(words) > 0:
            if words[-1][-1] != word[0]:
                rule = False
        if word not in words:
            words.append(word)
        else:
            rule = False
    if rule == True:
        print("Yes")
    else:
        print("No")
main()

Submission status: Accepted

Solution code:
# solution
import io

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

report = 'Yes'
if n!=len(set(m)):
  report ='No'
else:
  for i in range(n-1):
    if m[i][-1]!=m[i+1][0]:      
      report='No'
      break
print(report)

Submission status: Accepted

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

S = set([W[0]])

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = set()
prev = None
flag = 1
for _ in range(N):
    W = input()
    if W in S or (prev is not None and prev[-1] != W[0]):
        flag = 0
    prev = W
    S.add(W)
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

ok = 1
tmp_list = []
for i in range(n):
    w = str(input())

    if i == 0:
        tmp = w
        tmp_list.append(w)
        continue

    else:
        if w[0] != tmp[-1] or w in tmp_list:
            ok = 0

        else:
            tmp_list.append(w)
            tmp = w

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

Submission status: Accepted

Solution code:
N = int(input())
S = set()
prev = None
flag = 1
for _ in range(N):
    W = input()
    if W in S or (prev is not None and prev[-1] != W[0]):
        flag = 0
    prev = W
    S.add(W)
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def myAnswer(N:int,W:list) -> str:
   lis =[W[0]]
   pre = W.pop(0)[-1]
   for word in W:
      if(pre == word[0] and (word in lis)==False):
         lis.append(word)
         pre = word[-1]
      else:
         return "No"
   return "Yes"

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   W=[]
   for _ in range(N):
      W.append(input())
   print(myAnswer(N,W[:]))

if __name__ == '__main__':
   main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
flag = True
if len(set(W)) != N:
    flag = False
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        flag = False
print('Yes' if flag else '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] or W.count(W[i]) >= 2:
    print("No")
    exit()

print("Yes")

Submission status: Accepted

Solution code:
N,*W=open(0)

ans='Yes'
i=0
while i+1<int(N):
    if W[i][-2]!=W[i+1][0]:
        ans='No'
    i+=1
print([ans,'No'][int(N)>len(set(W))])

Submission status: Accepted

Solution code:


def solve():

    N = int(input())

    wlist = [input() for i in range(N)]
    s = set(wlist)

    if len(wlist) != len(s):
        print("No")
        exit()
    else:
        last = wlist[0][-1]
        for i in range(1, N):
            ini = wlist[i][0]
            if last != ini:
                print("No")
                exit()
            last = wlist[i][-1]

    print("Yes")


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

for i in range(n-1):
    if w.count(w[i]) == 1 and w[i][-1] == w[i+1][0]: #条件を満たしている
        continue
    else: #条件を満たしていない
        x = 1
        print("No")
        break

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

Submission status: Accepted

Solution code:
N = int(input())

W = input()
words = {W}

ans = True
for _ in range(N - 1):
    num = len(words)
    w = input()
    words.add(w)
    if (W[-1] != w[0] or num == len(words)):
        ans = False
        break
    W = w

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

Submission status: Accepted

Solution code:
n ,*L = map(str,open(0).read().split())
li = [L[0]]
for i in range(1,int(n)):
    if (L[i] in li) or L[i-1][-1] != L[i][0]:
        print("No")
        exit()
    li.append(L[i])
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
if len(set(w)) == n:
    for i in range(1, n):
        s0 = list(w[i - 1])
        s1 = list(w[i])
        if s1[0] == s0[-1]:
            pass
        else:
            print("No")
            exit()
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
ans = 'Yes'
words = [input() for _ in range(n)]
said = set()
tail = words[0][0]
for w in words:
    if w in said or w[0] != tail:
        ans = 'No'
        break
    said.add(w)
    tail = w[-1]

print(ans)

Submission status: Accepted

Solution code:
n =int(input())
w =[]
for i in range(n):
    w.append(input())
import sys
for i in range(n):
    for j in range(n):
        if i != j:
            if w[i] ==w[j]:
                print("No")
                sys.exit()

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 = int(input())
w = list()
for i in range(n):
    x = input()
    w.append(x)

ans = 'Yes'
used_w = []
for i, word in enumerate(w):
    if i == 0:
        used_w.append(word)
        prev = word[-1]
        continue
    if word[0] == prev and word not in used_w:
        prev = word[-1]
        used_w.append(word)
    else:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

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

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

print('Yes')