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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    result = True
    used = {str(input()): 0}
    for order in range(1,n):
        word = str(input())
        if word in used or list(used.keys())[order - 1][-1] != word[0]:
            result = False
            print('No')
            break
        else:
            used.setdefault(word,0)
    if result:
        print('Yes')
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    result = True
    used = {str(input()): 0}
    for order in range(1,n):
        word = str(input())
        if word in used or list(used.keys())[order - 1][-1] != word[0]:
            result = False
            print('NO')
            break
        else:
            used.setdefault(word,0)
    if result:
        print('Yes')
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    result = True
    used = {' ':0}
    for order in range(0,n):
        word = str(input())
        if word in used or sorted(used.keys())[len(used) -1][-1] == word[0]:
            print('NO')
            result = False
            break
        else:
            used.setdefault(word,0)
    if result:
        print('Yes')
 
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    result = True
    used = {' ':0}
    for order in range(0,n):
        word = str(input())
        print(sorted(used.keys())[len(used) -1])
        if word in used or sorted(used.keys())[len(used) -1][-1] == word[0]:
            print('NO')
            result = False
            break
        else:
            used.setdefault(word,0)
    if result:
        print('Yes')
 
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
dic = {}
w = list(input().split())
ok = True
pre = w[0][0]
for s in w:
  if(s in dic):
    ok = False
  else:
    dic[s] = 0
  if(pre[-1] !=  s[0]):
    ok = False
  pre = s
if ok : print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
dic = {}
w = list(input().split())
ok = True
pre = w[0][-1]
for s in w:
  if(s in dic):
    ok = False
  else:
    dic[s] = 0
  if(pre[-1] !=  s[0]):
    ok = False
  pre = s
if ok : print("Yes")
else: print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [input() for _ in [0]*n]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [input() for _ in [0]*n]

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

Submission status: Wrong Answer

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

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

    use.append(words[i])

print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import sys

# import itertools
# import numpy as np

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

N = int(readline())
W = read().decode('utf8').split()
temp = W[0][-1]
Ws = set(W)
if len(Ws) != N:
    print("No")
else:
    for w in W[1:]:
        if temp == w[0]:
            temp = w[-1]
        else:
            print("No")
            break
    print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

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

print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
W=[]
li=[]
flag=True
flag2=True
for i in range(N):
  W.append(str(input()))
for i in range(N):
  if not(W[i] in li):
    li.append(W[i])
  else:
    print('No')
    flag=False
    flag2=False
if flag:
  for i in range(1,N-1):
    if li[i-1][-1]!=li[i][0] and li[i][-1]!=li[i+1][0]:
      print('No')
      flag2=False
      break
if flag2:
  print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if (len(set(w)) < len(w)):
   print('No')
   exit()

for i in range(1, n-1):
   if (w[i][0] == w[i-1][-1] and w[i][-1] == w[i+1][0]):
      continue
   else:
      print('No')
      exit()
print('Yes')

Submission status: Wrong Answer

Solution code:

n = int(input())
w = []
a = []
status = True

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

a.append(w[0])

for i in range(1,n):
    a.append(w[i])
    if a.count(w[i]) == 1 and (a[i-1])[-1] == (a[i])[0]:
        pass
    else:
        status == False
        print(status)
        break

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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


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

Submission status: Wrong Answer

Solution code:
n = int(input())
word = []
flag = True
for i in range(n):
    w = input()
    if i == 0:
        last = w[-1]
        word.append(w)
    elif i == n - 1 :
        if w not in word:
            pass
        else:
            flag = False
    else:
        if w not in word and w[0] == last:
            last = w[-1]
            word.append(w)
        else:
            last = w[-1]
            word.append(w)
            flag = False

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

Submission status: Wrong Answer

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

for i in range(n-1):

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
W = [input() for _ in range(N)]
for i in range(1,N):
    if W[i-1][-1] != W[i][0] or W[i] in W[:i]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
W = [input() for _ in range(N)]
for i in range(1,N):
    if W[i-1][-1] == W[i][0] or W[i] in W[:i]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())

l = [None] * N

w = input()
l[0] = w
last = l[0][-1]

is_good = True

for i in range(1, N):
    w = input()
    if last != w[-1] or (w in l):
        is_good = False
    l[i] = w
    last = w[-1]

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

Submission status: Wrong Answer

Solution code:
N = int(input())

