Problem:


Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

In the first turn, a player announces any one word.

In the subsequent turns, a player announces a word that satisfies the following conditions:

That word is not announced before.

The first character of that word is the same as the last character of the last word announced.

In this game, he is practicing to announce as many words as possible in ten seconds.

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

Constraints

N is an integer satisfying 2 \leq N \leq 100.

W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

As hoge is announced multiple times, the rules of shiritori was not observed.

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No



Sample input:
4
hoge
english
hoge
enigma


Sample output:
No

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
n = int(raw_input())
s = []
for _ in xrange(n):
    s.append(raw_input())
 
ss = set()
last = None
ret = 'Yes'
for w in s:
    if w in ss:
        ret = 'No'
        break
    if last is None:
        ss.add(w)
        last = w
        continue
    if last[-1] != w[0]:
        ret = 'No'
        break
    ss.add(w)
    last = w
 
print ret
##17024717 | shenweiqiang's solution for [AtCoder-4252] [Problem B]

Submission status: Accepted

Solution code:
n = int(input())
words = ['']*n
for i in range(n):
    words[i] = input()
for i in range(len(words) - 1):
    if words.count(words[i]) > 1 or words[i][-1] != words[i+1][0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

W = []

W.append(input())

for n in range(N-1):
    w = input()

    if( w[0] == W[n][-1] and w not in W):
        W.append(w)
        continue

    else:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def abc112_b():
    n, limit_time = map(int, input().split())
    ans = 1001

    for _ in range(n):
        cost, time = map(int, input().split())

        if time <= limit_time and ans > cost:
            ans = cost

    return ans if ans != 1001 else "TLE"


def abc109_b():
    length = int(input())
    word_list = []

    for _ in range(length):
        word_list.append(input())

    for i in range(len(word_list) - 1):

        if word_list.count(word_list[i]) >= 2 or word_list[i][-1] != word_list[i+1][0]:
            return "No"

    return "Yes"


if __name__ == '__main__':
    print(abc109_b())

Submission status: Accepted

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

win = False
for j in range(1, N) :
    if words[j].startswith(words[j-1][-1]) and words[j] not in words[:j]:
       win = True
    else :
        win = False
        break

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

Submission status: Accepted

Solution code:
from collections import Counter

import sys

def main():
    n = int(input())
    values = []
    for i in range(n):
        values.append(str(input()))

    c = Counter(values)
    if any(c[i] > 1 for i in c):
        print('No')
        return
    
    for i in range(n - 1):
        if values[i][-1] != values[i + 1][0]:
            print('No')
            return 

    print('Yes')

    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
c=[]
d=0
for i in range(n):
	c.append(input())
for i in range(n-1):
	if c[i][-1]!=c[i+1][0]:
		print("No")
		exit()
for i in range(n):
	for q in range(n):
		if i!=q:
			if c[i]==c[q]:
				print("No")
				exit()

print("Yes")

Submission status: Accepted

Solution code:
import sys
N = int(input())
a = []
a.append(input())
for i in range(1, N):
    a.append(input())
    if a[i][0] != a[i - 1][-1]:
        print("No")
        sys.exit()
    for j in range(i):
        if a[j] == a[i]:
            print("No")
            sys.exit()
        else:
            None
print("Yes")

Submission status: Accepted

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

last_word = W[0]
word_dict[W[0]] = 1
for word in W[1:]:
    if last_word[-1] == word[0] and (not (word in word_dict)):
        last_word = word
        word_dict[word] = 1
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import copy
n = int(input())

word = [input() for _ in range(n)]
word2 = copy.deepcopy(word)
word2.append("koredeiinokasira...tukareta")
flag = 0

#文字が重複していないか
for index, q in enumerate(word):
    for index2, w in enumerate(word):
        
        
        if q == w:
            if index == index2:
                continue
            flag += 1
        
            

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


if flag != 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
word = input()
words = {word}
for i in range(n-1):
    word2 = input()
    if word[-1] == word2[0] and word2 not in words:
        words.add(word2)
        word = word2
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
flag = 1
for i in range(n):
  for j in range(n):
    if i == j:
      continue
    if w[i] == w[j]:
      flag = flag *0
      break
for i in range(n):
  if i == 0:
    continue
  if w[i-1][-1] == w[i][0]:
    flag = flag * 1
  else:
    flag = flag * 0
    
if flag == 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

for i in range(N):
    for j in range(1,N-i-1):
        if a[i] == a[N-j]:
                print("No")
                sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
wlist = [input() for i in range(N)]
wlist_counter = Counter(wlist)
ans = 1

if wlist_counter.most_common()[0][1] >= 2:
    ans = 0

for i in range(0,N-1):
    W_ed = wlist[i]
    W_st = wlist[i+1]
    if W_ed[-1] != W_st[0]:
        ans = 0
        break

if ans == 0:
    print("No")
elif ans == 1:
    print("Yes")

Submission status: Accepted

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

first_word = words[0][0]
last_word = ""
is_okay = True

tmp_words = list(set(words))
if (len(tmp_words) != len(words)) :
	is_okay = False

for s in words :
	if (first_word != s[0]) :
		is_okay = False
		break
	
	first_word = s[-1]


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

Submission status: Accepted

Solution code:
import sys

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

if len(set(W)) != N:
    print('No')
    sys.exit()

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

print('Yes')

Submission status: Accepted

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

#重複

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

Submission status: Accepted

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

for i in range(N):
    for j in range(1,N-i-1):
        if a[i] == a[N-j]:
                print("No")
                sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
import sys
c = int (input())
words = []
No=" "
for i in range (c) :
    words.append(input())
for x in range(len(words)-1):
    if words.count(words[x]) > 1 or words[x+1][0] != words[x][-1]:
        No="No"
        print (No)
        sys.exit() 


if No != "No":
     print ("Yes")

Submission status: Accepted

Solution code:
import sys
import string
input=sys.stdin.readline

n=int(input())
l=[list(input().rstrip()) for i in range(n)]
if len(set(map(tuple,l)))!=len(l):
        print('No')
else:
    for i in range(n-1):
        if l[i][-1]!=l[i+1][0]:
            print('No')
            break
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
n = int (input())
words = []
No=" "
for i in range (n) :
    words.append(input())
for x in range(len(words)-1):
    if words.count(words[x]) > 1 or words[x+1][0] != words[x][-1]:
        No="No"
        print (No)
        sys.exit() 
if No != "No":
     print ("Yes")

Submission status: Accepted

Solution code:
N = int(input())
a = list(input() for i in range(N)) #0～N-1まである
k = 0
for i in range(N-1): #0～N-2まである
  if a.count(a[i]) != 1:
    print('No')
    break
  elif (a[i+1][0:1]) != (a[i][-1:]): #1～N-1までやりたい　#0～N-2までやりたい
    print('No')
    break
  else:
    k = k + 1

if k == (N-1):
  print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
a = list(input() for i in range(N)) #0～N-1まである
k = 0
for i in range(N-1): #0～N-2まである
  if a.count(a[i]) != 1:
    print('No')
    break
  elif a[N-1] == a[i]:
    print('No')
    break
  elif (a[i+1][0:1]) != (a[i][-1:]): #1～N-1までやりたい　#0～N-2までやりたい
    print('No')
    break
  else:
    k = k + 1

if k == (N-1):
  print('Yes')

Submission status: Accepted

Solution code:
a=int(input())
b=[]
for i in range(a):
	b.append(input())
#print(b)
c=list(set(b))
#print(c)
if len(b)!=len(c):
	print("No")
else:
	hantei=True
	for i in range(a-1):
		if b[i][-1]==b[i+1][0]:
			continue
		else:
			hantei=False
			break
	if hantei:
		print("Yes")
	else:
		print("No")

Submission status: Accepted

Solution code:
lst = []
ans = True
for _ in range(int(input())):
    a = input()
    if len(lst) == 0:
        lst.append(a)
    else:
        x = lst[len(lst)-1]
        if x[len(x)-1] != a[0] or a in lst:
            ans = False
            break
        lst.append(a)
print("Yes" if ans is True else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#B問題
#しりとりが成立していたか確認する
#(同名禁止)

w=[]
N=int( input() )

for i in range (0,N):
    wi= input()
    w.append(wi)

#w[0]で一単語目
#w[0][1]で一単語目の二文字目を参照できる
comment="Yes"
for i in range (1,N):#二番目からスタート
    xyz=len(w[i-1])-1#一つ前のお尻の番号
    if(w[i][0]==w[i-1][xyz]):
        pass
    else:#前のお尻と先頭が一致しなければ
        #print("no")
        comment="No"
        break


#もうひとつの条件
#かぶり不可の確認
for i in range(0,N):#i最初から最後まで
    if(comment=="No"):break
    for u in range(i+1,N):#u 今の位置から後ろだけ
        if(w[i]==w[u]):#かぶりが存在した
            comment="No"
            break
print(comment)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    used = []
    for _ in range(N):
        W = input()
        if W in used:
            print(No)
            return

        if len(used) != 0 and used[-1][-1] != W[0]:
            print(No)
            return

        used.append(W)

    print(Yes)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def shiritori(n, ws):
    if len(ws) != len(set(ws)):
        return 'No'

    for i in range(1, len(ws)):
        if ws[i - 1][-1] != ws[i][0]:
            return 'No'
    return 'Yes'

n = int(input())
ws = []
for _ in range(n):
    ws += [input()]
print(shiritori(n, ws))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n=int(input())
wli=[]
w=input()
wli.append(w)

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

print("Yes")

Submission status: Accepted

Solution code:
import sys

N=int(input())
W_li=[]
W=input()
W_li.append(W)

for i in range(N-1):
    W=input()
    if W in W_li:
        print("No")
        sys.exit()
    elif W_li[i][-1:]!=W[0]:
        print("No")
        sys.exit()
    else:
        W_li.append(W)
        
print("Yes")

Submission status: Accepted

Solution code:
def abc109_b():
    n = int(input())
    words = [input() for _ in range(n)]
    for i in range(n-1):
        if words[i][-1] != words[i+1][0]:
            return "No"
    if len(set(words)) != len(words):
        return "No"
    return "Yes"


print(abc109_b())

Submission status: Accepted

Solution code:
n = int(input())
ans = 'Yes'
dic = []
iw = input()
dic.append(iw)
for i in range(1,n):
    p = i - 1
    w = input()
    if w in dic or dic[p][-1]!=w[0]:
        ans = 'No'
    dic.append(w)
print(ans)

Submission status: Accepted

Solution code:
#coding;utf-8
n=int(input())
data=[]
check=True
data.append(input())
for i in range(1,n):
  data.append(input())
  for j in range(i):
    if(data[i]==data[j]):
      check=False
  if(data[i-1][len(data[i-1])-1]!=data[i][0]):
    check=False
if(check==False):
  print("No")
else:
  print("Yes")

Submission status: Accepted

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

W = []
re = 'Yes'
last = ''
for i in range(N):
    W.append(input())
    if last != '' and last != W[i][0:1]:
        re = 'No'
    elif W.count(W[i]) >= 2:
        re = 'No'
    last = W[i][-1]
        
print(re)

Submission status: Accepted

Solution code:
import sys

n=int(input())
mydict={}
before="!"
for i in range(n):
    tmp=input()
    if(before=="!"):
        before=tmp[0]
    if(tmp in mydict or before!=tmp[0]):
        print("No")
        sys.exit()
    mydict[tmp]=i
    before=tmp[-1]

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
x=[]
x.append(input())
last_char=x[0][-1]
f_l_checker=True
for i in range(1,n):
    x.append(input())
    if f_l_checker:
        first_char=x[i][0]
        if first_char==last_char:
            f_l_checker=True
            last_char=x[i][-1]
        else:
            f_l_checker=False
            
set_x=set(x)
if len(set_x)==n and f_l_checker==True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
x=[]
f_l_checker=True
x.append(input())
for i in range(1,n):
    x.append(input())
    if f_l_checker:
        if x[i][0]==x[i-1][-1]:
            for j in range(i):
                if x[i]==x[j]:
                    f_l_checker=False
        else:
            f_l_checker=False
if f_l_checker:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
x=[]
x.append(input())
last_char=x[0][-1]
f_l_checker=True
 
for i in range(1,n):
    x.append(input())
    if f_l_checker:
        first_char=x[i][0]
        if first_char==last_char:
            f_l_checker=True
            last_char=x[i][-1]
        else:
            f_l_checker=False
            
set_x=set(x)
if len(set_x)==n and f_l_checker==True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
s=[]
f_l_checker=True
s.append(input())
for i in range(1,n):
    s.append(input())
    if f_l_checker:
        if s[i][0]==s[i-1][-1]:
            for j in range(i):
                if s[j]==s[i]:
                    f_l_checker=False
        else:
            f_l_checker=False
if f_l_checker:
    print("Yes")
else :
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
s=[]
fla=True
s.append(input())
for i in range(1,n):
    s.append(input())
    if fla :
        if s[i][0]==s[i-1][len(s[i-1])-1]:
            for j in range(i):
                if s[j]==s[i]:
                    fla=False
        else:
            fla=False
if fla:
    print("Yes")
else :
    print("No")

Submission status: Accepted

Solution code:
def a():
    n=int(input())
    w=list()
    for i in range(n):
        z=input()
        w.append(z)
    for i in range(1,n):
        if w[i][0]!=w[i-1][len(w[i-1])-1]:
            print("No")
            return 0
    w.sort()
    for i in range(n-1):
        if w[i]==w[i+1]:
            print("No")
            return 0
    print("Yes")
    return 0
a()

Submission status: Accepted

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

sw = sorted(w)
for i in range(1, len(sw)):
    if sw[i - 1] == sw[i]:
        print("No")
        sys.exit()
for i in range(1, len(w)):
    if w[i - 1][-1] != w[i][0]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys

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

sw = sorted(w)
for i in range(1, len(sw)):
  if sw[i - 1] == sw[i]:
    print("No")
    sys.exit()

for i in range(1, len(w)):
  if w[i - 1][-1] != w[i][0]:
    print("No")
    sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for i in range (n):
    s.append('a')
for i in range(n):
    s[i]= [j for j in input()]
flag=True
for i in range(n-1):
    k = len(s[i])
    if s[i][k-1]==s[i+1][0]:
        for j in range(n):
            if s[i]==s[j] and i!=j:
                flag=False
                break
    else:
        flag=False
        break
if flag :
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = []
flag = 1
for i in range(N):
    a.append(str(input()))
    if i != 0:
        for j in range(i):
            if a[i] == a[j]:
                flag =0


back = a[0][-1]
for i in range(1,N):
    front = a[i][0]
    if front != back:
        flag = 0
        break
    back = a[i][-1]

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

Submission status: Accepted

Solution code:
N=int(input())
W=[]
same=[]
counter=0
for i in range(N):
    W.append(input())

for i in range(len(W)):
    for x in range(i+1,len(W)):
        if W[i]==W[x]:
            same.append(W[i])
  
for i in range(len(W)-1):
    if len(same)!=0:
        counter=0
        break
    
    if W[i][-1]==W[i+1][0]:
        counter+=1
        
        
    if W[i][-1]!=W[i+1][0]:
        counter+=0
        
if counter==len(W)-1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())

chr = [str(input()) for i in range (n)]
#print(chr)

first = [chr[x][:1] for x in range(n)]
#print(first)

last = [chr[y][-1] for y in range(n)]
#print(last)

same = 1
for z in range (n-1):
  if last[z] == first[z+1]:
    same = 0
  else:
    same = 1
    break

dbl = 0
for i in range (n):
  for j in range (i+1, n):
    if chr[i] == chr[j]:
      dbl = 1
    else:
      continue

#print(same, dbl)
if same == 0 and dbl == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n = input()
last_word = raw_input()
arr = [last_word]
f = 0
for i in range(n-1):
    str = raw_input()
    if str in arr:
        f = 1
        break
    elif str[0] == last_word[-1]:
        last_word = str
        arr.append(str)
    else:
        f = 1
        break
if f == 0:
    print "Yes"
else:
    print "No"

Submission status: Accepted

Solution code:
n = input()
last_word = raw_input()
arr = [last_word]
f = 0
for i in range(n-1):
    str = raw_input()
    if str in arr:
        f = 1
        break
    elif str[0] == last_word[-1]:
        last_word = str
        arr.append(str)
    else:
        f = 1
        break
if f == 0:
    print "Yes"
else:
    print "No"

Submission status: Accepted

Solution code:
N = int(input().rstrip())
l = []
w = ""
for i in range(N):
  cur = input().rstrip()
  if (w != "" and w != cur[0]) or cur in l:
    print("No")
    exit()
  l.append(cur)
  w = cur[-1]
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
a = set()
b = W[0][0] 
OK = True
for w in W:
    if b[-1]!=w[0] or w in a:
        OK = False
    a.add(w)
    b = w
print('Yes' if OK else 'No')

Submission status: Accepted

Solution code:
N = int(input())
w = []
for i in range(N):
    w.append(input())
# [a1, a2, a3, ..., aN]
p = 0
for i in range(N):
  for j in range(i+1,N):
    if w[i] == w[j]:
      p = 1
      break
v = []
    
for i in range(N):
  v.append([])

for j in range(N):
  for s in list(w[j]):
    v[j].append(s)

for k in range(N):
  if k != 0:
    if v[k - 1][len(v[k - 1]) - 1] != v[k][0]:
      p = 1
      break

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

Submission status: Accepted

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


def check(l):
    for i in range(len(l)-1):
        if l[i][-1] != l[i+1][0]:
            return "No"
    for o in range(len(l)):
        if l[o] in l[:o] or o in l[o+1:]:
            return "No"
    return "Yes"


print(check(list_words))

Submission status: Accepted

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

for i in range(N-1):
    if w[i][len(w[i])-1]!=w[i+1][0]:
        r+=1
for v in w:
    if v not in c:
        c.append(v)
if len(c)==len(w):
    r+=0
else:
    r+=1
       
if r==0 :
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
c=int(input())
l=[]
b=''
f=False
for i in range(c):
	a=input()
	if l.count(a)>0 or (b!='' and a[0]!=b[-1]):
		f=True
	b=a
	l.append(a)
if f:
	print('No')
else:
	print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
l= []
x = 0
for elt in range(n):
    inp = input()
    l.append(inp)
for elt in range(len(l)):
    if l.count(l[elt]) > 1 :
        print("No")
        x+=1
        break

    else:
        if elt < len(l)-1:
            if l[elt][-1] != l[elt+1][0]:
                print("No")
                x += 1
                break
if x == 0:
    print("Yes")

Submission status: Accepted

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

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

print('Yes')

Submission status: Accepted

Solution code:
def get():
    n = int(input())

    g = []
    for _ in range(n):
        g.append(input())

    return g

def yesOrNo(g):
    c = 0
    
    for i in range(len(g)):
        for j in range(i+1, len(g), 1):
            if g[i] == g[j]:
                c += 1
                break
    
    for i in range(1, len(g), 1):
        if(g[i][0] != g[i-1][len(g[i-1])-1]):
            c += 1
            break

    return c
    

g = get()
r = yesOrNo(g)

if r != 0:
    print("No")

else:
    print("Yes")

Submission status: Accepted

Solution code:
num=int(input())
list1=[]
flag=0
j=0

for i in range(num):

    a=input()



    if a in list1:
        flag+=1
    list1.append(a)
    if j>0:
        if list1[i-1][len(list1[i-1])-1]==list1[i][0]:
           pass

        else:
          flag+=2

    j=1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import*
import sys
n = int(input())
listtt = []
string=input()
lastChar = string[-1]
listtt.append(string)
k=n-1
while(k) :
    k-=1
    string = input()
    if (string[0]!=lastChar):
       print("No")
       sys.exit()
    else :
       lastChar=string[-1]
       listtt.append(string)
for i in listtt :
    if listtt.count(i) > 1 :
        print ("No")
        sys.exit()
print ("Yes")

Submission status: Accepted

Solution code:
n=int(input())
used=[]
used.append(input())
chain=used[0][-1]
res="Yes"
for i in range(n-1):
    s=input()
    c=s[0]
    if s in used or chain!=c:
        res="No"
        break
    used.append(s)
    chain=s[-1]
    

print(res)

Submission status: Accepted

Solution code:
def Condition(W):
    for i in range(len(W)):
        for j in range(i,len(W)):
            if W[i]==W[j] and i!=j:
                print('No')
                return None
    for i in range(len(W)-1):
        k=len(W[i])-1
        if W[i][k]!=W[i+1][0]:
            print('No')
            return None
    print('Yes')    


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

Submission status: Accepted

Solution code:
n = int(input())

li = [input() for _ in range(n)]
set_li = set(li)
flag = 'Yes'

if len(li) == len(set_li):
    for i in range(n):
        li[i] = list(li[i])
    for i in range(n-1):
        if li[i][len(li[i])-1] != li[i+1][0]:
            flag = 'No'
            break
else:
    flag = 'No'

print(flag)

Submission status: Accepted

Solution code:
# abc109_b

from collections import Counter


def solve(words):
    if Counter(words).most_common()[0][1] > 1:  # repetition is present
        return "No"
    else:
        # initial letter first word not important
        # final letter final word not important
        if list(map(lambda x: x[0], words[1:])) == list(map(lambda x: x[-1], words[:-1])):
            return "Yes"
        else:
            return "No"


def solve2(words):
    for i in range(len(words) - 1):
        if words[i] in words[i + 1:]:
            return "No"
        else:
            if words[i][-1] != words[i + 1][0]:
                return "No"
    return "Yes"


if __name__ == "__main__":
    N = int(input(""))
    words = [input("") for i in range(N)]
    print(solve2(words))

Submission status: Accepted

Solution code:
# abc109_b

from collections import Counter


def solve(words):
    commons = Counter(words).most_common()
    if commons[0][1] > 1:
        return "No"
    else:
        # initial letter first word not important
        first_letters = list(map(lambda x: x[0], words[1:]))
        # final letter final word not important
        last_letters = list(map(lambda x: x[-1], words[:-1]))
        if first_letters == last_letters:
            return "Yes"
        else:
            return "No"


if __name__ == "__main__":
    N = int(input(""))
    words = [input("") for i in range(N)]
    print(solve(words))

Submission status: Accepted

Solution code:
import collections

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

lastchar=list(arr[0])[len(arr[0])-1]
count=1
for i in range(1,N):
    firstchar=list(arr[i])[0]
    if(lastchar==firstchar):
        lastchar=list(arr[i])[len(arr[i])-1]
        count+=1
    else:        
        break

flag=True

tocheck=list(collections.Counter(arr).values())

for item in tocheck:
    if(item>1):        
        flag=False        
        break

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

Submission status: Accepted

Solution code:
n=int(input())
s=[input()]
f=True
for i in range(1,n):
    d=input()
    if d in s or s[i-1][len(s[i-1])-1]!=d[0]: 
        f= False
    s.append (d)


if f :
    print ("Yes")

else:
    print ("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


cnt=0
for i in range (n-1):
    if word[i][len(word[i]) - 1] != word[i + 1][0]:
        cnt += 1
        print("No")
        break
    for j in range (i):
     if word[i+1]==word[j]:
        cnt+=1
        print ("No")
        break

if cnt==0:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
l= []
x = 0
for elt in range(n):
    inp = input()
    l.append(inp)
for elt in range(len(l)):
    if l.count(l[elt]) > 1 :
        print("No")
        x+=1
        break

    else:
        if elt < len(l)-1:
            if l[elt][-1] != l[elt+1][0]:
                print("No")
                x += 1
                break
if x == 0:
    print("Yes")

Submission status: Accepted

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

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

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

print ('Yes')

Submission status: Accepted

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