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())
word = []
now = ""
for i in range(N):
  w = input()
  if i == 0:
    word.append(w)
    now = w[-1]
  else:
    if w[0] == now and w not in word:
      word.append(w)
      now = w[-1]
    else:
      break
if len(word) == N:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys

N = int(input())
W = [0]*N
for i in range(N):
    W[i] = input()
tail = W[0][-1]
past = [W[0]]
for i in range(1,N):
    head = W[i][0]
    if tail == head and not (W[i] in past):
        tail = W[i][-1]
        past.append(W[i])
    else:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

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


def solve(lis):
	if len(lis) != len(set(lis)):
		return False

	for i in range(N-1):
		if lis[i][-1] != lis[i+1][0]:
			return False

	return True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N = I()
    w = []
    wc = set()

    for i in range(N):
        w.append(S())
        if w[i] in wc:
            print('No')
            return
        wc.add(w[i])

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

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1,N):
    k = input()
    W.append(k)
    if W[-2][-1]!=k[0] or len(set(W))!=(i+1):
        a = 'No'
        break

print(a)

Submission status: Accepted

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

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)]
used = []
ans = "Yes"

used.append(W[0])

for x in range(N-1):
    if W[x][-1] != W[x+1][0]:
        #print(W[x][0])
        ans = "No"
        break
    if W[x+1] in used:
        ans = "No"
        break
    else:
        used.append(W[x+1])

print(ans)

Submission status: Accepted

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


def main():
    N = int(input())
    flag = True
    pre = input()
    done = {pre}
    for _ in range(N - 1):
        now = input()
        if now[0] != pre[-1] or now in done:
            flag = False
        pre = now
        done.add(pre)
    if flag: print("Yes")
    else: print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())


s_ = input()
s_set = set([s_])

ans = 'Yes'

for _ in range(N-1):
    s = input()
    if s in s_set:
        ans = 'No'
    if s[0] != s_[-1]:
        ans = 'No'
    s_set.add(s)
    s_ = s

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for _ in range(n)]
flag = 0
if len(set(w)) == len(w):
    hoge = ''
    for i in range(n):
        if i == 0:
            hoge = w[i][len(w[i])-1]
        elif hoge == w[i][0]:
            hoge = w[i][len(w[i])-1]
        else:
            flag = 1
            break
    if flag == 1:
        print('No')
    else:
        print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N=int(input())
s=input()
t=s[len(s)-1]
S=[s]
for i in range(N-1):
  s = input()
  if s in S:
    print("No")
    break
  elif t==s[0]:
    t=s[len(s)-1]
    S.append(s)
  else:
    print("No")
    break

if len(S)==N:
  print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
out = "Yes"
S = input()
L = []

L.append(S)
for i in range(N-1):
    T = input()
    if T in L:
        out = "No"
    if T[0]!=S[-1]:
        out = "No"
    S = T
    L.append(S)
print(out)

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for _ in range(n)]
f=True
for i in range(1,n):
	if w[i-1][-1] == w[i][0]:
		f=True
	else:
		f=False
		break
if f==False:
	f=False
elif len(list(set(w))) == len(w):
	f=True
else:
	f=False
if f:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for _ in range(n)]
f=True
for i in range(1,n):
	if w[i-1][-1] == w[i][0]:
		f=True
	else:
		f=False
		break
if f==False:
	f=False
elif len(list(set(w))) == len(w):
	f=True
else:
	f=False
if f:
	print('Yes')
else:
	print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
	n = int(input())
	ws = [input() for _ in range(n)]
	cnt = []
	for w in ws:
		if w in cnt:
			print('No')
			return
		if len(cnt) and cnt[-1][-1] != w[0]:
			print('No')
			return
		cnt.append(w)
	print('Yes')
resolve()

Submission status: Accepted

Solution code:
N = int(input())
ans = "Yes"
appeared_words = [input()]
for _ in range(N - 1):
    curr_word = input()
    if appeared_words[-1][-1] != curr_word[0] or curr_word in appeared_words:
        ans = "No"
    appeared_words.append(curr_word)
print(ans)

Submission status: Accepted

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

if len(W) != len(set(W)):
    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())
lis=[input()]
ok=True
for i in range(n-1):
    a=input()
    if a in lis:
        ok=False
        break
    if lis[-1][-1]!=a[0]:
        ok=False
        break
    lis.append(a)
if ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
W = {}
last=""
flg = True

w =[]

