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())
prev=input()
words = [prev]
for i in range(N-1):
  cur = input()
  if cur[0] != prev[-1] or cur in words:
    print('No')
    break
  words.append(cur)
  prev = cur
else:
  print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
w = []
res = 'Yes'
prev = ''
# input
for i in range(n):
    w.append(input())
# 複数回発言をチェック
for word in w:
    if w.count(word) > 1:
        res = 'No'
        break
# w[i]の末尾とw[i+1]の先頭が同じならNo
for i in range(n):
    if i == 0:
        prev = w[i]
    else:  # i > 0
        if prev[-1] != w[i][0]:
            res = 'No'
            break
        prev = w[i]
print(res)

Submission status: Accepted

Solution code:
N = int(input())
L = [ input() for i in range(N)]
tmpl = []
tmp = L[0][0]
res = "Yes"
for l in L:
    if l in tmpl:
        res = "No"
        break
    if l[0] != tmp:
        res = "No"
        break
    tmp = l[-1]
    tmpl.append(l)
   
print(res)

Submission status: Accepted

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

flag = 0
word = input()
wordlist = [word]

for i in range(N-1):
    word = input()
    if flag == 1:
        break
    elif word[0] != wordlist[i][-1]:
        flag = 1
        break
    elif word in wordlist:
        flag = 1
        break
    wordlist.append(word)

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

Submission status: Accepted

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

N = int(input())
wN = [input() for i in range(N)]

wN2 = list(set(wN))

if len(wN) != len(wN2):
    print('No')
    exit()

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
word=""
wordb=""
flag=0
lis=[]
for i in range(N):
    word=input()
    lis.append(word)
    if i!=0:
        if word[0]!=wordb[len(wordb)-1]:
            flag=1
            break
    wordb=word
for j in range(len(lis)):
    if lis.count(lis[j])>1:
        flag=1
        break
if flag==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

N = int(input())
word_list = []
flag = True
word = input()
word_list.append(word)
for i in range(1,N):
    word = input()
    check = word_list[i-1]
    if check[-1] == word[0]:
        word_list.append(word)
        if is_unique(word_list) == False:
            flag = False
            break
    else:
        flag = False
        break
if flag == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=[input() for i in range(n)]
b=set(a)
c=0
if len(a)!=len(b):print("No")
else:
  for x in range(n-1):
     if a[x][len(a[x])-1]!=a[x+1][0]:c+=1
     else:pass
  if c>0:print("No")
  else:print("Yes")

Submission status: Accepted

Solution code:
# a, b = map(int, input().split())
# h1 = int(input())
n = int(input())

word_ary = []
word_set = set()

def main():
	for i in range(1, n + 1):
		w = input()
		if i > 1 and word_ary[i - 2][-1:] != w[0]:
			print('No')
			return
		if w in word_set:
			print('No')
			return
		word_ary.append(w)
		word_set.add(w)
	print('Yes')
			
main()

Submission status: Accepted

Solution code:
N = int(input())

flag = True

bw = ''
wl = []
for i in range(N):
    w = input().strip()
    if i != 0:
        if bw[-1] is not w[0]:
            flag = False
        if w in wl:
            flag = False
        if flag is False:
            break
    wl.append(w)
    bw = w

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

Submission status: Accepted

Solution code:
N = int(input())

W = []
fg = True

for lop in range(N):
    W.append(input())
    
w = set(W)
if not(len(w) == N):
    fg = False
else:
    mae = W[0]
    for lop in range(1,N):
        if not(mae[-1:] == W[lop][0]):
            fg = False
        mae = W[lop]
if fg :
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
w=[]
dup=False
for _ in range(n):
    s=input()
    if s in w:
        dup=True
    w.append(s)
if dup:
    print('No')

else:
    last=w[0][0]
    for wi in w:
        if last!=wi[0]:
            print('No')
            break
        last=wi[-1]
    else:
        print('Yes')

Submission status: Accepted

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

bag = set(W)
zipped = [(W[i-1], W[i]) for i in range(1, len(W))]
valid = len(bag) == len(W) and all(p[-1] == q[0] for p, q in zipped)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
W = []
for _ in range(N):
    W.append(input())
for i in range(N):
    if W.count(W[i]) >= 2:
        print('No')
        sys.exit()
    elif i < N - 1:
        if not W[i][len(W[i]) - 1] == W[i + 1][0]:
            print('No')
            sys.exit()
print('Yes')

Submission status: Accepted

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

