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())
string =[input() for i in range(n)]

j = 0
k = 1
finish = string[j][-1:]
start = string[k][0:1]

if len(string) == len(set(string)):
    while k <= n:
        if finish == start:
            j += 1
            k += 1
            if k == n:
                print("Yes")
        else:
            print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())

words=[input() for i in range(N)]
a = len(words)
b = len(set(words))

for i in range(N-1):
    c=words[i]
    d=words[i+1]
    e=c[0]
    f=d[-1]
    g=0
    if e != f:
        g=g+1
    break

if a != b:
    print("No")
elif g!=0:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

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

#if W.most_common()[0][1] == 1:
def is_unique2(seq):
    seen = []
    unique_list = [x for x in seq if x not in seen and not seen.append(x)]
    return len(seq) == len(unique_list)
c=0

if is_unique2(W)==True:
    for i in range(N-1):
        a = W[i]
        b = W[i+1]
#        print(a[len(a)-1])
#        print(b[0])
        if a[len(a)-1] == b[0]:
            c+=1
    if c == N-1:
        print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

words=[input() for i in range(N)]
a = len(words)
b = len(set(words))

for i in range(N):
    c=words[i]
    d=words[i+1]
    e=c[0]
    f=d[-1]
    g=0
    if e != f:
        g=g+1
    break

if a != b:
    print("No")
elif g!=0:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())

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

tmp=set(words)
#print(tmp)
c=1
if len(words)!=len(tmp):
    c=0
else:
    for i in range(N):
        print(words)
        if i==0:
            continue
        elif words[i][0]!=words[i-1][-1]:
            c=0
            break


#print(c)
if c:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
word_num = int(input())

word_list=[]
for i in range(word_num):
  word_list.append(str(input()))

# print(word_list)
temp = 0
for item in word_list:
  initial_word = item[0]
  last_word = item[-1]
  if(temp != initial_word and temp != 0):
      print("No")
      exit()
  temp = last_word
  # print("Ok")
print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

strList = [""] * N
strList[0] =input()
ans = "Yes"

for count in range(1,N):
    string = input()
    for s in strList:
        if s == string :
            ans = "No"
            break
        else:
            before = strList[count -1]
            car = before[len(before) -1: len(before)] 
            if car != string[:1]:
                ans = "No"
                break
    if ans == "No":
        break
    strList.append(string)

print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    already = set()
    prev = '-'
    for _ in range(n):
        word = input()
        if word in already:
            return False
        if prev[-1] != word[0]:
            return False
        already.add(word)
        prev = word
    return True


