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())
correct = True
words = set({})

W = input()
words.add(W)
last_letter = W[len(W)-1]

for i in range(1,N):
    W = input()
    if  not W in words and W[0] == last_letter:
        words.add(W)
        last_letter = W[len(W)-1]
    else:
        correct = False
        break

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

Submission status: Accepted

Solution code:
n = int(input())
ab = [input() for _ in range(n)] #数字1*複数列入力

l = len(set(ab))

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

Submission status: Accepted

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

for i in range(N):
    if L.count(str(L[i]))<2:
        if str(L[i-1])[-1] == str(L[i])[0]:
            pass
        elif i == 0:
            pass
        else:
            flag = 0
    else:
        flag = 0

if flag:
    print("Yes")

else:
    print("No")

Submission status: Accepted

Solution code:
import sys 

n=int(input())
w=[list(input()) for i in range(n)]
flag=True

for i in range(0,n-1):
    if  w[i+1][0]!=w[i][-1]:
        flag=False
for i in range(0,n-1):
    for j in range(1,n):
        if i==j:
            continue
        if w[i]==w[j]: 
            flag=False
if flag :
    print("Yes")
else : print("No")

Submission status: Accepted

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

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())
D = set()
s = input().rstrip()
D.add(s)
s0 = s[-1]
for _ in range(N-1):
    s = input().rstrip()
    if s in D:
        print("No")
        exit()
    if s[0] != s0:
        print("No")
        exit()
    D.add(s)
    s0 = s[-1]
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
e=''
S=[input() for  _ in range(n)]

for w in S:
    if e!=w[0] and e!='':
        print('No')
        exit()
    e=w[-1]

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

Submission status: Accepted

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

for i in range(N):
  w = input()
  W.append(w)
  
  if i != 0:
    if W[i-1][-1] != W[i][0] or W.count(w) >= 2:
      flag = 0
      
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

ok = True
for i in W:
    if W.count(i)>1:
        ok = False
        
for i in range(1,N):
    if W[i-1][-1] != W[i][0]:
        ok = False
        
if ok:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
pre = input()
dict = {pre:1}
for i in range(N-1):
    now = input()
    if now[0]!=pre[-1]:
        print('No')
        exit(0)
    elif now in dict:
        print('No')
        exit(0)
    else:
        dict[now] = 1
        pre = now 
print('Yes')

Submission status: Accepted

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

ans = "Yes"

words.append(w)

for i in range(1,n):
    w = input()
    if w not in words:
        if words[-1][-1]==w[0]:
            words.append(w)
            continue
        else:
            ans = "No"
            break
    else:
        ans = "No"
        break
print(ans)

Submission status: Accepted

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

words.append(w)

for i in range(1,n):
    w = input()
    if w not in words:
        if words[-1][-1]==w[0]:
            words.append(w)
            continue
        else:
            print("No")
            sys.exit()
    else:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ls = []
ans = ('Yes')
for i in range(N):
    ls.append(input())
for i in range(1,N):
    if ls[i] in ls[:i]:
        ans = ('No')
        break
    else:
        if ls[i][0] == ls[i-1][-1]:
            continue
        else:
            ans = ('No')
            break
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
tmp = []
isOK = True
for i in range(n):
    s = str(input())
    if len(tmp)!=0:
        if s in tmp:
            #print(s,tmp)
            isOK = False
            break
        if end!=s[0]:
            #print(end,s)
            isOK = False
            break
    end = s[-1]
    tmp.append(s)

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

Submission status: Accepted

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

flag = True

for i in range(n-1):
    s = input()
    if s not in l and s[0] == l[-1][-1]:
        l.append(s)
    else:
        flag = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

flag=True
if len(set(w))!=n:
    flag=False
    
for i in range(n-1):
    if w[i][-1]!=w[i+1][0]:
        flag=False

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n =int(input())
W=[]
w=''
for i in range(n):
    s=str(input())
    if i !=0 and w[-1] != s[0]:
        print('No')
        exit()
    else:
        w=s
        W.append(w)
