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:
# coding: utf-8

N = input()

list=[]
flag = True

for i in range(int(N)):
    temp=input()
    #print(temp)
    if str(temp) in list:
        flag=False
    list.append(temp)
    if flag==False:
        break

    str1=list[i-1]
    str2=list[i]
    if i!=0:
        if str1[-1]==str2[0]:
            flag=True
        else:
            flag=False
    if flag==False:
        break

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

Submission status: Accepted

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

count = int(input())

i = 0
str_list = []
while i < count:
    str_list.append(input())
    i += 1


# 重複判定
result_a = is_uniq(str_list)

result_b = True
for i, word in enumerate(str_list):
    # 最初の単語ではない場合
    if i != 0:
        # １つ前の単語の最後尾を取得
        pre_str_tail = str_list[i - 1][-1]
        str_head = str_list[i][0]

        if pre_str_tail != str_head:
            result_b = False
            break

if result_a and result_b:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

ans="No"
W=[]

w = input()
W.append(w)

for i in range(N-1):
	w = input()
	if W[i][-1]!=w[0]:
		print(ans)
		exit(0)
	W.append(w)

W.sort()

for i in range(N-1):
	if W[i]==W[i+1]:
		print(ans)
		exit(0)

ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ws = [str(input()) for i in range(n)]
before_w=""
ok = True
ends=[]
for i, w in enumerate(ws):
    if i == 0:
        before_w = w
        ends.append(w)
        continue
    if w[0] == before_w[-1]:
        before_w = w
        if(w in ends):
            ok=False
            break
        ends.append(w)

        continue
    else:
        ok = False
        break

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

Submission status: Accepted

Solution code:
N=int(raw_input())

array=[]

judge = 'Yes'

for i in range(N):
    word = list(raw_input())
    if word in array:
        judge = 'No'
        break
    if len(array) != 0:
        last = array[-1]
        if word[0] != last[-1]:
            judge = 'No'
            break

    array.append(word)

#print N
#print array

print judge

Submission status: Accepted

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

if len(W) == len(set(W)):
    accept = True
    lw = W[0][-1]
    for w in W[1:]:
        if lw != w[0]:
            accept = False
            break
        else:
            lw = w[-1]
    if accept:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
n=int(raw_input())

w={}
pre_last=''
for i in range(n):
  s=raw_input()
  if s in w:
    print "No"
    sys.exit()
  else:
    w[s]=1
  now_begin=s[0:1]
  if i > 0:
    if pre_last!=now_begin:
      print "No"
      sys.exit()
  pre_last=s[-1:]
print "Yes"

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input())
W = [input() for _ in range(n)]
a = []
before_tail = ""
current_first = " "
flag = True
for i in range(1,n):
    current_first = W[i][0]
    before_tail = W[i-1][-1]
    if current_first != before_tail:
        flag = False
        break

if flag and is_unique(W):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
N = int(input())

s = ['' for i in range(N)]
for i in range(N):
    s[i] = str(input())

for i in range(N):
    for j in range(i + 1, N):
        if s[i] == s[j]:
            print('No')
            sys.exit()

for i in range(1, N):
    str1 = list(s[i - 1])
    str2 = list(s[i])
    if str1[-1] != str2[0]:
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

w = [''] * n

end = ''
res = 'Yes'

hTable = {}

for i in range(0, n):
    w[i] = str(input())

    if (i == 0 or end == w[i][0]) and (w[i] not in hTable):
        end = w[i][-1]
        hTable.setdefault(w[i])
    else:
        res = 'No'


print(res)

Submission status: Accepted

Solution code:
n=int(input())
flag=False
l=[]
for i in range(0,n):
    if(i==0):
        s=input()
        l.append(s)
    if(n==1):
        print('Yes')
        continue
    if(i>=1):
        s=input()
        li=list(st)
        if(li[-1]==s[0] and s not in l):
            flag=True
        else:
            print('No')
            exit()
        l.append(s)
    st=s
if(flag):
        print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(raw_input())

W = [raw_input().replace("\r", "") for _ in range(N)]