print('Yes' if solve() else 'No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

strList = [""] * N
strList[0] =input()
ans = "Yes"

for count in range(1,N):
    string = input()
    for s in strList:
        if s == string :
            ans = "No"
            break
        else:
            before = strList[count -1]
            car = before[len(before) -1: len(before)] 
            if car == string[0:1]:
                ans = "No"
                break
    if ans == "No":
        break
    strList.append(string)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

word = input()
known_words = [word]
for i in range(n-2):
    word = input()
    if word in known_words:
        print('No')
        exit()
    if word[0] != known_words[-1][-1]:
        print('No')
        exit()
    known_words.append(word)
print('Yes')

Submission status: Wrong Answer

Solution code:
n=int(input())
list=[]
word=input()
list.append(word)
key=word[-1]
flag=True
for i in range(1,n):
    word=input()
    if key==word[0] and (word not in list):
        list.append(word)
        key=word[-1]
    else:
        print("No")
        flag=False
if flag:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import re
target = re.compile(r'^[a-z]+$')
n=int(input())

a=[]
flag=True

for i in range(n):
  a.append(input())
  if not re.match(target,a[i]):
    flag=False
    break

#print (a[0][-1])
if flag:
  for i in range(n-1):
    if a[i][-1]==a[i+1][0]:
      flag=True

if flag:
  if len(set(a))<len(a):
    flag=False
#for i in range(n):
#  if a.count(a[i])>=2:
#    flag=False
#    break
    
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
a = int(input())
wordli = dict()
go = True
for i in range(a):
	word = input()
	if i == 0:
		wordli[word] = 1
	else:
		if word not in wordli:
			wordli[word] = 1
		else:
			print ('No')
			go = False
			break

if go == True:
	print ('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
s2=list(input())
k = 0
w = []
r = ''
for i in range(len(s2)):
    r += s2[i]
w.append(r)
for i in range(1,n):
    s=list(input())
    if s[0]!=s2[len(s2)-1]:
        k = 2
    r = ''
    for j in range(len(s)):
        r += s[j]
    #print(w,r,w.count(r))
    if w.count(r) != 0:
        k = 1
    w.append(r)
    s2 = s
if k == 1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N=int(input())

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

tmp=set(words)
print(tmp)
c=1
if len(words)!=len(tmp):
    c=0
else:
    for i in range(N):
        print(words)
        if i==0:
            continue
        elif words[i][0]!=words[i-1][-1]:
            c=0
            break


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

Submission status: Wrong Answer

Solution code:
x = int(input())

ANS = "Yes"
s = []
def se(s):
	return 
for i in range(x):
	s.append(input())

print(s)
for i in range(x-1):
	if s[i+1][0] != s[i][-1]:
		print(s[i][-1],s[i][0],s[i+1][-1])
		ANS = "No"
		break
if len(s) == len(set(s)):
	print(ANS)
else:
	print("No")

Submission status: Wrong Answer

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

correct = True
for i in range(1, len(w)):
    if w[i] in w[i + 1:]:
        correct = False
        break
    if i > 0 and w[i][0] != w[i - 1][-1]:
        correct = False
        break

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

Submission status: Wrong Answer

Solution code:
word= input()
wordlist = [raw_input() for i in range(word)]
counts=0
for i in range(word):
    if i>0:
        if wordlist[i-1][-1]==wordlist[i][0]:
            for words in wordlist:
                if words==wordlist[i]:
                    counts=counts+1
            counts=counts-1
        else:
            counts=counts+1
if counts==0:
    print"ok"
else:
    print"No"

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=[]
for i in range(n):
  a.append(list(map(str,input())))
  
for j in range(1,n):
  if a[j][0]!=a[j-1][-1]:
    print("No")
    sys.exit()
  for l in range(j):
    if a[l]==a[j]:
      print("No")
      sys.exit()
    elif j==n-1:
      print("Yes")
      sys.exit()
  
print("Yes")

Submission status: Wrong Answer

Solution code:

n=int(input())
list=[]
word=input()
list.append(word)
key=word[-1]
for i in range(1,n):
    word=input()
    if key==word[0] and (word not in list):
        list.append(word)
        key=word[-1]
    else:
        print("No")
print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

strList = [""] * N
strList[0] =input()
ans = "Yes"

for count in range(1,N):
    string = input()
    for s in strList:
        if s == string :
            ans = "No"
            break
        else:
            before = strList[count -1]
            if before[len(before) -1: 1] == string[0:1]:
                ans = "No"
                break
    if ans == "No":
        break
    strList.append(string)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
count = 0
listA=[]
while (count <= N-1):
    try:
        listA.append(str(input()))
        count+=1
    except:
        break;
print(set(listA))
print(listA)
if(len(listA) != len(set(listA))):
    print("No")
else:
    for i in range(N-1):
        if(listA[i][-1]!=listA[i+1][0]):
            print("No")
            break
        if(i==N-2):
            print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
flag = True
s = []
words = []
w1 = input()
words.append(w1)
e = w1[-1]
print(e)
for i in range(n-1):
    wi = input()
    if e != wi[0]:
        flag = False
    for w in words:
        if w == wi:
            flag = False
    words.append(wi)
    e = wi[-1]
    print(e)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

strList = [""] * N
strList[0] =input()
ans = "Yes"

for count in range(1,N):
    string = input()
    for s in strList:
        if s == string :
            ans = "No"
            break
        else:
            before = strList[count -1]
            if before[len(before) -1: 1] == string[1:1]:
                ans = "No"
                break
    if ans == "No":
        break
    strList.append(string)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

flag = True
chr = 'A'
table = []
for i in range(n):
    line = input()
    if chr == line[0]:
        print('No')
        flag = False
        break

    if line in table:
        print('No')
        flag = False
        break
    table.append(line)
    chr = line[-1]

if flag:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=[]
for i in range(n):
  a.append(list(map(str,input())))
  
for j in range(1,n):
  if a[j][0]!=a[j-1][-1]:
    print("No")
    sys.exit()
  for l in range(j-1):
    if a[l]==a[j]:
      print("No")
      sys.exit()
    elif j==n-1:
      print("Yes")
      sys.exit()
  
print("Yes")

Submission status: Wrong Answer

Solution code:
num_word = int(input())
word_list = []
flag = True

for i in range(num_word):
    word_list.append(input())

for j in range(num_word - 1):
    word1 = word_list[j]
    word2 = word_list[j + 1]
    for k in range(j):
        if word1 == word_list[k]:
            flag = False
            break
    if word1 == word2:
        flag = False
    if word1[len(word1) - 1] != word2[0]:
        flag = False
        break

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

Submission status: Wrong Answer

Solution code:
n = int(input())
flag = True
s = []
w1 = input()
e = w1[-1]
print(e)
for i in range(n-1):
    wi = input()
    if e != wi[0]:
        flag = False
    e = wi[-1]
    print(e)

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

Submission status: Wrong Answer

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

def is_unique(seq):
    return len(seq) == len(set(seq))

if is_unique(t) == False:
  print('No')

count = 0       

while count < N-1:
  if t[count][-1] != t[count+1][0]:
      print('No')
      break
  else:
    count += 1
print('Yes')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

strList = [""] * N
strList[0] =input()
ans = "Yes"

for count in range(1,N):
    string = input()
    for s in strList:
        if s == string :
            ans = "No"
            break
        else:
            before = strList[count -1]
            if before[len(before) -1: 1] != string[1:1]:
                ans = "No"
                break
    if ans == "No":
        break
    strList.append(string)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=[]
for i in range(n):
  a.append(list(map(str,input())))
  
for j in range(1,n):
  if a[j][0]!=a[j-1][-1]:
    print("No")
    break
  elif j==n-1:
    print("Yes")
    break
  for l in range(j-1):
    if a[l]==a[j]:
      print("No")
      sys.exit()
    elif j==n-1 and l==j-2:
      print("Yes")
      sys.exit()

Submission status: Wrong Answer

Solution code:
num_word = int(input())
word_list = []
flag = True

for i in range(num_word):
    word_list.append(input())

for j in range(num_word - 1):
    word1 = word_list[j]
    word2 = word_list[j + 1]
    for k in range(j):
        if word1 == word_list[k]:
            flag = False
            break
    if word1[len(word1) - 1] != word2[0]:
        flag = False
        break

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

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
l=[]
for x in range(n):
	l.append(str(input()))
	if x>0:
		if not(l[x-1][-1] == l[x][0]) or (l[:x] in l):
			print("No")
			sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())

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

check=1

for i in range(2,N):
    if W[i-1][-1] != W[i][0]:
        check=0

    




W.sort()



for i in range(2,N):
    if W[i]==W[i-1]:
        check=0
        print(i)






if check==1:
    print("Yes")

else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

n=int(input())
list=[]
word=input()
list+=word
key=word[-1]
for i in range(1,n):
    word=input()
    if key==word[0] and (word not in list):
        list+=word
        key=word[-1]
    else:
        print("No")
print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())