if len(W) != len(list(set(W))):
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
for i,w in enumerate(l:=[input() for _ in range(int(input()))]):
  if i and (l[i][0]!=l[i-1][-1] or w in l[:i]): exit(print('No'))
print('Yes')

Submission status: Accepted

Solution code:
l=[input() for _ in range(int(input()))]
for i,w in enumerate(l):
  if i and (l[i][0]!=l[i-1][-1] or w in l[:i]): exit(print('No'))
print('Yes')

Submission status: Accepted

Solution code:
l=[input() for _ in range(int(input()))]
for i,w in enumerate(l):
  if i:
    if l[i][0]!=l[i-1][-1] or w in l[:i]:
      exit(print('No'))
print('Yes')

Submission status: Accepted

Solution code:
l=[input() for _ in range(int(input()))]
for i,w in enumerate(l):
  if i:
    if l[i][0]==l[i-1][-1] and w not in l[:i]:
      continue
    exit(print('No'))
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
w = list(input() for _ 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())
a = input()
s = {a}
a = a[-1]
c = 1
for _ in range(n-1):
    b = input()
    if a == b[0]:
        a = b[-1]
        c += 1
        s.add(b)
    else:
        print('No')
        break
else:
    print('Yes' if len(s) == c else 'No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
cnt = 0
for j in range(n-1):
    if (w[j][-1] == w[j+1][0])&(w.count(w[j])==1):
        pass
    else:
        cnt += 1
print("No") if cnt else print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = input()
double_set = set()
double_set.add(w)
finish_str = w[-1]

for i in range(1, n):
    w = input()
    if w not in double_set and w[0] == finish_str:
        double_set.add(w) 
        finish_str = w[-1]
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    W = [readline().strip() for _ in range(N)]

    for w in W:
        if W.count(w) > 1:
            print('No')
            return

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

    print('Yes')
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
for i in range(n):
    flag = True
    for j in range(i):
        if w[i] == w[j]:
            flag = False
    if not flag:
        break
    elif i >= 1 and w[i-1][-1] != w[i][0]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [input() for _ in range(n)]

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

if (len(w) != len(set(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:
N = int(input())
w = ""
S = []
f = True
for i in range(N):
    W = input()
    if i != 0:
        if W[0] != w[(len(w) - 1)] or W in S:
            f = False
            break
    w = W
    S.append(w)
if f == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
if len(W) != len(set(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


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    words = []
    flag = True
    for i in range(n):
        w = ns()
        if w in words:
            flag = False
        elif i != 0 and w[0] != words[-1][-1]:
            flag = False
        else:
            words.append(w)
    print('Yes' if flag else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc109/tasks/abc109_b
import collections
N = int(input())
Word_List = []
SP = ""
for i in range(N):
    CW = str(input())
    if i == 0:
        Word_List.append(CW)
        SP = CW[-1]
    elif SP != CW[0]:
        print("No")
        break
    else:
        Word_List.append(CW)
        SP = CW[-1]
else:
    Word_List = collections.Counter(Word_List)
    if len(Word_List) != N:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

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

for i in W:
    if W.count(i) > 1:
        print('No')
        exit()

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

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    W = [SS() 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)) < len(W):
        ans = 'No'

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import collections
N=int(input())
W=[""]*N
for i in range(N):
  W[i]=input()
c=collections.Counter(W)
if len(c)!=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:
def main():
    N = int(input())
    W_before = input()
    word_set = set()
    word_set.add(W_before)
    for i in range(N-1):
        W_after = input()
        if W_before[-1] != W_after[0]:
            print('No')
            return
        if W_after in word_set:
            print('No')
            return
        word_set.add(W_after)
        W_before = W_after
    print('Yes')

if __name__ == "__main__":
    main()

Submission status: Accepted

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


if len(set(w)) == N: #set:重複なしのリスト(型はlistではなく、set)
    if all(w[i][-1] == w[i+1][0] for i in range(N-1)):
        print("Yes")
        exit() #プログラムを終了

print("No")

Submission status: Accepted

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

if len(set(W)) == N:
    if all(W[i][-1] == W[i+1][0] for i in range(N-1)):
        print('Yes')
        exit()

print('No')

Submission status: Accepted

Solution code:
N = int(input())

w = input().strip()
d = set([w])
l = w[-1]
f = True
for _ in range(N-1):
    w = input().strip()
    if w.startswith(l) and not w in d:
        d.add(w)
        l = w[-1]
    else:
        f = False
print("Yes" if f else "No")

Submission status: Accepted

Solution code:
import sys

N = int(input())
W = list(input() for _ in range(N))

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

Submission status: Accepted

Solution code:
N = int(input())

words = []
ans = "Yes"
for count in range(N):
    word = input()
    if count == 0:
        words.append(word)
        next = word[-1]
        continue
    if next != word[0]:
        ans = "No"
    if words.count(word) == 1:
        ans = "No"
    words.append(word)
    next = word[-1]


print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    W_before = input()
    W_list = set()
    W_list.add(W_before)
    for i in range(N-1):
        W_after = input()
        if W_before[-1] != W_after[0]:
            print('No')
            return
        if W_after in W_list:
            print('No')
            return
        W_list.add(W_after)
        W_before = W_after
    print('Yes')

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
f = True
w = input()
used = set([w])
last = w[-1]
for i in range(n-1):
    w = input()
    if w in used or w[0]!=last:
        f = False
        break
    else:
        used.add(w)
        last = w[-1]
if f:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import math
from functools import reduce


def read():
    N = int(input().strip())
    W = []
    for i in range(N):
        w = input().strip()
        W.append(w)
    return N, W


def solve(N, W):
    used = dict()
    for w in W:
        if w in used.keys():
            return "No"
        used[w] = True
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            return "No"
    return "Yes"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
N = int(input())
W = [input() for _ in range(N)]

dict = defaultdict(bool)  # int/bool/list....
dict[W[0]] = True
for i in range(1, N):
    if (W[i][0] is not W[i - 1][-1]) or dict[W[i]]:
        print("No")
        sys.exit()
    dict[W[i]] = True

print("Yes")

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
word = []

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

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

v = True
z = list(set(w))
if len(z) != len(w):
  print("No")
else:
  for j in range(N - 1):
    if w[j][-1] != w[j+1][0]:
      v = False
  print("Yes") if v else print("No")

Submission status: Accepted

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

v = True
z = list(set(w))
if len(z) != len(w):
  print("No")
else:
  for j in range(N - 1):
    if w[j][-1] != w[j+1][0]:
      v = False
  print("Yes") if v else print("No")

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for i in range(N)]
pre = ''
shirori = {}
for i in range(N):
    S = s[i]
    if i == 0:
        pre = S[len(S) - 1]
        shirori[S] = 1
        continue
    else:
        if shirori.get(S) is None:
            now = S[0]
            if now == pre:
                pre = S[len(S) - 1]
                shirori[S] = 1
            else:
                print('No')
                exit(0)
        else:
            print('No')
            exit(0)
print('Yes')

Submission status: Accepted

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

for i in range(n):
  x_=input()
  if x_ not in l:
    l.append(x_)
    
  else:
    print('No')
    exit()
    
alpha_list=[chr(i) for i in range(97,123)]

for i in range(len(l)-1):
  if l[i][-1]==l[i+1][0]:
    continue
    
  else:
    print('No')
    exit()
    
print('Yes')

Submission status: Accepted

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

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

L = set(l)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(input())

w = input()
last = w[-1]
past = [w]
for _ in range(N-1):
    w = input()
    if w[0] != last or w in past:
        print('No')
        quit()
    last = w[-1]
    past.append(w)
print('Yes')

Submission status: Accepted

Solution code:
seen = set()

N = int(input())

prev = ""
for i in range(N):
    w = input()
    if w in seen:
        print("No")
        exit()
    seen.add(w)
    if i == 0:
        prev = w[-1]
        continue
    if prev != w[0]:
        print("No")
        exit()
    prev = w[-1]
print("Yes")

Submission status: Accepted

Solution code:
import sys
import heapq
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())

    l = "A"
    s = set()

    for i in range(N):

        w = input()
        if w[0] != l and i!=0:
            print("No")
            exit()
        if w in s:
            print("No")
            exit()
        l = w[-1]
        s.add(w)

    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

res = True

dic = {}

last = ""

for w in W:
    if last != "":
        if w in dic:
            res = False
        if not w[0] == last:
            res = False

    dic[w] = 1
    last = w[-1]


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=input()
d=[a]
for x in range(N-1):
  b=input()
  if b not in d:
    d.append(b)
    if a[len(a)-1]==b[0]:
      a=b
      if x==N-2:
        print("Yes")
    else:
      print("No")
      break
  else:
    print("No")
    break

Submission status: Accepted

Solution code:
s = input()
n = int(s)

check = True

arrays = []

for i in range(n):
    v = input()
    x = list(v)
    if i > 0:
        if not y == x[0]:
            check = False
            break
    for j in range(len(arrays)):
        if arrays[j] == v:
            check = False
            break
    arrays.append(v)
    y = x.pop()

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
x=str(input())
a.append(x)
d=bool(True)

for i in range(1, n):
  y=str(input())
  if x[len(x)-1]!=y[0]:
    d=False
    
  for j in range(len(a)):
    if y==a[j]:
      d=False
  a.append(y)
  x=y

if  d==True:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    words = []
    record = []
    previous = ''
    for i in range(N):
        words.append(str(input()))
    for i in range(N):
        if i == 0:
            record.append(words[i])
            previous = words[i]
        elif not words[i] in record and previous[-1] == words[i][0] and i != 0:
            record.append(words[i])
            previous = words[i]
        else:
            print('No')
            return
    print('Yes')
main()

Submission status: Accepted

Solution code:
n = int(input())
lists = [list(input()) for _ in range(n)]
lists_2 = [lists[0]]
for i in range(1,n):
  if lists[i-1][-1] == lists[i][0]:
    if lists[i] in lists_2:
      print("No")
      exit()
    else:
      lists_2.append(lists[i])
    if i == n-1:
      print("Yes")
    else:
      continue
  else:
    print("No")
    exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

s = []
for i in range(n):
  s.append(input())
  
no = False

s_1 = s[1::]

for i, c in enumerate(s):
  if s.count(c) > 1:
    no = True
    
  if i < len(s)-1:
    c_1 = s_1[i]
    if c[-1] != c_1[0]:
      no = True
      
if no == True:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
import sys
N=int(input())
S=input()
L=list()
m=S[-1]
L.append(S)
for i in range(N-1):
  S=input()
  if S[0]!=m:
    print("No")
    sys.exit()
  else:
    L.append(S)
    m=S[-1]
if len(set(L))==N:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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



word0 = wl[0][-1]

for i in range(1,n):
    if wl[i][0] == word0 and wl[i] not in wl[:i]:
        word0 = wl[i][-1]
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
che = [input()]
for i in range(1,n):
  a = input()
  if a in che:
    print('No')
    exit()
  else:
    che.append(a)
    if che[i-1][-1] == che[i][0]:
      continue
    else:
      print('No')
      exit()
print('Yes')

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	n = int(input())
	s = input()
	A = []
	A.append(s)

	flg = True
	for _ in range(n-1):
		cmd = input()
		if s[-1] == cmd[0] and cmd not in A:
			A.append(cmd)
			s = cmd
		else:
			flg = False

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

Submission status: Accepted

Solution code:
n = int(input())
w = []
flag = 0
tmp = ''

for i in range(n):
    w.append(input())
    if i == 0:
        continue
    elif w[i][0] != w[i-1][len(w[i-1])-1]:
        flag = 1

w = sorted(w)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
list1 = []
count = 0
for i in range(N):
  a = input()
  list1.append(a)
for i in range(N-1):
  if list1[i][-1] == list1[i+1][0]:
    pass
  else:
    count +=1
aaa = set(list1)
if len(aaa) == len(list1):
  pass
else:
  count+=1
if count == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
t = 0
s = set()
ans = 1
for i in range(n):
    w = input()
    if w[0] != t and i >= 1:
        ans = 0
        break
    t = w[-1]
    s.add(w)
if len(s) != n:
    ans = 0
print(["No","Yes"][ans])