check = []
for i in range(len(w)-1):
    if w[i][-1] == w[i+1][0] :
        check.append(True)
    else :
        check.append(False)

if len(w) == len(list(set(w))) and all(check) :
    print("Yes")
else :
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
w = []
noFlag = 0
for i in range(n):
    tmp = input()
    if tmp in w:
        noFlag = 1
    if not w == []:
        if not tmp[0] == w[-1][-1]:
            noFlag = 1
    w.append(tmp)

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

Submission status: Accepted

Solution code:
N=int(input())
W=[]
miss_flag=False
past_W=[]

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

for i in range(N):
    
    if W[i] in past_W:
        miss_flag=True
        break
    if i<N-1:
        if W[i][len(W[i])-1]!=W[i+1][0]:
            miss_flag=True
            break    

    past_W.append(W[i])
    

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

Submission status: Accepted

Solution code:
n = int(raw_input())
a = [raw_input() for i in xrange(n)]

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

for i in xrange(1, n):
	if a[i - 1][-1] != a[i][0]:
		print "No"
		exit(0)

print "Yes"

Submission status: Accepted

Solution code:
import sys
N=int(input())
wordlist=[]
wordbefore=input()
wordlist.append(wordbefore)
for i in range (1,N):
    word=input()
    if word in wordlist:
        print("No")
        sys.exit()
    if wordbefore[len(wordbefore)-1] !=word[0]:
        print("No")
        sys.exit()        
    wordlist.append(word)
    wordbefore=word    
print ("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
d = [input()]

ret = "Yes"
for _ in range(n-1):
    w = input()
    if w[0]!=d[-1][-1] or w in d:
        ret = "No"
    d.append(w)

print(ret)

Submission status: Accepted

Solution code:
N = int(input())
W = []
head = ''
ans = "Yes"
for i in range(N):
    W.append(input())
while len(W) != 0:
    word = W[-1]
    W.pop()
    if word in W or (head != '' and word[-1] != head):
        ans = "No"
        break
    head = word[0]
print(ans)

Submission status: Accepted

Solution code:
def siritori(N, W):
    if len(set(W)) < N:
        return False

    for i in range(N-1):
        word = W[i]
        following_word = W[i+1]

        if word[-1] != following_word[0]:
            return False

    return True

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

if siritori(N, W):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
memory = set()
end = None
break_flg = False
for i in range(n):
  w = input()
  if w in memory:
    print("No")
    break_flg = True
    break
  start = w[0]
  if end == start or end is None:
    memory.add(w)
    end = w[-1]
  else:
    print("No")
    break_flg = True
    break
if not break_flg:
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
temp = []
for i in range(n):
    temp.append(input())
temp_res = set(temp)
if len(temp) != len(temp_res):
    print("No")
else:
    ans = 0
    for i in range(n-1):
        # print(i)
        temp_c1 = str(temp[i])
        temp_c2 = str(temp[i+1])
        # print()
        # print(temp_c1)
        # print(temp_c2)
        if temp_c1[-1] == temp_c2[0]:
            ans+=1
        # print(ans)
    if ans == n-1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

list = []
result = 'Yes'
for i in range(n):
    if w_list[i] not in list:
        list.append(w_list[i])
    else:
        result = 'No'

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

Submission status: Accepted

Solution code:
n = int(input())
words = []
for i in range(n):
    words.append(input())
words_uniq = list(set(words))
result = []
if len(words) != len(words_uniq):
    print('No')
else:
    for i in range(1, len(words)):
        if words[i-1][-1] == words[i][0]:
            result.append('Yes')
        else:
            result.append('No')

    if 'No' in result:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
W = input()
dict = {W:1}
p = W
ans = 'Yes'
for n in range(N-1):
  W = input()
  if (p[-1] != W[0]) or (W in dict):
    ans = 'No'
    break
  else:
    dict[W] = 1
    p = W
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

if len(set(p)) != len(p):
    print('No')
    exit()

a = ""
b = w[0][len(w[0]) - 1]
for i in range(1, n):
    a = w[i][0]
    if a != b:
        print('No')
        exit()
    else:
        b = w[i][len(w[i]) - 1]

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

a = []
for i in range(N):
  a.append(input())
  if i > 0:
    curword = a[i]
    lastword = a[i-1]
    if lastword[len(lastword)-1] != curword[0]:
      print('No')
      exit()
    if curword in a[:len(a)-1]:
      print('No')
      exit()


print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(raw_input())
w = []

for i in range(n):
    tmp = raw_input()
    w.append(tmp)
    

flag = 0
for i in range(n):
    kensa = w[i]
    for j in range(n):
        if(j==i):
            continue
        if(kensa == w[j]):
            flag = 1

for i in range(n):
    if(i==0):
        continue
    if(w[i-1][-1] != w[i][0]):
        flag = 1
            

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

Submission status: Accepted

Solution code:
N = int(input())


def judge_siri():
    L = []
    for i in range(N):
        S = input()
        if S in L:
            return "No"
        if len(L) != 0 and S[0] != L[-1][-1]:
             return "No"
        L.append(S)
    return "Yes"

print(judge_siri())

Submission status: Accepted

Solution code:
n = int(input())

ans = 'Yes'

w = []

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

Submission status: Accepted

Solution code:
n=int(input())
flag=0
w=[]
used=[]
for _ in range(n):
    w.append(str(input()))
for i in range(n):
    if i==0:
        used.append(w[i])
    else:
        if (w[i] not in used) and (w[i-1])[-1]==(w[i])[0:1]:
            used.append(w[i])
        else:
            print('No')
            flag+=1
            break
if flag>0:
    pass
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

flag = 0
words = set()
for i in range(n):
    x = input()
    if i==0:
        y = x[0]
    words.add(x)

    #print(x,y, words)
    #print(":", y[-1], x[0])
    if not(y[-1] == x[0] and i < len(words)):
        flag = 1
        break
    y = x

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

Submission status: Accepted

Solution code:
n = int(input())
w = []
for i in range(n):
    w.append(str(input()))
check = 'Yes'
for i in range(n-1):
    a = w[i][-1]
    b = w[i+1][0]
    if a != b:
        check = 'No'
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)
if not is_unique(w):
    check = 'No'