l = [None] * N

w = input()
l[0] = w
last = l[0][-1]

is_good = True

for i in range(1, N):
    w = input() 
    if last != w[-1] or (w in l):
        is_good = False
    l[i] = w

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

Submission status: Wrong Answer

Solution code:
N = int(input())

l = [None] * N

w = input()
l[0] = w
last = l[0][-1]

is_good = True

for i in range(1, N):
    w = input() 
    if last != w[-1] or (w in l):
        is_good = False
        break
    l[i] = w

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

Submission status: Wrong Answer

Solution code:
n=int(input())
W=[]
for i in range(n):
    w=input()
    W.append(w)
    if i > 0:
        if W[0] == last and str(W).count(W[i]) <= 1:
            ans=1
        else:
            ans=0
            break
    last = W[len(W)-1]
if ans==0:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    W = [input() for j in range(N)]

    D = []
    ans = 'Yes'
    for i in range(N - 1):
        if W[i] in D:
            ans = 'No'
        elif W[i][-1] != W[i + 1][0]:
            ans = 'No'
        else:
            D.append(W[i])

    print(ans)


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=int(input())
c=0
z=[]
y=[]
b=[]
for i in range(a):
    x=str(input())
    z.append(x[0])
    y.append(x[-1])
    if i==0:
        b.append(x)
    if x not in b and z[i]==y[i-1]:
        b.append(x)
        c+=1
if c==a-1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

cnt_A=0
cnt_B=0

for i in range(N-1):
    if list_aaa[i][:-1] ==list_aaa[i+1][1:]:
        cnt_A +=1
    if list_aaa.count(list_aaa[i]) >=2 or list_aaa.count(list_aaa[i]) >=2 :
        cnt_B +=1


if cnt_A >=1 or cnt_B>=1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

cnt_A=0
cnt_B=0

for i in range(N-1):
    if list_aaa[i][:-1] ==list_aaa[i+1][1:]:
        cnt_A +=1
    if list_aaa.count(list_aaa[i]) >=2:
        cnt_B +=1

if cnt_A >=1 or cnt_B>=1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
A=int(input())
B = [input() for _ in range(A)]
count = 0
if len(set(B)) != len(B):
  print('No')
else:
  for b in B:
    if count == 0:
      k = b[-1]
      count += 1
    else:
      if k == b[0]:
        k = b[-1]
      else:
        print('No')
        break;
  print('Yes')

Submission status: Wrong Answer

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


ans = "Yes"
for i in range(N - 1):
  if W[i] not in W and W[i][-0] == W[i + 1][0]:
    pass
  else:
    ans = "No"
    break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
count=2
Ws=[]
W1=input()
Ws.append(W1)
for i in range(1, N-1):
    W=input()
    if W in Ws:
        break
    elif W[0]!=W1[-1]:
        break
    else:
        Ws.append(W)
        W1=W
        count=count+1
if count==N:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

is_satisfied = 'Yes'

if len(w) != len(set(w)):
    is_satisfied = 'No'
else:
    for i in range(1, len(w) - 1):
        if w[i][0] != w[i - 1][-1] or w[i][-1] != w[i + 1][0]:
            is_satisfied = 'No'
            break

print(is_satisfied)

Submission status: Wrong Answer

Solution code:
N = int(input())
words = []
s = input()
words.append(s)
ans = True
for i in range(N-1):
    t = input()
    print(t in words)
    if(t[0] == s[-1] and (t in words) == False):
        words.append(t)
        s = t
    else:
        ans = False
if(ans):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
words = []
s = input()
words.append(s)
ans = True
for i in range(N-1):
    t = input()
    print(t in words)
    if(t[0] == s[-1] and (t in words) == False):
        words.append(t)
        s = t
    else:
        ans = False
        break
