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())
start = input()
words = [start]
last = start[-1]
ans = 'Yes'
for i in range(n - 1):
  inp = input()
  if inp in words or last != inp[0]:
    ans = 'No'
    break
  words.append(inp)
  last = inp[-1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
words = [input() for _ in range(N)]
counts = Counter(words)

if max(counts.values()) > 1:
    print('No')
else:
    for i in range(1, len(words)):
        if words[i][0] != words[i - 1][-1]:
            print('No')
            break
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)

inf = 10 ** 15
mod = 10 ** 9 + 7
n = int(input())
judge = []
w = input()
pre = w[-1]
judge.append(w)
for i in range(n-1):
    w = input()
    if w[0] == pre and (not w in judge):
        pre = w[-1]
        judge.append(w)
    else:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
List = []
for i in range(N):
  if(i == 0):
    W1 = input()
    List.append(W1)
  else:
    W2 = input()
    if(W1[-1] != W2[0] or W2 in List):
      print("No")
      exit()
    else:
      W1 = W2
      List.append(W2)
print("Yes")

Submission status: Accepted

Solution code:
import collections

N = int(input())

W = []

ns = ""
tflag = False
for count in range(N):
    W.append(str(input()))
    if ns == "":
        ns = W[count]
    else:
        if ns[len(ns)-1] != W[count][0]:
            tflag = True
        else:
            ns = W[count]


ls = collections.Counter(W)

for ccount in ls.values():
    if ccount > 1:
        tflag = True
        break
if tflag == True:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
prev = input()
s = set([prev])
for i in range(n-1):
    w = input()
    if w in s:
        print('No')
        exit()
    if w[0] != prev[-1]:
        print('No')
        exit()
    s.add(w)
    prev = w
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
flg = 0
arr = []*n
arr.append(input())
for i in range(n-1):
  tmp = input()
  if arr[-1][-1] != tmp[0]:
    flg = 1
  if tmp in arr:
    flg = 1
  arr.append(tmp)
if flg == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A=int(input())
C=input()
B=set([C])
for i in range(A-1):
    D=input()
    if D in B or C[-1] != D[0]:
        print("No")
        exit()
    else:
        B.add(C)
        C=D
print("Yes")

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N,=pin()
    s=set()
    prev=""
    for i in range(N):
        temp=input()
        if temp in s:
            print("No")
            return
        if i>0 and temp[0]!=prev[-1]:
            print("No")
            return
        s.add(temp)
        prev=temp
    print("Yes")
#%%submit!
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

said = []
prev = ""
safe = True
for w in words:
    if prev == "":
        prev = w
        said.append(w)
        continue
    else:
        if prev[-1] != w[0]:
            safe = False
            break
        else:
            if w in said:
                safe = False
                break
            else:
                prev = w
                said.append(w)

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

Submission status: Accepted

Solution code:
n = int(input())

words = [input()]

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

Submission status: Accepted

Solution code:
import fileinput

n = int(input())

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

print("Yes")

Submission status: Accepted

Solution code:
from sys import exit

n=int(input())
w=input()

a=set()
a.add(w)
w=w[-1]
cnt=0

for _ in range(n-1):
	x=input()
	if x in a or w!=x[0]:
		cnt=1
	w=x[-1]
	a.add(x)

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

Submission status: Accepted

Solution code:
n=int(input())
lst=[str(input()) for i in range(n)]
flag = False
if len(set(lst))==n:
  if all([lst[j][-1]==lst[j+1][0] for j in range(0, n-1)]):
    flag=True
print("Yes" if flag==True else "No")

Submission status: Accepted

Solution code:
import sys
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')
    sys.exit()
for i in range(n - 1):
  for j in range(i + 1, n):
    if w[i] == w[j]:
      print('No')
      sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
words = [input() for _ in range(n)]
words_count = collections.Counter(words)
first_word = words[0]
word_end = first_word[0]
not_siritori = 0

for i in words_count.values():
  if i > 1:
    not_siritori += 1

for word in words:
  if word_end != word[0]:
    not_siritori += 1
  word_end = word[-1]

if not_siritori != 0:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
ans = 'Yes'
if len(set(W)) != N:
    ans = 'No'
prev = W[0]
for w in W[1:]:
    if w[0] != prev[-1]:
        ans = 'No'
    prev = w
print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(input())
words = [input() for i in range(N)]
after = [words[0]]

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

Submission status: Accepted

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    words = [input() for _ in range(n)]
    appeared = []
    for i in range(n):
        s = words[i]
        if i != 0:
            if s in appeared or s[0] != appeared[-1][-1]:
                print('No')
                exit()
        appeared.append(s)
    print('Yes')

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    W = [""] * N
    for i in range(N):
        W[i] = input().rstrip()

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

    c = Counter(W)
    values = c.values()
    condition_2 = all(v == 1 for v in values)

    if condition_1 and condition_2:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())

w=[]
for _ in range(n):
    w.append(input())

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

temp=w[0][0]

