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:
n = int(input())
list_w = [input() for s in range(0, n)]
for i in range(0, n):
    if i == 0 or (list_w[i - 1][-1] == list_w[i][0]) and list_w[i] not in list_w[:i]:
        print(list_w[i])
        continue
    else:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    words=[]
    n = int(input())
    words=[input().rstrip() for _ in range(n)]
    print(words)

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

    endstring=""
    for word in words:
        if len(endstring)==0:
            endstring=word[-1]
        else:
            if endstring==word[0]:
                endstring=word[-1]
            else:
                print("No")
                exit()
    print("Yes")


if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
used = list(input() for x in range(n))
ans = "Yes"
for i in range(n): 
  if used.count(used[i]) == 2:
    ans = "No"
    break
  if used[i][-1] != used[i][0]:
    ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
import os
import sys
from collections import defaultdict, Counter, deque
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


def main():
    n = int(input())
    vectoer = []
    flag = True
    for i in range(n):
        s = input()
        vectoer.append(s)

    if len(vectoer) != len(set(vectoer)):
        flag = False

    print(n)
    for i in range(n-1):
        if vectoer[i][-1] !=  vectoer[i+1][0]:
            flag = False
            break

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

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

ok = True
t = input()
p = t[-1]
for i in range(n-1):
  t = input()
  if t in s:
    ok = False
  s.add(t)
  if t[0] != p:
    ok = False
  p = t[-1]
  
print('Yes' if ok else 'No')

Submission status: Wrong Answer

Solution code:
from collections import *
n=int(input())
l=[]
for i in range(n):
    l.append(input())
f=0
c=Counter(l)
for i in c.values():
    if(i>1):
        f=1
        break
if(f==1):
    print("No")
else:
    d=0
    for i in range(1,n):
        if(l[i-1][-1]!=l[i][0]):
            d=1
            break
    if(f==1):
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
e=''
s=''
S=[input() for  _ in range(n)]
for w in S:
    if e!=s:
        print('No')
        exit()
    s=w[0]
    e=w[-1]
if S==set(S):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

words.append(w)

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

Submission status: Wrong Answer

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

words.append(w)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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):
    print(flag)
    if w[i][-1]!=w[i+1][0]:
        flag=False

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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[0] != b[-1]:
			print('No')
			sys.exit()
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

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[0] != b[-1]:
			print('No')
			sys.exit()
		else:
			print('Yes')
else:
	print('No')

Submission status: Wrong Answer

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): 
		if W[i][0] != W[i+1][-1]:
			print('No')
			sys.exit()
		else:
			print('Yes')
else:
	print('No')

Submission status: Wrong Answer

Solution code:
import sys

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

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

Submission status: Wrong Answer

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

cnt = 0
if len(set(W)) == len(W):
	for i in range(N-1): 
		if W[i][0] == W[i+1][-1]:
			cnt += 1
		else:
			cnt = cnt
else:
	print('No')

if cnt == N-1:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

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

cnt = 0
for i in range(N-1):
	first = W[i]
	next = W[i+1]
	if first[-1] == next[0]:
		cnt += 1
	else:
		cnt = cnt

if cnt == N-1:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

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

for i in range(N):
    Ws.append(W[i])
    for j in range(1,N+1):
        if W[i][-1] == W[j][0]:
            break
        else:
            ans = 'No'
            break
        
#print(Ws)

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

Submission status: Wrong Answer

Solution code:
def main():
    has_said = set()
    n = int(input())
    last = ""
    for i in range(n):
        w = input()
        if i > 1 and (w[0] != last or w in has_said):
            print("No")
            break
        last = w[-1]
        has_said.add(w)
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(n):
    w = input()
    l.append(w)
for k in range(n):
    if  l[k-1][-1] == l[k][0]:
        for j in range(i):
            if l[k] == l[j]:
                flag = 0
                break
            else:
                flag = 1
    else:
        flag = 0
if(flag == 1):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
H=input()
word=[]
for i in range(N-1):
  S=input()
  if S in word:
    print('No')
    exit()
  else:
    if H[-1]==S[0]:
      H=S
      word.append(H)
    else:
      print('No')
      exit()
