Problem:


Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

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

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

That word is not announced before.

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

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

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

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

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

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No



Sample input:
4
hoge
english
hoge
enigma


Sample output:
No

Submission status: Accepted

Solution code:
N = int(input())

words = []

flag = 0

for i in range(N):
    w = input()
#    print(words)
    words.append(w)
    if i == 0:
        continue
    if words[i-1][-1] != w[0]:
        flag = 1

sets = set(words)

if len(sets) != len(words):
    flag = 1

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

Submission status: Accepted

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

fun()

Submission status: Accepted

Solution code:
import sys

N=int(input())

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


#重複判定
if len(lst) != len(set(lst)):
    print("No")
    exit()


#しりとり判定
nbr=0
flag=0
before_word=""
now_word=""

for i in lst:
    
    if (before_word != ""):
        #前のワードと比較
        #一致しなかったらsys.exit
        if(before_word[-1] != i[0]):
            print("No")
            sys.exit()

    #before_wordを書き換え
    before_word = i

print("Yes")

Submission status: Accepted

Solution code:
import sys
def is_unique(seq):
    return len(seq) == len(set(seq))

## 最初に入力回数が与えられて、そのあとデータが入力される。といったパターン
N = int(input())
a = []
for i in range(N):
    a.append(input()) # ３度の入力に対して、1, 2, 3 と入力。
#print(a) # ['1', '2', '3']

if not(is_unique(a)):
	print("No")
	sys.exit()

last_char=""
counter=0
for item in a:
	if counter == 0:
		last_char = item[-1]
		counter = 1
	else:
		if(len(item) > 11):
			print("No")
			sys.exit()
		if not (item[0] == last_char):
			print("No")
			sys.exit()
		else:
			last_char = item[-1]
			
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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


ans = 1

if len(a) != len(set(a)):
    ans = 0

for i in range(0, N-1):
    if a[i][-1] != a[i+1][0]:
        ans = 0

if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

ans = 'Yes'
s = []
s.append(w[0])
for i in range(1,n):
    if w[i-1][-1] != w[i][0]:
        ans = 'No'
    if w[i] in s:
        ans = 'No'
    s.append(w[i])

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

w = []
count = 0

for i in range(n):
    w.append(input())
    if i >= 1:
        m = w[i - 1]
        l = m[-1]
        hantei = w[i].startswith(l)
        if hantei == False:
            count = 1
    a = 0
    for j in w:
        if w[i] == j:
            a += 1
        if a > 1:
            count = 1

if count == 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
n = int(input())
w=[]
for i in range(n):
    w.append(str(input()))

i=int(0)
z=str(w[0][:1])
x=int(0)
k=int(0)

while i < n:
    a=str(w[i][:1])
    if z != a:
        x=1
    z=str(w[i][-1:])
    k=int(0)
    while k < i:
        if w[i]==w[k]:
            x=1
        k +=1
    if x==1:
        break
    i+=1
    

if x==1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
def check_word(w,n):
    count = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                if w[i] == w[j]:
                    count += 1
            else:
                continue
    if count == 0:
        return True
    else:
        return False
    
def shiritori(w1,w2):
    if w1[len(w1)-1:len(w1)] == w2[0]:
        return True
    else:
        return False
    
n = int(input())
w = [input() for i in range(n)]
count = 0
if check_word(w,n):
    for i in range(n-1):
        if not shiritori(w[i],w[i+1]):
            print('No')
            break
        else:
            count += 1
else:
    print('No')

if count == (n-1):
    print('Yes')

Submission status: Accepted

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

ha=0
for i in range(n-1):
    if W[i][len(W[i])-1]!=W[i+1][0] :
        ha=1
for i in range(n):
    for j in range(i+1,n):
        if W[i]==W[j] :
            ha=1

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

Submission status: Accepted

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

