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())
f=True
l=[str(input())]
for i in range(1,n):
  a=str(input())
  if a in l or l[i-1][-1]!=a[0]:
    f=False
    break
  else:
    l+=[a]
print("Yes" if f==True else "No")

Submission status: Accepted

Solution code:
n = int(input())
w = list(input() for _ in range(n))
flg = False

for i in range(n-1):
    if(w[i][len(w[i])-1] == w[i+1][0]):
        cnt = 0
        for j in range(n):   
            if(w[j] == w[i]):
                cnt += 1
        if(cnt >= 2):
            flg = False
            break
        else:
            flg = True
    else:
        flg = False
        break
        
print("Yes" if flg else "No")

Submission status: Accepted

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

last = ""
a = set() 
check = True
for i in range(n):
  s = ss[i]
  if i == 0:
    last = s[len(s) - 1]
    a.add(s)
    continue

  if s in a:
    check = False
    break
  if last != s[0]:
    check = False
    break

  last = s[len(s) - 1]
  a.add(s)

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

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())
W=[input() for _ in range(n)]
end=W[0][-1]
Flag=1
exp=[W[0]]
for w in W[1:]:
    start=w[0]
    if end!=start or w in exp:
        Flag=0
        break
    end=w[-1]
    exp.append(w)
print('Yes' if Flag==1 else 'No')

Submission status: Accepted

Solution code:
n = int(input())

st= set()
back=""
flg=True
for i in range(n):
    s=input()

    if i>0 and back!=s[0]:
        flg=False
    
    back=s[-1]
    st.add(s)

if flg and len(st)==n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

frst = words[0]
wrds = set(words)
if len(wrds) != len(words):
	print("No")
else:	
	for i in range(1,len(words)):
		flag = 1
		if words[i-1][-1] != words[i][0]:
			print("No")
			flag = 0
			break
	if flag == 1:
		print("Yes")

Submission status: Accepted

Solution code:
# 簡単なアルゴリズムなのだが、下の # で躓きその違いは？

n = int(input())
l = [input() for _ in [0]*n]
if len(set(l)) != n:
    print('No')
else:
    for i in range(n-1):
        if l[i][-1] != l[i+1][0]: # if list(l[i])[-1] != list(l[i+1][0]): との違いが？
            print('No')
            break
        else:
            continue
    else:
        print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = [input() for _ in [0]*n]
#print(l)
if len(set(l)) != n:
    print('No')
else:
    for i in range(n-1):
        #print(i)
        #print(list(l[i])[-1])
        #print(list(l[i+1])[0])
        if l[i][-1] != l[i+1][0]:
            print('No')
            break
        #else:
            #print('Noo')
            #break
        else:
            continue
    else:
        print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
ng = 0
S = set()
pre_we = ""
for i in range(N):
    W=input()
    if W in S:
        ng = 1
    S.add(W)
    if (i != 0) and (pre_we != W[0]):
        ng = 1
    pre_we = W[-1]
if ng == 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
words = [input() for _ in range(n)]
use = [words[0]]
for i in range(1, n):
    if words[i] in use:
        print('No')
        exit()

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

    use.append(words[i])

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n=int(input())
word=[]
for i in range(n):
	w=input()
	if w in word:
		print("No")
		sys.exit()
	if i>=1 and w[0]!=word[-1][-1]:
		print("No")
		sys.exit()
	word.append(w)
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
W=[input() for i in range(N)]
s1=""
s2=""
success=1
if not(len(set(W))==len(W)):
    print("No")
else:
    for i in range(N-1):
        s1=W[i]
        s2=W[i+1]
        if not(s1[len(s1)-1]==s2[0]):
            success=0
            break
    if success==1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
w = list(input() for i in range(n))
s = True

for i in range(len(w)-1):
  if w[i][-1]!=w[i+1][0]:
    s = False
    break

ws = set(w)
if s and len(ws)==len(w):
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

for i in range(1,n):
    pre , now = w[i-1],w[i]
    if pre[-1] !=now[0] or now in w[:i]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

back = w[0][-1]

for i in range(n):
    for j in range(i+1,n):
        if w[i] == w[j]:
            print("No")
            exit()

for i in range(1, n):
    pre = w[i][0]
    if pre != back:
        break
    back = w[i][-1]
    if i == n-1:
        print("Yes")
        exit()

print("No")

Submission status: Accepted