if(ans):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
w=[input() for i in range(n)]
last=""
wl=[]
ans="Yes"
for x,i in enumerate(w):
    if x==0:
        last=i[-1]
        continue
    if i in wl:
        ans="No"
    if i[0]!=last:
        ans="No"
    last=i[-1]
    wl.append(i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

t = len(list(set(word)))

if n == t:
    for i in range(n-1):
        if word[i][-1] == word[i+1][0]:
            continue
        else:
            print("No")
    else:
        print("Yes")
else:
        print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions

n = int(stdin.readline().rstrip())

li = [stdin.readline().rstrip() for _ in range(n)]
k = len(li)
lin = list(set(li))

if len(li) != k:
    print("No")
    exit()

for i in range(len(li)-1):
    if li[i][-1] != li[i+1][0]:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions

n = int(stdin.readline().rstrip())

li = [stdin.readline().rstrip() for _ in range(n)]
k = len(li)
li = list(set(li))
if len(li) != k:
    print("No")
    exit()


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

print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

prev = ''
if len(set(W)) != len(W):
    exit(0)

prev = W[0]
for w in W[1:]:
    if prev[-1] != w[0]:
        print('No')
        exit(0)
    prev = w
print('Yes')

Submission status: Wrong Answer

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

prev = ''
if len(set(W)) != len(W):
    exit(0)

prev = W[0]
for w in W[1:]:
    if prev[-1] != w[0]:
        print(prev[-1], w[0])
        print('No')
        exit(0)
    prev = w
print('Yes')

Submission status: Wrong Answer

Solution code:
noOfWords= int(input())
words = []
satisfactor = True
for i in range(noOfWords):
    word = input()
    words.append(word)

if len(set(words)) < len(words):
    print("NO")    
    satisfactor = False 
else:
    for i in range(len(words)-1):
        if words[i][len(words[i])-1] ==  words[i+1][0]:
            continue
        else:
            satisfactor = False
            print("NO")
            break
if satisfactor :
    print("YES")

Submission status: Wrong Answer

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

if len(set(words)) < len(words):
    print("NO")    
    satisfactor = False 
else:
    for i in range(len(words)-1):
        if words[i][len(words[i])-1] ==  words[i+1][0]:
            continue
        else:
            satisfactor = False
            print("NO")
            break
if satisfactor :
    print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(1,len(W)):
  if (W[i-1][-1] != W[i][0]) or (W[i] in W[:i] == True):
    print("No")
    break
else:print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(1,len(W)):
  if W[i-1][-1] == W[i][0] or W[i] in W[:i]:
    print("No")
    break
else:print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())

a=[input() for i in range(n)]

ans=True
if all(a.count(w) == 1 for w in a):
    for i in range(n-1):
        if a[i][-1]!=a[i+1][0]:
            ans=False
    
if ans:    
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())

a=[input() for i in range(n)]

ans=False    
for i in range(n-1):
    if a.count(a[i])==1:
        if a[i][-1] == a[i+1][0]:
            ans=True
        else:
            ans=False
    else:
        ans=False

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

Submission status: Wrong Answer

Solution code:
N = int(input())
words = [input() for i in range(N)]
ans = "Yes"
tmp = list(dict.fromkeys(words))
if words == tmp:
    for j in range(1,N):
        if words[j][0] != words[j-1][-1]:
            ans = "No"
            break
    print(ans)
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
words = [input() for i in range(N)]
ans = "Yes"
tmp = list(dict.fromkeys(words))
if words == tmp:
    for j in range(1,N):
        if words[j][0] != words[j-1][-1]:
            ans = "No"
            break
    for k in range(N):
        if len(words[k]) > 10:
            ans = "No"
            break
    print(ans)
else:
    print("No")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def shiritori():
    n = int(input())
    words = [input() for _ in range(n)]
    print(words)
    for word in words:
        count = 0
        for w in words:
            if w == word:
                count += 1
        if count > 1:
            print('No')
            exit()
    
    for i in range(n):
        if i + 1 <= n - 1:
            x = words[i+1][0]
            y = words[i][-1]
            if x == y:
                continue
            else:
                print('No')
                exit()
    
    print('Yes')


if __name__ == '__main__':
    shiritori()

Submission status: Wrong Answer

Solution code:
N=int(input())
W=[]
c=[]
for _ in range(N):
  W.append(input())
c.append(set(W))
if len(c)!=len(W):
  print("No")
  quit()
for i in range(n-1):
  if W[i][-1]!=W[i+1][0]:
    print("No")
    quit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
S=[input() for _ in range(n)]
ans=1
for i in range(n-1):
    if S[i][-1] == S[i+1][0]:
        ans += 1