for i in range(N):
    w.append(str(input()))
    
cnt=0
for i in w:
    
    if i in W:
        flg = False
        break
    else:
        W[i] = 1
        
    if cnt !=0:
        if i[0] == last:
            last = i[-1]
        else:
            flg = False
            break
    else:
        last = i[-1]
            
    cnt+=1
        
if(flg == True):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if check == 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()
else:
  w = W.pop(0)
  r = w[-1]
  for w in W:
    if r == w[0]:
      r = w[-1]
    else:
      print('No')
      exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
S = [input() for _ in range(N)]
d = defaultdict()
d[S[0]] = 1
for i in range(1, N):
    if S[i] in d.keys():
        print('No')
        exit()
    d[S[i]] = 1
    if S[i][0] != S[i-1][-1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())

w = [0]*n
used = []

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

if(w[n-1] not in used):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
words = set()
before = ''
now = ''
ans = 'Yes'
for i in range(N):
    now = input()
    if i == 0:
        words.add(now)
        before = now
    elif now not in words and before[-1] == now[0]:
        words.add(now)
        before = now
    else:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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



www = "YYY"
for i in range(N-1):
    if S[i][-1] != S[i+1][0]:
        www = "fuck"

qqq = "ZZZ"
S.sort()
for i in range(N-1):
    if S[i] == S[i+1]:
        qqq = "bich"

if www == "YYY" and qqq == "ZZZ":
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

jdg = 'Yes'
if len(set(w)) != len(w):
    jdg = 'No'
    print(jdg)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def dupchk(seq):
  return len(seq) != len(set(seq))
arrw = []

N = int(input())
for i in range(0,N):
  W = str(input())
  arrw.append(W)