a=[]
flag=False

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

#print (a[0][-1])

for i in range(n-1):
  if a[i][-1]==a[i+1][0]:
    flag=True

if len(set(a))<len(a):
  flag=False
#for i in range(n):
#  if a.count(a[i])>=2:
#    flag=False
#    break
    
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
index = 0
list1 = []
listForWord=[]
lists = []
flag =0
while index <n:
    word = input()
    list1.append(list(word))
    if index!= 0:
        length = len(lists[index-1])
        if lists[index-1][length-1] == list1[index][0]:
            if word in listForWord == False:
                pass
            else:
                frag =1
        else:
            frag =1
    lists.append(list1[index])
    listForWord.append(word)
    index+=1
    if index==n and flag ==0:
        print("Yes")
    elif index ==n and flag ==1:
        print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
s2=list(input())
k = 0
w = []
r = ''
for i in range(len(s2)-1):
    r += s2[i]
w.append(r)
for i in range(1,n):
    s=list(input())
    if s[0]!=s2[len(s2)-1]:
        k = 1
    r = ''
    for j in range(len(s)-1):
        r += s[j]
    if w.count(r) != 0:
        k = 1
    w.append(r)
    s2 = s
if k == 1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N=int(input())
count = 0
listA=[]
while (count <= N-1):
    try:
        listA.append(str(input()))
        count+=1
    except:
        break;