ans = "Yes"

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

    else:
        if i == 0:
            continue

        if W[i][0] != W[i-1][-1:]:
            ans = "No"
            break

print ans

Submission status: Accepted

Solution code:
a = int(input())
flg = 0
b =[]
c = ""
for i in range(a):
    s = str(input())
    for j in b:
        if s == j:
            flg = 1
    if i != 0:
        if s[0:1] != c[-1:]:
            flg = 1
    c = s
    b.append(s)
if flg == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
w = []
for i in range(n):
    w.append(input())
ans = "Yes"
flag = 0
for i in w:
    if w.count(i) != 1:
        flag= 1
        ans = "No"
        break

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

Submission status: Accepted

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

s = set()
l = []

for c in w:
    s.add(c)
    l.append([c[0], c[len(c) - 1]])

if len(s) != len(w):
    print("No")
    exit()

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

print("Yes")

Submission status: Accepted

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:
    if w[0][-1] != w[1][0]:
        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: Accepted

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

    if len(set(W)) != N:
        print('No')
        return 0
    else:
        pre = ''
        for i, word in enumerate(W):
            if i > 0:
                if pre != word[:1]:
                    print('No')
                    return 0
            pre = word[len(word)-1 :]
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
N = int(input())
k = input()
a = []
for i in range(N-1):
    a.append(input())
lis = [k]
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: Accepted

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 0 < i and W[i-1][-1] != W[i][0]:
            result = "No"
            break
        else:
            result = "Yes"
print(result)

Submission status: Accepted

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

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

Submission status: Accepted

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

if (len(words)==len(set(words))):
    for i in range(N-1):
        if(words[i][-1] != words[i+1][0]):
            status = 'error'
            break
        elif(i == N-2):
            status = 'done'
else:
    status = 'error'

if(status == 'done'):
    print('Yes')
elif(status == 'error'):
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
shiritori = []

for i in range(N):
    word = input()
    shiritori.append(word)
    if i == 0:
        pass
    else:
        if shiritori[i].startswith(shiritori[i-1][-1:]):
            pass
        else:
            print("No")
            exit()


if len(set(shiritori)) == N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys


def main():
    lines = [x.strip() for x in sys.stdin.readlines()]
    N = lines[0]
    words = lines[1:]
    w = words[0][-1]
    result = "Yes"
    if len(set(words)) != len(words):
        result = "No"
    else:
        for i in words[1:]:
            if i[0] != w:
                result = "No"
            w = i[-1]
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
  n = int(input())
  words = []

  for _ in range(n):
    word = input()
    words.append(word)
  set_word = set(words)
  if len(set_word) != len(words):
    print("No")
    return 0

  for i, word in enumerate(words):
    if i > 0:
      last = words[i-1][-1]
      front = words[i][0]

      if front != last:
        print("No")
        return 0
      

  print("Yes")



solve()

Submission status: Accepted

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

Solution code:
n = int(input())

spoken_words = []
for i in range(n):
    word = input()
    if i >= 1:
        if word in spoken_words or spoken_words[-1][-1] != word[0]:
            print("No")
            exit()
    spoken_words.append(word)
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

def is_unique(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)

N = int(stdin.readline().rstrip())
ans = "No"
words = []

for i in range(N):
    word = stdin.readline().rstrip()
    words.append(word)
if is_unique(words):
    ans = "Yes"
    for i in range(N-1):
        if words[i][-1] != words[i+1][0]:
            ans = "No"
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
def checker(n):
    words = []
    last_one = []
    for i in range(n):
        word = input()
        wl = list(word)
        h = wl[0]
        l = wl[-1]
        if word in words:
            print('No')
            return
        if i>0 and  h != last_one[-1]:
            print('No')
            return
        words.append(word)
        last_one.append(l)
    print('Yes')
    return

checker(n)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 109 20180908
# Question:B

def main(N, words):
	answer = "Yes"
	
	for j in range(1,N):
		
		if words[j] in words[:j]+words[j+1:]:
			answer = "No"
			break
		elif words[j-1][len(words[j-1])-1] != words[j][0]:
			answer = "No"
			break
	return answer
		
	
	
	