Solution code:
N = int(input())

words = set()

flag = True
for i in range(N):
    word = input()
    if i == 0:
        words.add(word)
        prev_word = word
    else :
        if prev_word[-1] != word[0]:
            flag = False
        else :          
            words.add(word)
            prev_word = word
            
if flag:
    if len(words) == N :
        print('Yes')
    else :
        print('No')
else :
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = set()
for i in range(n):
  w = input()
  if i == 0 or (w[0] == c and w not in s):
    c = w[-1]
    s.add(w)
  else:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
def solve(n, W):
    last = ''
    d = {}
    for w in W:
        if last and last != w[0] or w in d:
            return 'No'
        last = w[-1]
        d[w] = None
    return 'Yes'

_n = int(input())
_W = [input() for _ in range(_n)]
print(solve(_n, _W))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
w = [input() for _ in range(n)]
s = sorted(w)
flag = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        flag = 1
for i in range(n-1):
    #if w[i] in w[:i-1]: flag = 1
    if w[i+1][0] != w[i][-1]:flag = 1
if flag:print("No")
else: print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict


def solve():
    N = int(input())
    w_dict = defaultdict(int)
    pw = input()
    w_dict[pw] = 1
    for _ in range(N - 1):
        cw = input()
        if cw[0] != pw[-1] or w_dict[cw] == 1:
            print('No')
            exit()
        w_dict[cw] = 1
        pw = cw
    print('Yes')


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
dic = {W[0]:1}
rev = W[0][len(W[0])-1:]
for w in W[1:]:
    if w not in dic:
        dic[w] = 1
        if rev != w[0]:
            print("No")
            exit()
        rev = w[len(w)-1:]
        continue
    print("No")
    exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
A = [input() for _ in range(N)]
pre = A[0]
for a in A[1:]:
  if A.count(pre) >= 2:
    print("No")
    exit()
  if pre[-1] == a[0]:
    pre = a
  else:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
W = read().decode('utf8').split()
temp = W[0][-1]
Ws = set(W)
f = True
if len(Ws) != N:
    f = False

else:
    for w in W[1:]:
        if temp == w[0]:
            temp = w[-1]
        else:
            f = False
            break
print("Yes" if f else "No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    W=[input() for i in range(N)]
    tmp=None
    s=set()
    for w in W:
        if tmp:
            if tmp[-1]!=w[0] or w in s:
                print('No')
                exit()
            else:
                tmp=w
                s.add(w)
        else:
            tmp=w
            s.add(w)
    print('Yes')
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
prev = input()
history = set()
history.add(prev)
ans = "Yes"
for _ in range(N-1):
    now = input()
    if now in history or prev[-1] != now[0]:
        ans = "No"
        break
    history.add(now)
    prev = now
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
words = [input() for _ in range(N)]
w_prev = words[0]
wordlist = [w_prev]
flag = True

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

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

Submission status: Accepted

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

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


for i in range(N-1):
    if W.count(W[i]) >= 2:
        print('No')
        sys.exit()
    if W[i][-1] != W[i+1][0]:
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for _ in range(n)]
ans='Yes'
for i in range(1,n):
  if w[i-1][-1]!=w[i][0]:
    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())
l = []
a = list(input())
l.append(a)
last = a[-1]
for i in range(n-1):
  a = list(input())
  if last != a[0]:
    print("No")
    exit()
  if a in l:
    print("No")
    exit()
  l.append(a)
  last = a[-1]
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
w = [input() for i in range(N)]
for i in range(len(w) - 1):
    if (w.count(w[i]) > 1): print('No'); exit(0)
    if (w[i][-1] != w[i + 1][0]): print('No'); exit(0)
print('Yes')

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

# import math
# import string
import fractions
# from fractions import Fraction
from fractions import gcd

# import re
# import array
# import copy
# import functools
# import operator

import collections
# from collections import deque
# from collections import Counter

# import itertools
# import bisect
# import heapq

# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
# from itertools import accumulate
# import random
# import time
from operator import mul
# from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# def lcm(n, m):
#     return int(n * m / gcd(n, m))

# def reduce_x(p, q):
#     common = fractions.gcd(p, q)
#     return (p // common, q // common)

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce_x(mul, range(n, n - r, -1), 1)
#     denom = reduce_x(mul, range(1, r + 1), 1)
#     return numer // denom