print('Yes')

Submission status: Wrong Answer

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

l = []

for i in range(N):
  if i != 0:
    if W[i-1] == W[i]:
      print('No')
      break
  
  if W[i] in l:
    print('No')
    break
    
  l.append(W[i])
else:
  print('Yes')

Submission status: Wrong Answer

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

Word = [W[0]]
for i in range(2,n):
    s = W[i-1]
    t = W[i]
    
    if(s[-1] != t[0] or t in Word): 
        flg = 0
        break
    Word.append(t)
    
if (flg): print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
dic = dict()
for i in range(N):
    S = input()
    if S in dic:
        dic[S] += 1
    else:
        dic[S] = 1
    Start  = S[0]
    if i != 0:
        if Start != End or dic[S] > 1:
            print("No")
            exit
    End = S[len(S)-1]
print("Yes")

Submission status: Wrong Answer

Solution code:
N, *W = open(0).read().split()

is_ok = True

if len(W) != len(set(W)):
    is_ok = False
else:
    for i, w in enumerate(W):
        if i > 1:
            if before_w != w[0]:
                is_ok = False
                break
        
        before_w = w[-1]
    
if is_ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())

lis = []
ans = "Yes"
for i in range(N):
    W = input()
    lis.append(W)
    if (W in lis == False) or (W[0] == lis[i-1][-1]):
        pass
    else:
        ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=0
for i in range(n-1):
  keep=s[-1]
  s=input()
  if keep != s[0]:
    ans=1
  else:
    continue
print(["Yes","No"][ans])

Submission status: Wrong Answer

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

WS = list(set(W))
cnt = 0

if len(WS) != len(W):
  cnt += 1
else:
  for i in range(N-1):
      if len(W[i])!=1 and W[i][-1] != W[i+1][0]:
          cnt += 1