if(listA != set(listA)):
    print("No")
else:
    for i in range(N-1):
        if(listA[i][-1]!=listA[i+1][0]):
            print("No")
            break
        if(i==N-2):
            print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())

shiritori = []
tmp = 0
for i in range(n-1):
    shiritori.append(input())
    if i > 0:
        if not shiritori[i-1][-1] == shiritori[i][0]:
            tmp += 1
        if not tmp > 0:
            for j in range(i):
                if shiritori[i] == shiritori[j]:
                    tmp += 1
                    break;
if(tmp > 0):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

correct = True
end = w[0][-1]
for i in range(1, len(w)):
    word = w[i]
    if word in w[i + 1:]:
        correct = False
        break
    start = word[0]
    if start != end:
        correct = False
        break
    end = word[-1]

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

Submission status: Wrong Answer

Solution code:
N=int(input())
count = 0
listA=[]
while (count <= N-1):
    try:
        listA.append(str(input()))
        count+=1
    except:
        break;
print(set(listA))
print(listA)
if(listA != set(listA)):
    print("No")
else:
    for i in range(N-1):
        if(listA[i][-1]!=listA[i+1][0]):
            print("No")
            break
        if(i==N-2):
            print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
k = input()
a = []
for i in range(N-1):
    a.append(input())
lis = []
for words in a:
  if words in lis:
    print('No')
    sys.exit()
  elif k[-1] != words[0]:
    print('No')
    sys.exit()
  else:
    lis.append(words)
    k = words
print('Yes')

Submission status: Wrong Answer

Solution code:
num_word = int(input())
word_list = []
flag = True

for i in range(num_word):
    word_list.append(input())

for j in range(num_word - 1):
    word1 = word_list[j]
    word2 = word_list[j + 1]
    if word1[len(word1) - 1] != word2[0]:
        flag = False
        break

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

Submission status: Wrong Answer

Solution code:
#coding: utf-8

n = int(raw_input())

s = []

w = raw_input()
s.append(w)

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

Submission status: Wrong Answer

Solution code:

n=int(input())
list=[]
word=input()
list+=word
key=word[-1]
for i in range(1,n):
    word=input()
    if key==word[0] and word not in list:
        list+=word
        key=word[-1]
    else:
        print("No")
print("Yes")

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    W = []
    for n in range(N):
        W.append(input())
    for i, w in enumerate(W):
        for wn in W[i+1:]:
            if w == wn:
                print('No')
                return 
        prev_w = w
        if i==0:
            continue
        else:
            if prev_w[-1] != w[0]:
                print('No')
                return
    print('Yes')
    return