# def reverse_range(a, b):  # b < a ,  get [b, a)
#     return range(b, a, -1)  # range(a, b+1, -1)


def main():
    n = int(input().strip())
    s_old = input().strip()
    C = collections.Counter()
    C[s_old] += 1

    s_new = ""

    for i in range(n - 1):
        s_new = input().strip()
        C[s_new] += 1
        if C[s_new] > 1 or s_new[0] != s_old[-1]:
            print("No")
            return
        s_old = s_new
    print("Yes")
    eprint("debug")
    pass
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

for i in sList:
  if sList.count(i) > 1:
    print("No")
    exit(0)

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

print("Yes")

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    W = INPUT()

    l = defaultdict(bool)
    l[W] = True
    for i in range(N-1):
        next_W = INPUT()
        if l[next_W] or next_W[0] != W[-1]:
            print("No")
            sys.exit()
        l[next_W] = True
        W = next_W

    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
w = []
for i in range(n):
    w.append(str(input()))

count = n
for i in range(n - 1):
    for j in range(i + 1, n):
        if w[i] == w[j]:
            count = 0

for i in range(n - 1):
    s1 = list(w[i])
    s2 = list(w[i + 1])
    #print(s1)
    #print(s2)
    if s1[len(s1) - 1] != s2[0]:
        #print(i)
        count = 0

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
l = [input() for i in range(n)]
count=1

l_f = [x for x in set(l) if l.count(x) > 1]
if len(l_f) != 0:
    print('No')
    sys.exit()
for i in l:
    
    last = i[-1]
    try:
        first = l[count][0]
        count+=1
        if last == first:
            continue
        else:
            print('No')
            sys.exit()
    except IndexError:
        print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

s = set()
# print(w)
for a, i in enumerate(w):
    if a == 0:
        lastword = i[-1]
        s.add(i)
        continue
    if i[0] != lastword or i in s:
        print("No")
        sys.exit()
    lastword = i[-1]
    s.add(i)
print("Yes")

Submission status: Accepted

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

for i in range(1,len(li)):
    if li[i][0] == li[i-1][-1] and li[i] not in li2:
        li2.append(li[i])
    else:
        print("No")
        break
if li==li2:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

N=int(input())
W=[list(input()) for i in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if W[i]==W[j]:
            print("No")
            sys.exit()
for i in range(1,N):
    if W[i][0]==W[i-1][-1]:
        continue
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for _ 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 = [input() for i in range(N)]
flag = True

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

Submission status: Accepted

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

if (len(set(w)) < len(w)):
   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:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np



def main():
	n=int(input())
	w=[input().rstrip().decode('utf-8') for _ in range(n)]
	
	now=w[0][-1]
	
	ans="Yes"
	
	wset=set(w)
	if len(wset)!=n:
		ans="No"
		
	for i in range(1,n):
		if now!=w[i][0]:

			ans="No"
		now=w[i][-1]

	
	print(ans)
	




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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
b = len(set(W))==len(W) and all(map(lambda s,t:s==t, (s[-1] for s in W[:-1]) ,(s[0] for s in W[1:])))
print("YNeos"[not b::2])

Submission status: Accepted

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

ok = True
for i in range(1, len(words)):
    w = words[i]
    if words[i-1][-1] != w[0] or w in exsited_words:
        ok = False
        break
    exsited_words.append(w)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n, *words = sys.stdin.read().split()
n = int(n)

def main():
    announced = set()
    last = words[0][0]
    for w in words:
        if w in announced:
            return 'No'
        elif w[0] != last:
            return 'No'
        announced.add(w)
        last = w[-1]
    return 'Yes'

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

l = []
ans = 'Yes'

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

    if l.count(w) >= 1:
        ans = 'No'
        break
    
    if i > 0:
        befor = l[i - 1]

        if w[0] != befor[-1]:
            ans = 'No'
            break

    l.append(w)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
W = [input().strip() for i in range(N)]
s = set(W)
flag = False
if len(list(s)) != N:
    print("No")
else:
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            flag = True
            break
    if flag:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
import math
import heapq
import sys
from collections import Counter
import datetime
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

#N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

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



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

print('Yes')

Submission status: Accepted

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

flag = True

for i in range(1, n):
    if w_list[i-1][-1] != w_list[i][0]:
        flag = False
    elif w_list[i] in w_list[:i-1]:
        flag = False
if flag == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
W = []
for _ in range(n):
    w = input()
    if w in W:
        print('No')
        exit()
    W.append(w)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
n = int(input())
a = set()
temp = input()
end_char = temp[-1]
a.add(temp)
for i in range(n-1):
    temp = input()
    if temp in a or end_char != temp[0]:
        print('No')
        exit()
    end_char = temp[-1]
    a.add(temp)
print('Yes')

Submission status: Accepted

Solution code:
B = ""
L = []
N = int(input())
W1 = input()
L.append(W1)
for _ in range(N-1):
    W = input()
    if W in L:
        print("No")
        exit()
    L.append(W)
    if not W1[-1] == W[0]:
        print("No")
        exit()
    W1 = W
print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
W = []
for _ in range(N) :
  W.append(str(input()))
#print (W)

wl = []
for i in range(N) :
  if W[i] not in wl :
    wl.append(W[i])
  else :
    print ("No")
    exit()
  if i > 0 :
    if W[i-1][-1] != W[i][0] :
      print ("No")
      exit()
print ("Yes")

Submission status: Accepted

Solution code:
n = int(input())

words = [input() for i in range(0, n)]

shiritori = []

def solve():
  last_char = words[0][0]
  for i in range(0, n):
    # 既に使った単語があるとダメ
    if words[i] in shiritori:
      print('No')
      return
    
    # 前の単語の末尾の文字と今の単語の先頭の文字が不一致だとダメ
    if words[i][0] != last_char:
      print('No')
      return

    last_char = words[i][len(words[i])-1]
    shiritori.append(words[i])

  print('Yes')


def main():
  solve()


if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
W = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(N)]