if len(words) == len(set(words)) and all([words[i][-1] == words[i+1][0] for i in range(len(words) - 1)]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = []
flg = 1
for i in range(N):
    a.append(input())
for i in range(N-1):
    if(a[i][-1] != a[i+1][0]):
        flg = 0
a.sort()
for i in range(N-1):
    if(a[i] == a[i+1]):
        flg = 0
if(flg == 0):
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    prev = input()
    already = {prev}
    for _ in range(n - 1):
        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: Accepted

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

judge = len(w) == len(set(w))

for pre, post in zip(w[:-1], w[1:]):
    judge &= pre[-1] == post[0]

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

Submission status: Accepted

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

Submission status: Accepted

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

word_num = int(input())

word_list=[]
for i in range(word_num):
  word_list.append(str(input()))
  if(is_unique(word_list) == False):
      print("No")
      exit()



# 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: Accepted

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')
else:
    print('No')

Submission status: Accepted

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[count] = string

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 土  9/ 8 21:24:49 2018

# Usage
#
"""
from operator import and_
from functools import reduce
def get_nlines():
    N = int(input())
    return [input() for i in range(N)]


def tsunagari_check(first, second):
    if first[-1] == second[0]:
        return True
    else:
        return False

def judge(data):
    """
    >>> judge(["hoge","english", "hoge"])
    False
    >>> judge(["basic","cpp","python"])
    True
    >>> judge(["agg","abc", "cba"])
    False
    """
    # 1st check
    if len(set(data)) == len(data):
        pass
    else:
        return False

    # 2nd check
    checked = [tsunagari_check(data[i], data[i+1]) for i in range(len(data)-1)]
    # print(checked)
    return reduce(and_, checked)

if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    RES = judge(get_nlines())
    if RES:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
ans = "Yes"
arr = []
for i in range(N):
    arr.append(input())
    if not i == 0:
        if arr[i-1][-1] == arr[i][0] and not arr[i] in arr[:-2]:
            pass
        else:
            ans = "No"
            break

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
W=list()

start=list()
end=list()

for i in range(N):
    W.append(input())
    w=W[i]
    w=list(w)
    
    if i!=0:
        start.append( w[0] )

    if i!=(N-1):
        end.append( w.pop() )
        
    w.clear()

Ws=set(W)

if len(W)!=len(Ws) or start!=end:
    print("No")

else :
    print("Yes")

Submission status: Accepted

Solution code:
# abc109b

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

for i in range(N):
    W.append(input())

h = []
for i in range(1,N):
    h.append(W[i][0])
t = []
for i in range(N-1):
    t.append(W[i][-1])    

flg = 1
for i in range(N-1):
    if h[i] != t[i]: flg = 0
W.sort()
for i in range(N-1):
    if W[i] == W[i+1]: flg = 0

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

Submission status: Accepted

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

def is_unique(seq):
    return len(seq) == len(set(seq))
flag = 'B'
if is_unique(t) == False:
  flag = 'A'

count = 0       
while count < N-1:
  if t[count][-1] != t[count+1][0]:
      flag = 'A'
      count += 1
  else:
    count += 1

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

Submission status: Accepted

Solution code:
n = int(input())

memo = []
flag = 1
for i in range(n):
    w = input()
    start = w[0]
    if i==0: end = w[len(w)-1]; memo.append(w); continue
    if start == end and not w in memo: end = w[len(w)-1]; memo.append(w)
    else: flag = 0; break

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

Submission status: Accepted

Solution code:
a=int(input())
l=[]
for i in range(a):
    s=input()
    if i!=0:
        if s[0]!=last or l.count(s):
            print('No')
            exit()
    l.append(s)
    last=s[-1]
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
index=0
lists =[]
listForWords=[]
flag =0
while index<n:
    word = input()
    list1 = list(word)
    if index!=0:
        length = len(lists[index-1])
        if list1[0] == lists[index-1][length-1]:
            for li in listForWords:
                if word == li:
                    flag =1
        else:
            flag =1
    lists.append(list1)
    listForWords.append(word)
    index+=1

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

Submission status: Accepted

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: Accepted

Solution code:
N = int(input())
a = []
for i in range(N):
    a.append(input())
flag = True
for j in range(N-1):
    a_i = a[j]
    a_ii = a[j+1]
    if a_i[-1] != a_ii[0]:
        flag = None
        break
    for k in range(j+1, N):
        if a[j] == a[k]:
            flag = None
            break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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 >= 1:
        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: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
list_w = list()
for i in range(n):
    list_w.append(input())
a = 0
i = 0
while i <= n-2:
    x = list_w[i]
    y = list_w[i+1]
    if x[-1] != y[0]:
        a += 1
        break
    if i > 0:
        for j in range(i):
            if x == list_w[j - 1]:
                a += 1
                break
    i += 1
if a == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = input()
s = set()
s.add(w)
for _ in range(n-1):
    x = input()
    if x in s or w[-1] != x[0]:
        print("No")
        exit()
    s.add(x)
    w = x
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

ans = 'Yes'
pre = input()

his = {}
his[pre] = 1
for i in range(N-1):
    s = input()
    if s[0] != pre[ len(pre) - 1 ] or (s in his):
        ans = 'No'
        
    his[s] = 1
    pre = s
    
print (ans)

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(n):
    w = input()
    l.append(w)
l.append(w[-1])
f = l[0]
ls = set(l)
fff=0
if len(l) != len(ls):
    fff = 1
    print("No")
else:
    first = f[0]
    for i in range(n):
        if l[i][-1] == l[i+1][0]:
            continue
        else:
            fff = 1
            print("No")
            break
if fff ==0:
    print("Yes")

Submission status: Accepted

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

if len(set(w)) != n:
	print("No")
else:
	ok = True
	for i in range(n - 1):
		if w[i][-1] != w[i + 1][0]:
			ok = False
			break
	if ok:
		print("Yes")
	else:
		print("No")

Submission status: Accepted

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
        break
if flag:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w1 = input()
w = {w1}
flag = True
cw = w1
for _ in range(n-1):
    nw = input()
    if nw[0] != cw[-1] or nw in w:
        flag = False
    w.add(nw)
    cw = nw
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

# 標準入力
N = int(input())

# 単語を入れる配列
words = []

flag = 0

for i in range(0, N):
    # 単語の標準入力
    tmp = input()
    words.append(tmp)
    if(i != 0):
        if(tmp2[-1] != tmp[0]):
            flag = 1
    tmp2 = tmp
    for j in range(0, i):
        if(words[j] == words[i]):
            flag = 1

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

Submission status: Accepted

Solution code:
n = int( input() )

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

#print(list)

j = 0
k = 1
error = 0

while j < n-1:
    str1 = list[j]
    str2 = list[j+1]
    if str1[-1] == str2[0]:
        j += 1
        continue
    else:
        error += 1
        break

while k <= n:
    count = list.count(list[-k])
    if count != 1:
        error += 1
        break
    else:
        k += 1
        continue
        
if error == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(raw_input())
W = []
for _ in range(n):
    W.append(raw_input().strip())

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

Submission status: Accepted

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

S=0

for i in range(N-1):
    if W.count(W[i])!=1:
        ans="No"
        break
    elif W[i][-1]==W[i+1][0]:
         S=S+1

if S==N-1:
    ans="Yes"
else:
    ans="No"
    
print(ans)

Submission status: Accepted

Solution code:
time=input()
w_l=[]
ch=0
for i in range(time):
    j=raw_input()
    if j in w_l:
        print("No")
        ch=1
        break
    else:
        if w_l==[]:
            w_l.append(j)
        else:
            j_1=list(w_l[-1])
            j_2=list(j)
            if j_1[-1]!=j_2[0]:
                print("No")
                ch = 1
                break
            else:
                w_l.append(j)

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

Submission status: Accepted

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

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

Submission status: Accepted

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 = 1
    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: Accepted

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

Submission status: Accepted

Solution code:
x = int(input())
ANS = "Yes"
s = []

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

Submission status: Accepted

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

correct = True
for i in range(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: Accepted

Solution code:

N = int(input())
wardList = [input() for _ in range(N)]
ans = "Yes"
history = set()
lastCharacter = ''

for i in range(N):
    ward = wardList[i]
    if ward in history:
        ans = "No"
        break
    else:
        if i > 0:
            if lastCharacter != ward[0]:
                ans = "No"
                break
        history.add(ward)
        lastCharacter = ward[len(ward)-1]

print(ans)

Submission status: Accepted

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
for l in range(num_word  - 1):
    if word_list[num_word - 1] == word_list[l]:
        flag = False

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

Submission status: Accepted

Solution code:
import sys

n = int(input())
t = input()
w = [t]

for i in range(n-1):
    s = input()
    if s in w:
        print('No')
        sys.exit()
    w += [s]

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


print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

flag = True
chr = 'A'
table = []
for i in range(n):
    line = input()
    if not(chr == line[0] or chr == 'A'):
        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: Accepted

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"Yes"
else:
    print"No"

Submission status: Accepted

Solution code:
n = int(input())
flag = True
s = []
words = []
w1 = input()
words.append(w1)
e = w1[-1]

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]


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

Submission status: Accepted

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[:x]):
			print("No")
			sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = set()
wk = None

for _ in range(n):
  wi = input()
  if wi in w or wk and wk[-1] != wi[0]:
    print('No')
    break
  w.add(wi)
  wk = wi
else:
  print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
s=input()
lt=[s]
lw=s[-1]
msg='Yes'
for i in range(1, n):
    s=input()
    if s[0] != lw or lt.count(s) > 0:  
        msg='No'
        break
    else:
        lw=s[-1]
        lt.append(s)
print(msg)

Submission status: Accepted

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]:
            pre_w = w
            continue
        else:
            print("No")
            exit()
    print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N= int(input())
W=[]
f=0
s2=" "
for i in range(N):
    s=str(input())
    if s in W or (i >0 and s2[-1]!=s[0]):
        f=1
        break
    W.append(s)
    s2=s
if f==1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

for j in range(len(word)):
    if j > 0:
        mae = word[j-1]
        ima = word[j] 
        if mae[-1] != ima[0]:
            print("No")
            exit()
for w in word:
    if word.count(w) > 1:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
count = 0
listA=[]
while (count <= N-1):
    try:
        listA.append(str(input()))
        count+=1
    except:
        break;
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: Accepted

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

tmp = [S[0]]
flag = True
for i in range(1,N):
    if S[i-1][-1] != S[i][0]:
        flag = False
        break
    if S[i] in tmp:
        flag = False
        break
    tmp.append(S[i])

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

Submission status: Accepted

Solution code:
N = int(input())
word = []
flag = 0
for i in range(N):
  now = input()
  if i == 0:
    word.append(now)
  else:
    check = word[i-1]
    if now[0] != check[len(check)-1]:
      flag = 1
      print("No")
      break
    for j in range(len(word)):
      if now == word[j]:
        flag = 1
        print("No")
        break
    word.append(now)
if flag == 0:
  print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
W_his=[]
count=0
s_flag=1

for i in range(N):
	W_his.append(input())
	if i != 0:
		W_0=W_his[i-1]
		W_1=W_his[i]
		if W_0[-1] != W_1[0]:
			s_flag=0
			break
			
		for j in range(i-1):
			if W_his[j] == W_his[i]:
				s_flag=0
				break

if s_flag==1:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
w = []
for i in range(n):
    w.append(input())
result = 'Yes'

l = len(w)
w_ = list(set(w))
l_ = len(w_)

if l != l_:
    result='No'

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

print(result)

Submission status: Accepted

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

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

char = wordList[0][-1:]
for n in range(1, len(wordList)):
    if(char != wordList[n][:1]):
        print("No")
        exit()
    char = wordList[n][-1:]

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
word_list = [input() for i in range(N)]
#print(word_list)

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

Submission status: Accepted

Solution code:
n = int(input())
tango = []
count = 0
kaburi = 0
for i in range(n):
    tango.append(input())

for i in range(n-1):
    if tango[i][-1] != tango[i+1][0]:
            count = 1

for i in range(n):
    for j in range(n):
        if tango[i] == tango[j]:
            kaburi += 1



if count == 0 and kaburi == n:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
siritori=[input() for i in range(n)]
tale=siritori[0][:1]
answer='Yes'
for i in range(n):
    if tale!=siritori[i][:1]:
        answer='No'
        break
    if siritori.index(siritori[i])!=i:
        answer='No'
        break
    tale=siritori[i][-1:]
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
flag = True
s = str(input())
b = set()
b.add(s)
for i in range(N-1):
    k = str(input())
    if (k[0] != s[-1]) or (k in b):
        flag = False
        break
    b.add(k)
    s = k
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N=int(input())

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

check=1

for i in range(1,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

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

else:
    print("No")

Submission status: Accepted

Solution code:
def main():
    N = input()
    lst = []
    result = 'Yes'
    for i in range(N):
        W = raw_input()
        # print lst
        if lst == []:
            lst.append(W)
            continue
        if W in lst:
            result = 'No'
            break
        elif W[0] != lst[-1][-1]:
            # print W[-1]
            # print lst[-1][-1]
            result = 'No'
            break
        else:
            lst.append(W)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy


def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    W_set = set([])
    pre_last_char = ""
    for i in range(N):
        input_raw = read_func().strip().split()
        W = input_raw[0]
        if W not in W_set and (pre_last_char == "" or pre_last_char == W[0]):
            W_set.add(W)
            pre_last_char = W[len(W) - 1]
        else:
            print "No"
            exit()
    print "Yes"

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

def checkRule(words):
  if len(words) != len(set(words)):
    print("No")
    return

  tail= words[0][0]
  for w in  words:
    if w[0] != tail:
      print("No")
      return
    else:
      tail = w[-1]

  print("Yes")

checkRule(words)

Submission status: Accepted

Solution code:
import sys

n = int(input())

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

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

if not is_unique(w):
    print("No")
    sys.exit(0)

pre_word = w[0]
for word in w[1:]:
    # print(pre_word[-1], word[0])
    if pre_word[-1] != word[0]:
        print("No")
        sys.exit(0)
    pre_word = word
print("Yes")

Submission status: Accepted

Solution code:
ans, s = "Yes", ''
d = {}
for _ in range(int(input())):
    t = [str(x) for x in ''.join(input())]
    if d.get(''.join(t)) != None or (_ > 0 and t[0] != s[-1]):
        ans = "No"
        break
    d.setdefault(''.join(t), 1)
    s = t
print(ans)