print(check)

Submission status: Accepted

Solution code:
wd_cnt = int(input())

words = []

for i in range(wd_cnt):
    word = input()
    if word in words:
        print('No')
        exit()
    if len(words) > 0 and (word[0] != words[len(words) - 1][-1]):
        print('No')
        exit()
    words.append(word)
print('Yes')

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())
st = set()
s = []
ok = True
for i in range(n):
  s.append(input())
for i in range(n):
  if s[i] in st:
    ok = False
  if i > 0 and s[i][0] != s[i-1][-1]:
    ok = False
  st.add(s[i])
print("Yes" if ok else "No")

Submission status: Accepted

Solution code:
N = int(input())
L = []
oldword = input()
L.append(oldword)
for i in range(N-1):
    newword = input()
    if newword[0] == oldword[-1] and newword not in L:
        ans = 'Yes'
        L.append(newword)
        oldword = newword
    else:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

ns = lambda: stdin.readline()[:-1] # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

N = ni()

Words = []
w = ns()
last = w[-1]
Words.append(w)
flag = 1
for _ in range(N-1):
    w = ns()
    if w[0] != last:
        flag = 0
    if w in Words:
        flag = 0
    last = w[-1]
    Words.append(w)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n=int(input())

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

prev=[]
for i in range(n):
    x=w[i]
    if x in prev:
        print('No')
        sys.exit()
    elif i>0 and x[0]!=w[i-1][-1]:
        print('No')
        sys.exit()
    else:
        prev.append(x)
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
d = {}
last = None
flag = True

for _ in range(N):
    word = input()
    if word in d.keys():
        flag = False
    else:
        d[word] = 1

    if last is not None and last != word[0]:
        flag = False
    else:
        last = word[-1]

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

Submission status: Accepted

Solution code:
from sys import stdin, stdout
from collections import Counter

input = lambda: stdin.readline().rstrip()
# write = stdout.write

def main():
    N = int(input())
    W = stdin.read().splitlines()

    word = Counter(W)
    last = W[0][-1]
    for i in range(1, N):
        s = W[i]
        if word[s] > 1 or s[0] != last:
            print('No')
            return
        last = s[-1]
    print('Yes')

main()

Submission status: Accepted

Solution code:
import sys
N = int(input())
W = [input() for _ in range(N)]
d = set()
last = ""
for i in range(N):
    if W[i] in d:
        print("No")
        sys.exit()
    if last != "" and last != W[i][0]:
        print("No")
        sys.exit()
    last = W[i][-1]
    d.add(W[i])

print("Yes")

Submission status: Accepted

Solution code:
a=[input() for _ in range(int(input()))]
if len(a) > len(set(a)):
    print("No")