main()

Submission status: Wrong Answer

Solution code:

n=int(input())
list=[]
word=input()
list+=word
key=word[-1]
for i in range(1,n):
    word=input()
    if key==word[0] and word in list:
        list+=word
        key=word[-1]
    else:
        print("No")
print("Yes")

Submission status: Wrong Answer

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

used_words = [w[0]]

def check_shiritori(b_word, a_word):
    if b_word[-1] == a_word[0]:
        return True
    else:
        return False

rule_flag = True
for i in range(1, n):
    if w[i] in used_words:
        rule_flag = False        
    if check_shiritori(w[i-1], w[i]):
        used_words.append(w[i])

if rule_flag is True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
flag = False
dic = []

word = input()
dic.append(word)

for i in range(N-1):
    word = input()
    if(word not in dic and word[0] == dic[-1][-1]):
        dic.append(word)
    else:
        flag = True
        break
if(flag == True):
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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

for i in range(n):
    s = input()
    if s in w:
        flag = 0
        break
    else:
        w.append(s)
        
if flag != 0:
    for i in range(1, n-1):
        if w[i][-1] != w[i+1][0]:
            flag = 0
            break

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

Submission status: Wrong Answer

Solution code:
N = int(input())
counter = 0
qq = 0
L = []
for i in range(N) :
    if i == 0 :
        w = input()
        L.append(w)
        q = w[-1]
    if i != 0 :
        w = input()
        if w in L :
            qq += 1
        p = w[0]
        if p == q :
            q = w[-1]
            counter += 1

            
            
if counter == N-1 and qq != 0 :
    print("Yes")
else :
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())

a=[]
flag=False

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

#print (a[0][-1])

for i in range(n-1):
  if a[i][-1]==a[i+1][0]:
    flag=True

for i in range(n):
  if a.count(a[i])>=2:
    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):
    X = input()
    W.append(X)
    if i >= 1:
        if W[i-1][len(W[i-1])-1] != W[i][0]:
            print("No1")
            exit()
    for j in range(i):
        if W[i] == W[j]:
            print("No2")
            exit()
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
words = list()
isTrue = True
for i in range(n):
    word = input()
    if i > 0:
        for w in words:
            if words == w:
                isTrue = False
                break
        if word[0] != words[-1][-1]:
            isTrue = False
    if isTrue:
        words.append(word)
    else:
        break
if isTrue:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

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

next_s = S[0][0]
for s in S:
    if next_s != s[0]:
        print("No")
        break
    
    next_s = s[-1]
else:
    print("Yes")

Submission status: Wrong Answer

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

bb = []
if len(set(aa)) != len(aa):
    print('No')
else:
    for i in range(n-1):
        if aa[i][-1] == aa[i+1][0]:
            bb.append(True)
        else:
            bb.append(False)
    if all(bb):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
word=input()
key=word[-1]
for i in range(1,n):
    word=input()
    if key==word[0]:
        key=word[-1]
    else:
        print("No")
print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())						# 5

ans="Yes"
W=[]

w = input()
W.append(w)
for i in range(1,N-1):
	w = input()
	if w in W:
		ans="No"
		break
	W.append(w)
	if W[i-1][-1]!=W[i][0]:
		ans="No"
		break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(raw_input().replace("\n", ""))

w_list = []

flag = True
for i in xrange(N):
    w_i = raw_input().replace("\n", "")
    if i >= 2:
        w_last = w_list[i-1]
        if w_last[-1] != w_i[0] and flag == True:
            flag = False
        if w_i in w_list and flag == True:
            flag = False
    w_list.append(w_i)

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

Submission status: Wrong Answer

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