N = int(input())
words = []
try:
	while True:
		words.append(input())
except EOFError:
	pass
print(main(N,words))

Submission status: Accepted

Solution code:
N = int(input())

already_list=[]
w=0
for i in range(N):
    W = input()
    if W not in already_list:
        if w==0 or w[-1]==W[0]:
            already_list.append(W)
            w=W

if len(already_list) == N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
w=[]
for i in range(n):
    w.append(input())
if n==len(list(set(w))):
  ans='Yes'
else:
  ans='No'

for i in range(n-1):
    if w[i][-1:]==w[i+1][0]:
        a=0
    else:
        ans='No'
        break
print(ans)

Submission status: Accepted

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 
        break       
    if check_shiritori(w[i-1], w[i]):
        used_words.append(w[i])
    else:
        rule_flag = False
        break

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

Submission status: Accepted

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

ans = "Yes"
used = {}
for i in range(n):
    if ws[i] in used or (0 < i and ws[i - 1][-1] != ws[i][0]):
        ans = "No"
        break
    used[ws[i]] = i
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  8 18:33:41 2018
ABC109B
@author: maezawa
"""
import collections
n = int(input())
words = []
for i in range(n):
    words.append(input())

samew = collections.Counter(words)
sn = sorted(samew.values())
if sn[0] != 1 or len(set(sn)) != 1:
    print('No')
else:
    ans = 'Yes'
    for i in range(n-1):
        if words[i][-1] == words[i+1][0]:
            continue
        else:
            ans = 'No'
            break
    print(ans)

Submission status: Accepted

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

def chk_shiri(w):
    for i in range(n - 1):
        if w[i][-1] == w[i + 1][0]:
            continue
        else:
            return False
    return True
    
if len(w) != len(set(w)):
    print('No')
elif chk_shiri(w):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
words = []
ans = 1
for i in range(n):
    word = input()
    if word not in words:
        words.append(word)
    else:
        ans = 0
if len(words) == n:
    for i in range(n-1):
        word = words[i]
        if words[i][len(word)-1] == words[i+1][0]:
            continue
        else:
            ans = 0
            break

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.read().split()

N = int(input[0])
words = input[1:]

hantei = 0

for i in range(N-1):
    for j in range(i+1,N):
        if words[i] == words[j]:    # 同じ文字がないか
            hantei += 1
            break
    if list(words[i])[-1] != list(words[i+1])[0]:   #しりとりになっているか
        hantei += 1
        break

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

Submission status: Accepted

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
        L.append(w)
        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: Accepted

Solution code:
# problem Bt
n = int(input())

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

first = w[0][0]
new_w = []
res = True
for i in range(n):
    if w[i][0] != first or w[i] in new_w:
        res = False
        break
    new_w = w[0:i+1]
    first = w[i][-1]

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

Submission status: Accepted

Solution code:
import sys

line = input()
n = int(line)

word_list = []
line = input()
word_list.append(line)
prefix = line[-1:]
#print("prefix =" + prefix)

ans = "Yes"
for i in range(1, n):
    line = input()

    if line in word_list:
        ans = "No"
    
    word_list.append(line)

    atama = line[:1]
    #print("atama = " + atama)

    if atama != prefix:
        ans = "No"

    prefix = line[-1:]
    #print("prefix =" + prefix)

    if i == 0:
        continue

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

w = str(input())
W = list(w)
# start = W[0]
Ws = [w]
stop = W[-1]
count = 1

for i in range(N-1):

	w2 = str(input())
	W2 = list(w2)
	if(w2 not in Ws):
		if(W2[0]==stop):
			stop = W2[-1]
			count += 1
			Ws.append(w2)

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

Submission status: Accepted

Solution code:

import sys
iN = int(input())
aList = [x.strip() for x in sys.stdin.readlines()]



dicList = {aList[0]:1}
for i in range(1,iN):
    if aList[i][0] != aList[i-1][-1] :
        print("No")
        exit()
    if aList[i] not in dicList :
        dicList[aList[i]] = 0
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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]:
        f = 1
    s.append(t)
    
if f == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def count_word(words, word):
    count = 0

    for w in words:
        if w == word:
            count += 1

    return count

n = int(input())

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

bind_letter = ""
for word in words:
    matches = count_word(words, word)
    if matches >= 2:
        print("No")
        exit()

    if bind_letter != "":
        if word[0] != bind_letter:
            print("No")
            exit()
    bind_letter = word[len(word) - 1]
    
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
string_list=[input() for i in range(n)]
ans=0
for i in range(n-1):
    if string_list[i][-1:] != string_list[i+1][:1] :
        ans +=1
zako =set(string_list)

if len(string_list) == len(zako) and ans==0 :
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N=int(input())
list1=[]

s=input()
S=s
list1.append(s)
#print(list1[0][-1])
for i in range(N-1):
    s=input()
    #print(s)
    #print(s[len(s)-1])
    if s in list1:
        print("No")
        exit()
    elif s[0] != S[len(S)-1]:
        print("No")
        exit()
    else:
        S=S+s
        list1.append(s)
print("Yes")

Submission status: Accepted

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

N = int(input())
words = []
for i in range(N):
    words.append(input())
hantei = 0
for i in range(N-1):
    a = [x for x in words[i]]
    b = [x for x in words[i+1]]
    if a[len(a)-1] == b[0]:
        pass
    else:
        hantei += 1
        break
if hantei == 0 and is_unique(words) == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
s = S()
last = s[-1]
lis = [s]
for i in range(n-1):
    s = S()
    if s in lis or s[0] != last:
        print("No")
        exit()
    else:
        last = s[-1]
        lis.append(s)
print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

input = sys.stdin.readline
n = int(input())
w = []

for i in range(n):
    w.append(str(input()))

for i in range(n):
    if w.count(w[i]) > 1:
        print("No")
        exit(0)

    if i != n - 1:
        if w[i][-2] != w[i + 1][0]:
            print("No")
            exit(0)


print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
list = []
result = True
for i in range(N):
    word = input()
    if i > 0:
        chk_word = list[i - 1]
        if chk_word[-1] != word[0]:
            result = False
    list.append(word)
    if list.count(word) > 1:
        result = False
print('Yes' if result else 'No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Shiritori

n = int(input().strip())
ws = []
w = None
ret = 'Yes'
for i in range(n):
    w_ = input().strip()
    if w_ in ws:
        ret = 'No'
    else:
        ws.append(w_)
    if w is None:
        w = w_
        continue
    if w[-1] != w_[0]:
        ret = 'No'
    w = w_
print(ret)

Submission status: Accepted

Solution code:
import collections

N = int(input())
W = [input() for i in range(N)]
c = collections.Counter(W)

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

Submission status: Accepted

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

res = 'No'
ok_list = []
for i in range(n-1):
    if siritori_list[i][-1] == siritori_list[i+1][0]:
        ok_list.append('ok')

siritori_set_list = list(set(siritori_list))

if len(siritori_set_list) == n and len(ok_list) == n-1:
    res = 'Yes'

print(res)

Submission status: Accepted

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

ans = len(ws)==len(set(ws))
for pre, pos in zip(ws, ws[1:]):
    ans &= pre[-1]==pos[0]

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

Submission status: Accepted

Solution code:
N=input("")
N=int(N)
S=[]
f=1
for i in range(1,N+1,1):
    mystr=input("")
    if i>=2:
        if lastchar!=mystr[0]:
            f=0
            break
        if mystr in S:
            f=0
            break

    lastchar=mystr[-1]
    S+=[mystr]
if f==0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

W = []
for _ in range(N):
    w = input()
    W.append(w)

W_set = set(W)
if len(W_set) != N:
    print('No')
else:
    last = None
    satisfy = True
    for w in W:
        if last == None:
            last = w[-1]
            continue
        else:
            if w[0] != last:
                satisfy = False
                break
            last = w[-1]

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

Submission status: Accepted

Solution code:
arr=[]
n=int(raw_input())
for i in range(n):
	arr.append(raw_input())
b=[arr[0]]
t=True
for i in range(1,len(arr)):
	if arr[i] not in b and b[-1][-1]==arr[i][0]:
		b.append(arr[i])
	else:
		t=False
		break
print "Yes" if t else "No"

Submission status: Accepted

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

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

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

t = "Yes"

li_uniq = []
for x in W:
    if x not in li_uniq:
        li_uniq.append(x)


if W == li_uniq:
    for i in range(N - 1):
        if W[i][-1] == W[i+1][0]:
            continue
        else:
            t = "No"
else:
    t = "No"

print(t)

Submission status: Accepted

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("No")
            exit()
    for j in range(i):
        if W[i] == W[j]:
            print("No")
            exit()
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for x in range(N)]
counter=0
def isunique(seq):
    return len(seq) == len(set(seq))

if isunique(W) == False:
    print("No")
else:
    for i in range(N-1):
        if W[i][-1]==W[i+1][0]:
            counter += 0
        else:
            counter += 1
    if counter ==0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
used_words = []

pre_word = input()
used_words.append(pre_word)
state = "Yes"


for i in range(N-1):
    W = input()

    if pre_word[-1] != W[0]:
        state = "No"
        break

    for uw in used_words:
        if uw == W:
            state = "No"
            break
    if state == "No":
        break

    used_words.append(W)
    pre_word = W

print(state)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
words = []
flag = True

for i in range(n):
    w = input()
    if i >= 1:
        if words[-1][-1] != w[0]:
            flag = False
        
    words.append(w)

    
c = Counter(words)

for j in  c.values():
    if j != 1:
        flag = False
        
if flag :
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for _ in range(n)]
j=True
t=w[0][-1]
for i in range(1,n):
    if w[i][0]!=t:
        j=False
    else:
        t=w[i][-1]
from collections import Counter
c=Counter(w)
x=[list(c.items())[i][1] for i in range(len(list(c.items())))]
if max(x)>1:
    j=False
print("Yes" if j else "No")

Submission status: Accepted

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

Solution code:
N = input()
a = []
for i in range(int(N)):
    content = input()
    if a.count(content) != 0:
        print("No")
        exit()
    elif len(a) > 0 and a[-1][-1] != content[0]:
        print("No")
        exit()
    else:
        a.append(content)

print("Yes")

Submission status: Accepted

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


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


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

Submission status: Accepted

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

Submission status: Accepted

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

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

if len(S) != len(set(S)):
    print("No")
    
else:
    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: Accepted

Solution code:
N=int(input())
mojiretsu=[]
c1=""
c2=""

c3=""
c4=""
for i in range(N):
    mojiretsu.append(input())

for i in range(N):
    c1=mojiretsu[i]
    for j in range(N):
        c2=mojiretsu[j]
        if i!=j:
            if c1==c2:
                print("No")
                exit()

for i in range(N-1):
    c3=mojiretsu[i]
    c3=c3[-1]
    c4=mojiretsu[i+1]
    c4=c4[0:1]
    
    if c3!=c4:
        print("No")
        exit()
        
                
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
ans = 0
if len(W) != len(set(W)):
    ans = 1
else:
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            ans = 1
            break

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

Submission status: Accepted

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

frag = 1
for str in list:
  if list.count(str) != 1:
    frag = 0
for i in range(1,N):
  if list[i - 1][len(list[i - 1]) - 1] != list[i][0]:
    frag = 0
    
if frag == 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

print(get_res(words))

Submission status: Accepted

Solution code:
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    w = [input() for i in range(n)]

    w_set = set()
    for i in range(n):
        if i == 0:
            w_set.add(w[i])
        else:
            wi, wii = w[i][-1], w[i-1][0]
            if w[i][0] == w[i-1][-1] and w[i] not in w_set:
                w_set.add(w[i])
            else:
                print("No")
                exit()

    print("Yes")



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
N = int(input())
W=[]
for i in range(N):
	W = W +[input()]
for j in range(N-1):
	if W[j][-1]==W[j+1][0]:
		pass
	else:
		print("No")
		sys.exit()
for k in range(N):
	if W.count(W[k])==1:
		pass
	else:
		print("No")
		sys.exit()
print("Yes")