elif all([s[0]==e[-1] for (s, e) in zip(a+["?"],["?"]+a)][1:-1]):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, W):
    for i in range(1, N):
        if W[i-1][-1] != W[i][0]:
            return 'No'

    if len(set(W)) != N:
        return 'No'
    return 'Yes'


def main():
    N = read_int()
    W = [read_str() for _ in range(N)]
    print(slv(N, W))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if is_unique(w):
    for i in w[1:]:
        if tmp[-1] == i[0]:
            count += 1
        else:
            break
        tmp = i

if len(w) == count:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
valid = True
words = []
words.append(input().strip())
for i in range(1, n):
    w = input().strip()
    if w in words or words[i-1][-1] != w[0]:
        print("No")
        break
    words.append(w)
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

w = input()
p = w[-1]

l = {w}

ans = 'Yes'
for _ in range(n - 1):
    w = input()

    if p != w[0] or w in l:
        ans = 'No'

    p = w[-1]
    l.add(w)

print(ans)

Submission status: Accepted

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

def shiritori(words):
    history = set()
    pre = None
    for cur in words:
        if cur in history:
            return False
        if pre and pre[-1] != cur[0]:
            return False
        history.add(cur)
        pre = cur
    return True

def main():
    n = int(input())
    words = []
    for _ in range(n):
        words.append(input().strip())
    if shiritori(words):
        print('Yes')
    else:
        print('No')

main()

Submission status: Accepted

Solution code:
n = int(input())
flag = 0
buf = input()
last = buf[-1]
S = {buf}

for i in range(n-1):
	buf = input()
	if(buf[0] != last or buf in S):
		flag = 1
	S.add(buf)
	last = buf[-1]
	
if(flag == 0):
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
n = int(input())
log = []

last = ""
ans = "Yes"

for i in range(n):
    s = input()
    if (last != "" and last != s[0]) or (s in log):
        ans = "No"
        break
    log.append(s)
    last = s[len(s) - 1]


print(ans)

Submission status: Accepted

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

def calc():
	used = [W[0]]
	for i in range(N - 1):
		if W[i + 1] in used:
			return False
		if W[i][-1] != W[i + 1][0]:
			return False
		used.append(W[i + 1])
	return True

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

Submission status: Accepted

Solution code:
import sys
import copy

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]
sall = lambda: sys.stdin.readlines()

def main():
    n = ni()
    ws = sall()
    ws = [w.rstrip() for w in ws]

    o = ws[0]
    s = set()
    s.add(o)
    for w in ws[1:]:
        if o[-1] != w[0] or w in s:
            print('No')
            return

        s.add(copy.copy(w))
        o = copy.copy(w)

    print('Yes')

main()

Submission status: Accepted

Solution code:
n = int(input())
le = [input() for j in range(0,n)]
f = [True]
for i in range(1,n):
    if le.count(le[i])>1:
        f[0]=False
        break
    if le[i][0]!=le[i-1][-1]:
        f[0]=False
        break

if f[0]==True:
    print('Yes')

if f[0]!=True:
    print('No')

Submission status: Accepted

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

winflag=True

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

Submission status: Accepted

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

Submission status: Accepted

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

status = True
known = []

for i, w in enumerate(ws):
    if w in known:
        status = False
        break
    if w == "":
        status = False
        break
    if i !=0 and known[-1][-1] != w[0]:
        status = False
        break
    known.append(w)

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

Submission status: Accepted

Solution code:
a = int(input())
b = []
ppp = 0
for i in range(a):
	b.append(input())
	y = list(b[-1])
	s = y[0]
	e = y[-1]
	if i == 0:
		n = e
	else:
		for j in range(len(b)-1):
			if b[-1] == b[j]:
				ppp = 1
			if j == len(b)-2:
				yy = list(b[j])
				ss = yy[0]
				ee = yy[-1]
				if ee != s:
					ppp = 1
	if ppp == 1:
		break
if ppp == 1:
	print("No")
else:
	print("Yes")

Submission status: Accepted

Solution code:
import sys

N = int(input())

arr = []

arr.append(input())

for i in range(1,N):
    s = input()
    if s in arr:
        print("No")
        sys.exit()
    else:
        if arr[i-1][-1:] != s[0]:
            print("No")
            sys.exit()

        arr.append(s)

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input())
ws = [input() for _ in range(n)]
flg = True