for item in w:
    if temp!=item[0]:
        print("No")
        exit()
    else:
        temp=item[-1]

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

word_list = []
f = 0
for i, n in enumerate(range(N)):
  s = input()
  if i == 0:
    pre = s[-1]
    word_list.append(s)
    continue
  if s in word_list:
    f = 1
    break
  if s[0] != pre:
    f = 1
    break
  pre = s[-1]
  word_list.append(s)
if f == 1:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = input()
temp_set = {w}
c = w[-1]
ans = "Yes"
for _ in range(n - 1):
    w = input()
    if w[0] != c or w in temp_set:
        ans = "No"
        break
    temp_set.add(w)
    c = w[-1]
print(ans)

Submission status: Accepted

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

memo = [W[0]]
OK = True
pre = W[0]
for word in W[1:]:
    if word in memo or pre[-1] != word[0]:
        OK = False
        print("No")
        break
    memo.append(word)
    pre = word
if OK:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
    n = int(input())
    w = []
    bit = 0
    for i in range(n):
        w.append(input())
    if len(set(w)) != n:
        print("No")
    else:
        for i in range(n-1):
            if w[i][-1] != w[i+1][0]:
                print("No")
                bit = 1
                break
        if bit == 0:
            print("Yes")
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(input())
Word = []
tail = ""
for i in range(N):
    W = list(input())
    head = W[0]
    W = ''.join(W)
    if i != 0:
        if tail != head or (W in Word):
            print("No")
            exit()
    tail = W[-1]
    Word.append(W)
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

tmp = input()
used = set([tmp])
for _ in range(n-1):
  w = input()
  
  if tmp[-1] != w[0] or w in used:
    print("No")
    break
  
  used.add(w)
  tmp = w
else:
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
resl = "Yes"
wrds = set()
for i in range(n):
  sng = input()
  if i==0:
    lst = sng[len(sng)-1]
    wrds.add(sng)
  elif sng[0]==lst and (sng not in wrds):
    lst = sng[len(sng)-1]
    wrds.add(sng)
  else:
    resl = "No"
print(resl)

Submission status: Accepted

Solution code:
n = int(input())
words = set()
lastWord = None
for _ in range(n):
  word = input()
  if word in words:
    print('No')
    break
  words.add(word)
  
  if lastWord and lastWord[-1] != word[0]:
    print('No')
    break
  lastWord = word
else:
  print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

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

buf = set()

target = S[0][0]
for s in S:
    if s in buf:
        print("No")
        exit()
    else:
        if s[0] != target:
            print("No")
            exit()

        buf.add(s)
        target = s[-1]

print("Yes")

Submission status: Accepted

Solution code:

n = int(input())
w = [input() for i in range(n)]
wset = set(w)
flag = True
if len(wset) != n:
  flag = False

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

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

Submission status: Accepted

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

if n == len(set(words)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
n = int(input())
ls = [str(input()) for i in range(n)]
if len(ls) != len(list(set(ls))):
    print("No")
    sys.exit()
for i in range(n):
    if i == 0:
        a = ls[0]
    else:
        if ls[i-1][-1] == ls[i][0]:
            continue
        else:
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

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

  if len(W) == 0 or (W.count(w) == 0 and l == w[0]):
    W.append(w)
    l = w[-1]
  else:
    print("No")
    exit()    

print("Yes")

Submission status: Accepted

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

for i in range(1, N):
  if W.count(W[i]) != 1 or W[i - 1][-1] != W[i][0]:
    flag = False
    break

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[input() for i in range(n)]
    ll=[]
    ans='Yes'
    if len(set(l))!=n:
        ans='No'
    else:
        for j in range(n-1):
            if l[j][-1]==l[j+1][0]:
                ll.append(l[j])
            else:
                ans='No'
                break
    print(ans)
resolve()

Submission status: Accepted

Solution code:
n = int(input())
w_list = [input() for i in range(n)]
dum = w_list[0][-1]
#print(dum)
for i in range(1,n):
    if w_list[i][0] != dum:
        print("No")
        exit()
    dum = w_list[i][-1]
w_list_len = len(w_list)
w_set = set(w_list)
w_set_len = len(w_set)
if w_set_len != w_list_len:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

def main():
    N, *W = map(str, open(0).read().split())
    
    if not int(N) == len(set(W)):
        print('No')
    else:
        for i in range(1, int(N)):
            if not W[i][0] == W[i -1][-1]:
                print('No')
                exit()
        print('Yes')


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w_list = [input() for nesya in range(n)]
a = len(set(w_list))
t = 1
c = 0
while t < n:
  if (w_list[t-1])[-1] != (w_list[t])[0]:
    print('No')
    c += 1
    break
  t +=1
if c == 0:
  if a == n:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
if len(w) != len(set(w)):
    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())
x=[input() for _ in range(N)]
flag=0

if len(x)!=len(list(set(x))):
  flag=1

for i in range(N-1):
  if x[i][-1]!=x[i+1][0]:
    flag=1
if flag==0:
  print("Yes")