print('No' if cnt >0 else 'Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if cnt == n and len(set(w)) == n:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
word_list = []
flag = True
for i in range(n):
    word = input()
    if word_list == []:
        word_list.append(word)
    else:
        if word_list[-1][-1] == word[0]:
            word_list.append(word)
        else:
            flag = False
            break
            
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [input()]
    for i in range(1, N):
        W = input()
        if A[-1][-1] == W[0]:
            for j in range(i-1):
                if A[j] == W:
                    print("No:重複")
                    return
            A.append(W)
        else:
            print(A, "No:違う")
            return
    print("Yes")

main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [input()]
    for i in range(1, N):
        W = input()
        if A[-1][-1] == W[0]:
            for j in range(i-1):
                if A[j] == W:
                    print("No")
                    return
                else:
                    A.append(W)
        else:
            print("No")
            return
    print("Yes")

main()

Submission status: Wrong Answer

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


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

for t in range (1,N):
    if W[t-1][-1]==W[t][0]:
      ss=True
    else:
      ss=False 
     
      

     
if ss==False:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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



for t in range (N-1):
    if W[t-1][-1]==W[t][0]:
      ss=True
    else:
      ss=False 
     
      

if len(W)!=len(set(W)):   
  ss=False
     
if ss==False:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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



for t in range (N-1):
    if W[t-1][-1]==W[t][0]:
      ss=True
    else:
      ss=False 
     
      
W=dict.fromkeys(W)
if len(W)!=N:   
  ss=False
     
if ss==False:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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



for t in range (N):
    if W[t-1][-1]==W[t][0]:
      ss=True
    else:
      ss=False 
      
W=dict.fromkeys(W)
if len(W)!=N:   
  ss=False
     
if ss==False:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
wordlist = []
for i in range(n):
    word = str(input())
    if word in wordlist:
        print('No')
        exit()
    if wordlist and wordlist[-1][-1] == word[-1]:
        print('No')
        exit()
    wordlist.append(word)
print('Yes')

Submission status: Wrong Answer

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


for t in range (N):
    if W[t-1][-1]==W[t][0]:
      ss=True
    else:
      ss=False 
if len(W)!=N:   
  ss=False
     
if ss==False:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

n = readInt()
d = defaultdict(int)
p="0"
for i in range(n):
	x = input()
	if p[-1]!=x[0]:
		print("No")
		exit()
	d[x]+=1
	p = x

for i in d:
	if d[i]>1:
		print("No")
		exit()

print("Yes")

Submission status: Wrong Answer

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

frag='Yes'
for i in range(n):
  if a.count(a[i])!=1:
    frag='No'
    break
for i in range(n-1):
  if a[i][-1]!=a[i+1][0]:
    frag='No'
    break
    
print(frag)

Submission status: Wrong Answer

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

frag='Yes'
for i in range(n):
  if a.count(a[i])>1:
    frag='No'
    break
for i in range(n-1):
  if a[i][-1]!=a[i+1][0]:
    frag='No'
    break
    
print(frag)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for w in range(len(Ws)):
    if Ws.count(w)>=2:
        print('No')
        exit()

for x in range (1,len(Ws)):
    if Ws[x][0] != Ws[x-1][-1]:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

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

for w in range(len(Ws)):
    if Ws.count(w)>=2:
        print('No')
        exit()

for x in range (1,N):
    if Ws[x][0] != Ws[x-1][-1]:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

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

for w in range(len(Ws)):
    if Ws.count(w)>1:
        print('No')
        exit()

for x in range (1,N):
    if Ws[x][0] != Ws[x-1][-1]:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
ls = []
w = []
K = 0
for i in range(N):
  ls.append(str(input()))
for j in range(0,N-1):
  if ls[j][(len(ls[j])-1):] and ls[j+1][(len(ls[j+1])-1):]:
    if ls[j] in w:
      print("No")
      K += 1
      break
    else:
      w.append(ls[j-1])
  else:
    print("No")
    K += 1
    break
if K == 0:
  print("Yes")

Submission status: Wrong Answer

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

s = W[0]

for i in range(N-1):
    k = input()
    if s[-1]==k[0] and k not in W:
        W.append(k)
        s = W[-1]
    else:
        a = 'No'
        
        break

print(a)

Submission status: Wrong Answer

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
print(out)

Submission status: Wrong Answer

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[-1]:
			print('No')
			return
		cnt.append(w)
	print('Yes')
resolve()

Submission status: Wrong Answer

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[0][-1] != w[-1]:
			print('No')
			return
		cnt.append(w)
	print('Yes')
resolve()

Submission status: Wrong Answer

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[0][-1] != w[-1]:
			print('No')
			return
	print('Yes')
resolve()

Submission status: Wrong Answer

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

w =[]

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

Submission status: Wrong Answer

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

w =[]

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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)
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
ll = [input() for _ in range(n)]
check = 0
for i in range(len(ll)-2):
    if ll[i][len(ll[i])-1] != ll[i+1][0]:
        check = 1
    if ll[i] in ll[i+1:]:
        check = 1


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

Submission status: Wrong Answer

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("Yes")

Submission status: Wrong Answer

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



www = "YYY"
for i in range(N-2):

    if S[i][-1] != S[i+1][0]:
        www = "fuck"


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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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]=temp
else:
  print("Yes")

Submission status: Wrong Answer

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]
else:
  print("Yes")

Submission status: Wrong Answer

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[len(templ)-1]:
    print("No")
    break
else:
  print("Yes")

Submission status: Wrong Answer

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[-1] != W[-1][-1]:
        print("No")
        sys.exit()
    W.append(w)

print("Yes")

Submission status: Wrong Answer

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

Solution code:
n = int(input())
words = []
last = ''
ans = 'Yes'
for i in range(n):
  inp = input()
  if inp in words or last != inp[-1]:
    ans = 'No'
    break
  words.append(inp)
  last = inp[-1]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,*w=open(0);print("YNeos"[len(w)>len(set(w))or all(w[x][-1]!=w[x+1][0]for x in range(int(n)-1))::2])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

ans = {}
for s in S:
    if s[0] in ans:
        ans[s[0]] += 1
    else:
        ans[s[0]] = 1

    if s[-1] in ans:
        ans[s[-1]] -= 1
    else:
        ans[s[-1]] = -1

if sum(ans.values()) == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

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