if len(ws) == len(set(ws)):
    for i in range(1, n):
        if ws[i][0] != ws[i-1][-1]:
            flg = False
else:
    flg = False


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

Submission status: Accepted

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

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

words = set()

res = True
char = ''

for word in w:
    if word in words:
        res = False
        break
    if char != '' and word[:1] != char:
        res = False
        break
    words.add(word)
    char = word[-1:]


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

Submission status: Accepted

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

Submission status: Accepted

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


count = 0


#重複判定


for i in range(1, N):
    if W[i][0] != W[i - 1][-1]:
        count += 1
        break

W.sort()
for i in range(N - 1):
    if W[i] == W[i + 1]:
        count += 1
        break

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

else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W_list = [input() for _ in range(N)]
appeared_words = set()

previous_word = W_list[0]
appeared_words.add(previous_word)
for word in W_list[1:]:
    if previous_word[-1] != word[0]:
        print("No")
        exit(0)
    elif word in appeared_words:
        print("No")
        exit(0)
    else:
        previous_word = word
        appeared_words.add(word)
else:
    print("Yes")

Submission status: Accepted

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

isOK = True
for i in range(N):
  word = input()
  if word in words:
    print("No")
    isOK = False
    break
  if len(words) > 0:
    if words[-1][-1] != word[0]:
      print("No")
      isOK = False
      break
  words += [word]


if isOK:
  print("Yes")

Submission status: Accepted

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

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

def judge(xs):
    s = set()

    for x, y in zip(xs, xs[1:]):
        s.add(x)
        if y in s:
            return False
        if x[-1] != y[0]:
            return False

    return True

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8
#
    
def main(n, m):
    for i in range(n - 1):
        if m[i][-1] != m[i+1][0]:
            # print('No {} {} {}'.format(i, m[i][-1], m[i+1][0]))
            print('No')
            return
        
    if len(set(m)) != len(m):
        # print(len(check), len(m))
        print('No')
        return

    print('Yes')
    
        
if __name__ == '__main__':
    try:
        n  = int(input().strip())
        moji = []
        for i in range(n):
            moji.append(str(input().strip()))
        main(n, moji)
    except EOFError:
        pass

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
if __name__=='__main__':
    N = int(input())
    WORDs = [input() for i in range(N)]
    for i in range(N-1):
        if not WORDs[i][-1] == WORDs[i+1][0]:
            print("No")
            break;
    else:
        if len(WORDs) == len(set(WORDs)):
            print("Yes")
        else:
            print("No")

Submission status: Accepted

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

Submission status: Accepted

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

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

#1
Wi_set = set(Wi)
if len(Wi) != len(Wi_set):
    print('No')
    exit()

#2
tail = ""
for W in Wi:
    if tail != "":
        if tail != W[0]:
            print('No')
            exit()
    tail = W[-1]

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

t = str(input())
t_old = t[-1]
cc = 0
word = [t]

for i in range(N-1):
  t = str(input())
  t_new = t[0]
  if t_new == t_old:
    if t in word:
      cc += 1
      break
    else:
      t_old = t[-1]
      word.append(t)
  else:
    cc +=1
    break

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

Submission status: Accepted

Solution code:
N = int(input())
words = []
flag = 0

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

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

Submission status: Accepted

Solution code:
n = int(raw_input())
a = []
for i in range(n):
  a.append(raw_input())
b = set(a)
c = len(b)
d = len(a)
ans = []
if c == d:
  for i in range(n-1):
    x = a[i]
    y = a[i+1]
    z = x[-1]
    w = y[0]
    if z == w:
      ans.append(1)
    else:
      ans.append(0)
  if ans.count(1)==n-1:
    print "Yes"
  else:
    print "No"
else:
  print "No"

Submission status: Accepted

Solution code:
n = int(input())
ls = [input()]
c = 'Yes'

for i in range(1,n) :
   a = input()
   if a in ls :
      c = 'No'
   elif ls[i-1][len(ls[i-1])-1] != a[0] :
      c = 'No'
   ls.append(a)

print(c)

Submission status: Accepted

Solution code:
import math
import sys
#mod = 998244353
#sys.setrecursionlimit(100000)


il = []
for line in sys.stdin:
    il.append(line.strip())

N = int(il[0])
il = il [1:]

def main():
    if N != len(set(il)):
        print("No")
        return
    temp_w = None
    for w in il:
        if temp_w != None:
            if temp_w[-1] != w[0]:
                print("No")
                return
        temp_w = w
    print("Yes")
main()