else:
  print("No")

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(1, n):
    if w[i-1][-1] != w[i][0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys

N = int(input())
items = []
for i in range(N):
  item = input()
  items.append(item)

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

for i in range(len(items)):
  if(i != 0 and items[i][0] != items[i-1][-1]):
    print('No')
    sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
def solve(W):
    set_W = set(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)]

if solve(W):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
ans='Yes'
S=[input() for i in range(n)]

if len(set(S))!=n:
  ans='No'

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
d=[]
for i in range(n):
    w=input()
    if i>=1:
        if w[0]!=last:
            print('No')
            sys.exit()
    last=w[-1]
    d.append(w)
d=sorted(d)
for i in range(len(d)-1):
    if d[i]==d[i+1]:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

N = int(input())

lw = list()
for i in range(N):
    lw.append(input())

def check1(l):
    c = collections.Counter(l)
    lv = list(c.values())
    if lv == [1] * len(lv):
        return 1

def check2(l):
    c = 0
    for i in range(len(l)-1):
        if l[i][-1] == l[i+1][0]:
            c += 1
    if c == len(l) - 1:
        return 1

if check1(lw) == 1 and check2(lw) == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p = []
for i in range(n):
    p.append(input())
    
for i in range(n):
    if p.count(p[i]) != 1:
        print("No")
        exit()
for i in range(1,n):
    mae = p[i-1]
    ato = p[i]
    if mae[-1] != ato[0]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

r=set(w)
o=''
m=''
if len(r) != len(w):
    
    print('No')
    sys.exit()

for i in range(n-1):
    o=w[i]
    m=w[i+1]
    if o[-1] != m[0]:
        print('No')
        sys.exit()
    
        
        
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

t = set(w)
if len(w) != len(t):
    print("No")
    exit(0)

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

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input()) 
w = [input() for _ 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 numpy as np
import sys
import math

n=int(input())
W=[input() for i in range(n)]
if len(W)!=len(set(W)):
    print('No')
    sys.exit()
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())
W=[input() for _ in range(N)]
ans='Yes'

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

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

print(ans)

Submission status: Accepted

Solution code:
MOD = 10 **9 + 7
INF = 10 ** 10

def main():
    N = int(input())
    w = input()
    W = {w}
    before = w
    flag = True
    for _ in range(N - 1):
        w = input()
        if w in W:
            flag = False
            break
        else:
            if before[-1] != w[0]:
                flag = False
                break
            before = w
            W.add(w)
    print('Yes' if flag else 'No')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

n=I()
words=[input().rstrip() for i in range(n)]
u=len(list(set(words)))
if u!=n:
    print("No")
    sys.exit()
for i in range(n-1):
    if words[i][-1]!=words[i+1][0]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
W = []
flag = True
for i in range(n):
    w = input()
    if w in W:
        flag = False
    if i > 0 and W[i-1][-1] != w[0]:
        flag = False
    W.append(w)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc109/tasks/abc109_b

n = int(input())

words = []
for _ in range(n):
    words.append(input())

pre = words[0]
done = set([pre])
for i in range(1, n):
    w = words[i]
    if pre[-1] == w[0] and w not in done:
        pre = w
        done.add(w)
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

if len(set(l)) < n:
    print("No")
    sys.exit()

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

print("Yes")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
l = [input() for i in range(n)]
n_l = [l[0]]
ans = "Yes"
for i in range(1,n):
    if l[i] not in n_l:
        n_l.append(l[i])
    else:
        ans = "No"
        break

    if l[i-1][-1] == l[i][0]:
        continue
    else:
        ans = "No"

print(ans)

Submission status: Accepted

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

jdg = True

s_last = w[0][-1]
ss = [w[0]]

for s in w[1:]:
    if s in ss:
        jdg = False
        break
    if s[0] != s_last:
        jdg = False
        break
    s_last = s[-1]
    ss.append(s)
print('Yes' if jdg else 'No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


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


def solve(N: int, W: "List[str]"):
    print(YES if len(set(W)) == N and all(
        W[i][-1] == W[i + 1][0]
        for i in range(N - 1)
    ) else NO)


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:
import numpy as np
import sys

input = sys.stdin.readline

N = int(input())

x = []

res = True
for i in range(N):
    w = input()
    w = w[:(len(w)-1)]
    if w in x:
        res = False
    x.append(w)
    if i > 0: 
        if w[0] != x[i-1][-1]:
            res = False
        

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
li = [input() for _ in range(n)] #n行に１つずつ入力されるmojiretu
ans = 'Yes'
lw = li[0][0]
for s in li:
    if lw != s[0]:
        ans = 'No'
        break
    else:
        lw = s[-1]

c = collections.Counter(li)
if c.most_common()[0][1] != 1:
    ans = 'No'
print(ans)

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

Submission status: Accepted

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

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(n-1):
    temp = w[i]
    temp2 = w[i+1]
    if temp[-1] != temp2[0] or has_duplicates(w) == True :
        print("No")
        exit()
print("Yes")