print("Yes" if ans == n else "No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Solution code:
N = int(input())
W = [input() for _ in range(N)]
bl = True
if len(W) != len(set(W)):
    bl = False
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        bl = False
print(bl)

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    d = collections.defaultdict(int)
    s = [str(input().rstrip('\n')) for _ in range(n)]
    for i in range(n):
        if i != 0:
            if s[i][0] != s[i-1][-1] or s[i] in d:
                print("NO")
                exit()
        d[s[i]]
    print("YES")


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
 
N = int(input())
W = [input().strip() for _ in range(N)]
 
dic = defaultdict(int)
 
for i in range(N):
  if i == 0:
    tmp = W[i][-1]
    dic[W[i]] = 1
  else:
    if tmp != W[i][0] or dic[W[i]]:
      print("No")
      break
    else:
      tmp = W[i][-1]
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
s=set()
wp=input()
s.add(wp)

f=True
for i in range(n-1):
  wn=input()
  if wp[-1]!=wn[0]:
    f=False
  elif s.issubset(set(wp))==True:
    f=False
  wp=wn
  s.add(wn)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
ary = []
s = 'Yes'
for i in range(N):
  w = input()
  if w in ary:
    s = 'No'
    break
  if len(ary) > 0 and w[0] != ary[-1][-1]:
    s = 'No'
    break
    
print(s)

Submission status: Wrong Answer

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

for i in range(n-1):
  if w[i][-1]!=w[i+1][0]:
    flag*=0
  else:
    flag*=1

for i in w:
  w.remove(i)
  if i in w:
    flag*=0

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

Submission status: Wrong Answer

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

for i in range(n-1):
  if w[i][-1]==w[i+1][0]:
    flag*=1
  else:
    flag*=0

for i in w:
  w.remove(i)
  if i in w:
    flag*=0

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

Submission status: Wrong Answer

Solution code:
N=int(input())
words=[]
flg=True

before=input()
N=N-1

for i in range(N):
    s=input()
    if before[-1] != s[0]:
        flg=False
    words.append(s)
    if len(words) != len(set(words)):
        flg=False
    before=s
print("Yes" if flg else "No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    word_list=[input() for i in range(N)]
    already_list = []
    for i, word in enumerate(word_list):
        if(i==0):
            already_list.append(word)
            continue
        if(word not in already_list and word[0] == word_list[i-1][0]):
            already_list.append(word)
        else:
            print('No')
            return
    print('Yes')




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
k = []
result=[]
for i in range(n):
    a = input()
    k.append(a)
ans = collections.Counter(k)
for i in range(1,n):
    if k[i-1][-1] == k[i][0] and ans.most_common()[0][1] == 1:
        result.append("1")
    else:
        result.append("0")
print(result)
aim = collections.Counter(result)
print(aim.most_common()[0][1])
if aim.most_common()[0][1] != n-1 or aim.most_common()[0][0] =='0':
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
flag_1 = 1
flag_2 = None
inf = [input() for i in range(N)]
for j in range(N):
    for k in range(N):
        if j==k:
            continue
        if inf[j] == inf[k]:
            flag_1 = 0
            break

for p in range(N - 1):
    sear_1 = [q for q in inf[p]]
    sear_2 = [o for o in inf[p + 1]]
    if sear_1[-1] == sear_2[0]:
        flag_2 = 1
    else:
        flag_2 = 0
if flag_1 == 1 and flag_2 == 1:
    print("Yes")
elif flag_1 == 0 or flag_2 ==0:
    print("No")

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    lw = ""
    d = collections.defaultdict(list)
    for i in range(n):
        w = str(input().rstrip('\n'))
        if lw != "":
            if w[0] != lw or w in d:
                print("NO")
                exit()
        lw = w[-1]
        d[w]
    print("YES")


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
N = int(input())
flag_1 = 1
flag_2 = None
inf = [input() for i in range(N)]
print(inf)
for j in range(N):
  for k in range(N):
    if inf[j]==inf[k]:
      flag_1 = 0
      break

for p in range(N-1):
  sear_1 = [q for q in inf[p]]
  sear_2 = [o for o in inf[p+1]]
  if sear_1[-1]==sear_2[0]:
    flag_2 = 1
  else:
    flag_2 = 0
if flag_1 == 1 and flag_2 == 1:
  print("Yes")
elif flag_2 == 0 and flag_2 == 0:
  print("No")

Submission status: Wrong Answer

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

if len(l) != len(set(l)):
    print('No')

flg = True
for i in range(len(l)-1):
    if l[i][-1] != l[i+1][0]:
        print('No')
        flg = False
        break

if flg:
    print('Yes')