ok = len(set(W)) == len(W)
for s, t in zip(W, W[1:]):
    ok &= s[-1] == t[0]
if ok:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# coding: utf-8

log = []

count = int(input())

isValid = True
prev = ""
for i in range(count):
    word = input().rstrip()
    if len(prev) > 0:
        if word[0] != prev[-1]:
            isValid = False
    if word in log:
        isValid = False

    log.append(word)
    prev = word

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
m = {}
n = int(input())
prev = ""
ok = True
for i in range(n):
  s = input()
  if i != 0:
    if prev[-1] != s[0]:
      ok = False
  if s in m:
    ok = False
  prev = s
  m[s] = 1
print("Yes" if ok else "No")

Submission status: Accepted

Solution code:
n = int(input())

A = []

for i in range(n):
    s = input()
    if i == 0:
        A.append(s)
    else:
        if A[-1][-1] == s[0] and A.count(s) == 0:
            A.append(s)
        else:
            break
if len(A) == n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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


for i in range(N-1):
    if W[i][-1:] != W[i + 1][:1]:
        flg = False
        break
    if W[i] in words or W[i+1] in words:
        flg = False
        break
    words.add(W[i])


print('Yes') if flg == True else print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
S = input()
s_tail = S[len(S)-1]
A = []
A.append(S)
flg = 0

for i in range(N-1):
    S = input()
    s_head = S[0]
    if s_tail!=s_head:
        flg = 1
    elif not (S in A):
        A.append(S)
    else:
        flg = 1

    s_tail = S[len(S)-1]

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

Submission status: Accepted

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

if len(set(W)) < N:
    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 = [str(input()) for _ in range(n)]
tmp = 0

for i in range(n-1):

    if w.count(w[i])==1 and str(w[i])[-1]==str(w[i+1])[0]:
        tmp += 1

if tmp==n-1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n= int(input())
words=[input() for i in range(n)]
flag="Yes"
if len(words)!=len(set(words)):
  print("No")

else:
  for i in range(n-1):
    if words[i][-1]==words[i+1][0]:
      pass
    else:
      flag="No"
      break
  print(flag)

Submission status: Accepted

Solution code:
N = int(input())
moji = input()
moji_len = []
moji_len.append(moji)
flag = "Yes"
for i in range(N-1):
	siri = input()
	if(siri in moji_len):
		flag = "No"
	if not(moji[-1]==siri[0]):
		flag = "No"
	moji_len.append(siri)
	moji = siri
print(flag)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

W_set = set(W)

flag = 0

if len(W) != len(W_set):
    print("No")
else:
    for idx, w in enumerate(W[:-1]):
        if w[-1] == W[idx + 1][0]:
            continue
        else:
            flag = 1
            break
    if flag == 0:
        print("Yes")
    else:
        print("No")