if dupchk(arrw) == False:
  for i in range(0,N-1):
    if arrw[i][-1] != arrw[i+1][0]:
      print("No")
      sys.exit()
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
lst = [input() for i in range(N)]
for i in range(N-1):
    n = lst[i]
    m = lst[i+1] 
    if lst[i+1] in lst[:i+1] or n[-1] != m[0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc109


def main():
    N = int(input())
    W = [None] * N
    for i in range(N):
        W[i] = input()
    
    app = [W[0]]
    for i in range(1, N):
        w = W[i]
        if w in app or w[0] != app[-1][-1]:
            return "No"
        app.append(w)
    
    return "Yes"


print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
l = []    
a = input()
l.append(a)
i = 1
for i in range(s-1):
    b = input()
    if l[-1][-1] != b[0]:
        break
    l.append(b)

ans = set(l)
if len(ans) == s:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
w=list(input()for _ in range(n))
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')
            exit()
    print('Yes')

Submission status: Accepted

Solution code:
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N = inp()
S = []
f = "Yes"
for i in range(N):
    s = input()
    if i > 0:
        prev = S[i-1]
        if s in S or s[0] != prev[-1]:
            f = "No"
    S.append(s)
print(f)

Submission status: Accepted

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

last = ""
s = set()

for i in range(n):
    if i != 0:
        if (last != w[i][0]) or w[i] in s:
            print("No")
            exit()
    s.add(w[i])
    last = w[i][-1]


print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
ans = 'Yes'
if len(w)!= len(set(w)):
    ans = 'No'
else:
    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=[0]*N
W[0]=str(input())
for i in range(1,N):
  s=str(input())
  if s[0]==W[i-1][-1] and s not in W:
    W[i]=s
  else:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
temp=str(input())
templ=list(temp)
tempb=templ[len(templ)-1]
w=[0]*n
w[0]=temp
for i in range(0,n-1):
  temp=str(input())
  templ=list(temp)
  if temp in w or tempb!=templ[0]:
    print("No")
    break
  tempb=templ[len(templ)-1]
  w[i+1]=temp
else:
  print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
words_count = defaultdict(int)

last_word = input()
words_count[last_word] += 1
for _ in range(n - 1):
    word = input()
    if word[0] != last_word[-1]:
        print("No")
        exit()
    if words_count[word] > 0:
        print("No")
        exit()
    words_count[word] += 1
    last_word = word

print("Yes")

Submission status: Accepted

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

ans = "Yes"

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

d = dict()
pre = input()
d[pre] = 1
for _ in range(N - 1):
    w = input()
    if w in d or pre[len(pre) - 1] != w[0]:
        print("No")
        exit()
    d[w] = 1
    pre = w

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
rireki = []
rireki.append(input())
flag = 1
for i in range(N-1):
  rireki.append(input())
  if rireki[-2][-1] != rireki[-1][0]:
    flag = 0
  if rireki[-1] in rireki[:-1]:
    flag = 0
print("Yes" if flag else "No")

Submission status: Accepted

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

N = inputI()
l = inputSLs(N)

if len(set(l))!=N:
  No()
  exit()
else:
  for i in range(N-1):
    if l[i][-1]!=l[i+1][0]:
      No()
      exit()
Yes()

Submission status: Accepted

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

flag = True

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

Submission status: Accepted

Solution code:
import math
import re
import copy

neko = "Yes"
n = int(input())
w = []
for i in range(n):
    w.append(input())
s = copy.copy(w)
if len(set(s)) != len(w):
    neko = "No"
for i in range(len(w)-1):
    if w[i][len(w[i])-1] != w[i+1][0]:
        neko = "No"
        break
print(neko)

Submission status: Accepted

Solution code:
import sys

N = int(input())

W = []
for i in range(N):
    w = str(input())
    if w in W:
        print("No")
        sys.exit()
    if i != 0 and w[0] != W[i-1][-1]:
        print("No")
        sys.exit()
    W.append(w)

print("Yes")

Submission status: Accepted

Solution code:
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

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

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 'Yes'
    N = int(input())
    wl = []
    wl.append(input().rstrip('\n'))
    for i in range(1,N):
        wl.append(input().rstrip('\n'))
        if wl[i-1][-1] != wl[i][0]:
            ans = 'No'
            break
    if len(wl) != len(set(wl)):
        ans = 'No'
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

ans = ['']*n

ans[0] = input()

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

    ans[i] = w
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
prev = input()
said = {prev}
for _ in range(1, N):
    now = input()
    if now not in said and prev[-1] == now[0]:
        said.add(now)
        prev = now
        continue
    print("No")
    break
else:
    print("Yes")

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
W = [s]
for i in range(n-1):
    s = input()
    if W[-1][-1] == s[0] and not s in W:
        W.append(s)
    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(1, n):
    if w[i][0] != w[i - 1][-1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
W = SR(n)
used = set()
last = W[0][0]
for w in W:
    if last != w[0] or w in used:
        print("No")
        exit()
    last = w[-1]
    used.add(w)
print("Yes")

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())
W = []
jud = 1

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

c = collections.Counter(W)
ct = len(c)

for i in range(N-1):
    fst = W[i]
    fnl = W[i+1]
    if fst[-1] != fnl[0]:
        jud = 0

if ct != N:
    print("No")
elif jud == 0:
    print("No")
else: print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
ketu = ""
mozi = []
frag = 0
for i in range(N):
    stri = input()
    if (ketu != "" )and(ketu != stri[0]):
        frag = 1

    ketu = stri[-1]
    mozi.append(stri)

if frag == 1:
    print("No")
    exit()

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

print("Yes")

Submission status: Accepted

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

if len(list(set(W))) == N:
    first = W[0]
    for i in W[1:]:
        if first[-1] != i[0]:
            print("No")
            exit()
        first = i
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

ans = 'Yes'

for i in range(1, n):
    s = input()
    if s in l:
        ans = 'No'
        break
    else:
        if l[-1][-1].endswith(s[0]):
            l.append(s)
        else:
            ans = 'No'
            break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [input() for i in range(N)]
if len(A) != len(set(A)):
    print('No')
else:
    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:
import collections
a = int(input())
words = [input() for i in range(a)]
c = collections.Counter(words)
key = len(c.keys())
tmp = 0
for i in range(len(words)-1):
	if len(words) == key:
		if words[i][-1] == words[i+1][0]:
			tmp += 1
		else:
			tmp = 0
	else:
		break
if tmp == len(words)-1:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
import sys
import math
import bisect

def solve():
    n = int(input())
    my_set = set()
    for i in range(n):
        if i == 0:
            s = input()
            my_set.add(s)
        else:
            pre, s = s, input()
            if pre[-1] != s[0]:
                return False
            if s in my_set:
                return False
            my_set.add(s)
    return True

def main():
    if solve():
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

N = int(input())

memo = defaultdict(int)

for i in range(N):
    tmp = input()
    memo[tmp] += 1
    if i==0:
        last = tmp[-1]
        continue
    if memo[tmp]==2:
        print("No")
        sys.exit()
    else:
        if last != tmp[0]:
            print("No")
            sys.exit()
        last = tmp[-1]
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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