if len(W) == len(set(W)):
    for i in range(N):
        if W[i-1][-1] == W[i][0]:
            result = "Yes"
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [input() for i in range(n)]
b = []
b.append(a[0])
res = True
for i in range(1,n):
    if a[i-1][-1] != a[i][0]:
        res = False
        break
    if a[i] in b:
        res = False
        break
    b.append(a[i])

if res:
    print('Yes')
else:
    print('NO')

Submission status: Wrong Answer

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

ans = 0

if len(set(w_list)) != N:
    print('No')
    exit()
for i in range(1,N):
    print(i)
    if w_list[i-1][-1] == w_list[i][0]:
        ans += 1
if ans == N - 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())

last = None
seen = set()
for _ in range(n):
  w = input()
  if w in seen or (last and last[-1] != w):
    print("No")
    break
  seen.add(w)
  last = w
else:
  print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
wdlist=list()
N=int(input())
for i in range(N):
	wdlist.append(input())

winflag=True

for i in range(N-1):
	if(wdlist[i][-1]!=wdlist[i+1][0]):
		winflag=False
		break
	for j in range(i):
		if(wdlist[j]==wdlist[i]):
			winflag=False
			break
if(winflag==True):
	print ("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
f = 0

for i in range(n):
    t = input()
    if t in s:
        f = 1
    elif i != 0 and s[i-1][-1] != t[0]:
        print(s[i-1], s[i-1][-1], t[0])
        f = 1
    s.append(t)
    
if f == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())

last = None
seen = set()
for _ in range(n):
  w = input()
  if w in seen or (last and last[-1] != w):
    print("No")
    break
  seen.add(w)
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[]
for i in range(n):
    st=input()
    if st in s:
        print('No')
        exit()
    s.append(st)

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

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = 'Yes'

w = []

for i in range(n):
	a = input()
	if a in w:
		ans = 'No'
	else:
		w.append(a)
b = w[0]
if n == 2:
	if w[0][-1] != w[1][0]:
		ans = 'No'
else:
	for i in range(1,n-2):
		if b[-1] == w[i][0]:
			b = w[i]
		else:
			ans = 'No'
print(ans)

Submission status: Wrong Answer

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

if __name__ == "__main__":
    N = int(input())
    pre_w = input()
    words = [pre_w]
    for i in range(N-1):
        w = input()
        if w in words:
            print("No")
            exit()
        words.append(w)

        if pre_w[-1] == w[0]:
            continue
        else:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

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

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

next_s = ""
for s in S:
    if next_s == "":
        next_s = s[-1]
        continue
    
    if next_s != s[0]:
        print("No")
        break
    
    next_s = s[-1]
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
W = input()
L = []
L.append(W)
last = W[-1]
ans = 'Yes'
for _ in range(N-1):
    w = input()
    if w in L:
        ans = 'No'
    if last == w[0]:
        last = w[-1]
    else:
        ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
sirito_list = []
is_siritori = True
for _ in range(N):
  if not sirito_list:
    sirito_list.append(input().strip())
  else:
    tmp_word = input().strip()
    if tmp_word[0] != sirito_list[-1][-1] or tmp_word in sirito_list:
      print('No')
      is_siritori = False
      break
if is_siritori:
  print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import io

sys.stdin = io.StringIO(
    """3
abc
arc
agc"""
)

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()

ss = []
for i in range(n):
    ss.append(ns())

for i in range(n):
    for j in range(i):
        if ss[i] == ss[j]:
            print("No")
            sys.exit(0)

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

print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
rec = []
flag = True
t = input()
pre = t[-1]
for i in range(1, n):
    s = input()
    if s in rec:
        flag = False
    elif s[0] != pre:
        flag = False
    else:
        rec.append(s)
        pre = s[-1]

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

Submission status: Wrong Answer

Solution code:
already = {}
n = int(input())
last = ''
for i in range(n):
  s = input()
  if i != 0 and s[0] != last[-1]:
    print('No')
    break
  last = s
else:
  print('Yes')