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())
W=[]
for _i in range(N):
    W.append(input())
if(sorted(W)!=sorted(list(set(W)))):
    print("No")
else:
    for i in range(len(W)-1):
        if(W[i][-1]!=W[i+1][0]):
            print("No")
            break
    else:
        print("Yes")

Submission status: Accepted

Solution code:
a = int(input())
strings =[input() for i in range(a)]

b = 0
c = 1
#finish = strings[b][-1:]
#start = strings[c][0:1]

if len(strings) == len(set(strings)):
    while c <= a - 1:
        finish = strings[b][-1:]
        start = strings[c][0:1]
        if finish == start:
            b += 1
            c += 1
            if c == a:
                print("Yes")
        else:
            print("No")
            break
else:
    print("No")

Submission status: Accepted

Solution code:
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:
import sys
if __name__ == '__main__':
    N = int(input())
    W = [str(input()) for _ in range(N)]
    if len(W) != len(set(W)):
        print('No')
        sys.exit(0)
    for i in range(1,N):
        if W[i-1][-1] != W[i][0]:
            print('No')
            sys.exit(0)
    print('Yes')

Submission status: Accepted

Solution code:
s = set()
pv = ""

fail = False
N = input()
for _ in xrange(N):
    w = raw_input()
    if w in s or (pv and w[0] != pv[len(pv)-1]):
        fail=True
        break
    s.add(w)
    pv = w
if fail:
    print "No"
else:
    print "Yes"

Submission status: Accepted

Solution code:
n=int(input())
w1=input()
detalist={w1}
last=w1
flag=True
for _ in [0]*(n-1):
    wi=input()
    if wi in detalist or wi[0] != last[-1]:
        flag=False
        break
    last=wi
    detalist.add(wi)
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

tmpW = input()
past = set()
past.add(tmpW)
flag = True
for i in range(N - 1):
    W = input()
    if(tmpW[-1:] != W[0:1]):
        flag = False
    elif(W in past):
        flag = False
    tmpW = W

    past.add(W)
    # print(past)

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

Submission status: Accepted

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

for n in range(N):
    a = input()
    l.append(a)

l_uniq = list(set(l))

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

Submission status: Accepted

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

    r = input()
    s = set()
    s.add(r)
    r = r[-1]
    for i in range(n - 1):
        w = input()
        if w in s or r != w[0]:
            print('No')
            return
        s.add(w)
        r = w[-1]
    print('Yes')

main()

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
l = list(set(w))
if len(l) != n:
    print("No")
    quit()
a = w[0][-1]
for i in range(1,n):
    if a != w[i][0]:
        print("No")
        quit()
    a = w[i][-1]
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = "Yes"

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

if (len(W) != len(set(W))):
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
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(input())
tango = []
for i in range(n):
    tango.append(list(input()))
    
rule1 = True
rule2 = True

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

if not is_unique(tango):
    rule2 = False
    
if rule1 and rule2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

bigram = [(w[i-1], w[i]) for i in range(1, len(w))]
valid  = len(set(w)) == len(w) and \
         all(a[-1] == b[0] for a, b in bigram)

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

Submission status: Accepted

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

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

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

    tail = w[-1]

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

W = []
Se = set()
for i in range(N):
  st = input()
  W.append(st)
  Se.add(st)
  
if len(Se) != N:
  print("No")
  exit(0)

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

print("Yes")

Submission status: Accepted

Solution code:
"""
B - Shiritori
しりとりを判定
条件は、
まだ発言なし
頭とお尻一致
"""

N = int(input())

says = []
for part in range(N):
    says.append(input())

says_unique = []
for say in says:
    # 単語重複
    if say in says_unique:
        print("No")
        break
    
    
    if len(says_unique) == 0:
        says_unique.append(say)
    else:
        if say[0] == says_unique[-1][-1]:
            says_unique.append(say)
        else:
            print("No")
            break
else:
    print("Yes")

Submission status: Accepted

Solution code:
#abc333b
import sys

n=int(raw_input())
s=[]
for i in xrange(n):
 s.append(raw_input())
if len(s)!=len(set(s)):
 print 'No'
 sys.exit()
for i in xrange(n-1):
 if s[i][-1]!=s[i+1][0]:
  print 'No'
  sys.exit()
print 'Yes'

Submission status: Accepted

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

if len(word) > len(set(word)):
    print('No')
else:
    success = True
    for i in range(N-1):
        if word[i][-1] != word[i+1][0]:
            success = False
            print('No')
            break
    if success:
        print('Yes')

Submission status: Accepted

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

words.append(input())
ans = True
for _ in range(N-1):
    w = input()
    l = words[-1]
    ans &= (not w in words)
    ans &= (w[0] == l[-1])
    words.append(w)

print(["No", "Yes"][ans])

Submission status: Accepted

Solution code:
from itertools import tee
N = int(input())
w0, w1 = tee((input() for _ in range(N)), 2)

words = {next(w1)}
flag = 'Yes'
for a,b in zip(w0,w1):
  if a[-1] != b[0] or b in words:
    flag = 'No'
  words.add(b)

print(flag)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W = []
flag = "Yes"
last_chara = ''
for i in range(N):
  now_W = input()
  www = list(now_W)
  if i != 0:
    if www[0] != last_chara:
      flag = "No"
      break
  if now_W in W:
    flag = "No"
    break
  W.append(now_W)
  last_chara = www[-1]
print(flag)

Submission status: Accepted

Solution code:
N = int(input())
s = set()
pr = None
ok = 1
for i in range(N):
    w = input()
    if pr and pr != w[0]:
        ok = 0
    if w in s:
        ok = 0
    pr = w[-1]
    s.add(w)
print('Yes'*ok or'No')

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for _ in range(n)]
valid = len(w) == len(set(w))
for i in range(1, n):
    valid &= w[i][0] == w[i - 1][-1]
print('Yes' if valid else 'No')

Submission status: Accepted

Solution code:
print("No" if (lambda w:(sum([w.count(s)-1 for s in w])) or sum([w[i][0] != w[i-1][-1] for i in range(1,len(w))]))([input() for i in range(int(input()))]) else "Yes")

Submission status: Accepted

Solution code:
print("No" if (lambda w:(sum([w.count(s)-1 for s in w])) or sum([1-(w[i][0] == w[i-1][-1]) for i in range(1,len(w))]))([input() for i in range(int(input()))]) else "Yes")

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for i in range(n)]
flag=True
for s in w:
    if w.count(s) > 1:
        flag = False
for i in range(1,n):
    if w[i][0] != w[i-1][-1]:
        flag = False
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
N = int(input())
s = set()
p = input()
s.add(p)
valid = True
for i in range(1, N):
    t = input()
    if(t in s or p[-1] != t[0]):
        valid = False
    p = t
    s.add(p)
print("Yes" if valid else "No")

Submission status: Accepted

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

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
  if c>0:print("No")
  else:print("Yes")

Submission status: Accepted

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

count=0

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

if len(set(word)) != len(word):
    count += 1

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

Submission status: Accepted

Solution code:
#encoding utf-8

n = int(input())
words = [0]*n
for i in range(n):
    words[i] = str(input())

state = 1

for i in range(n-1):
    # print(list(words[i])[-1],list(words[i+1])[0])
    if list(words[i])[-1] == list(words[i+1])[0]:
        state = 1
    else:
        state = 0
        break

if len(list(set(words))) < n:
    state = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
word_list = [input() for _ in range(n)]
flag_count = 0
for word in word_list:
    count = 0
    count = word_list.count(word)
    if count == 1:
        if word_list.index(word) != 0:
            if word[0] == last_string:
                flag_count += 1
    last_string = word[-1]
if flag_count == n-1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
flg=True
se=set()
for i in range(n):
  s=input()
  if s in se:
    flg=False
  se.add(s)
  if not i:
    f,b=s[0],s[-1]
  else:
    if s[0]!=b:
      flg=False
    f,b=s[0],s[-1]
if flg:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
l = []
ans = 'Yes'
for i in range(N):
    w = input()
    if w in l:
        ans = 'No'
        break
    l.append(w)
    if i == 0:
        continue
    if l[i-1][-1] != l[i][0]:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
cnt = int(input())
ans = 'Yes'
pw = input()
already = set()
already.add(pw)
for i in range(1, cnt):
    nw = input()
    if pw[-1] != nw[0] or nw in already:
        ans = 'No'
        break
    else:
        pw = nw
        already.add(pw)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
W = str(input())
gobi = W[-1]
List = []
List.append(W)
a = True
for i in range(N-1):
  W = str(input())
  if gobi == W[0] and not(W in List):
    List.append(W)
    gobi = W[-1]
    continue
  else:
    a = False
    break
if a == True:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())

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

WS = set(WL)

R = 'Yes'
if len(WL) == len(WS):
    for w1, w2 in zip(WL[:-1], WL[1:]):
        if w1[-1] != w2[0]:
            R = 'No'
            break
else:
    R = 'No'

print(R)

Submission status: Accepted

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

flg = True
for i in range(n - 1):       
    if w[i][-1] != w[i + 1][0]:
        flg = False
        break
for i in range(n):
    for j in range(i):
        if w[i] == w[j]:
            flg = False
            break
    if not flg:
        break
    
print('Yes' if flg else 'No')

Submission status: Accepted

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

def func(N, words):
    if (len(words) != len(set(words))):
        return "No"
    
    for n in range(N-1):
        if words[n][-1] != words[n+1][0]:
            return "No"
    else:
        return "Yes"

print(func(N, words))

Submission status: Accepted

Solution code:
L=[input()for x in' '*int(input())];print('YNeos'[any(i[-1]!=j[0]*L.count(i)for i,j in zip(L,L[1:]))::2])

Submission status: Accepted

Solution code:
N=int(input())
W=[]
count=0
for i in range(N):
	w=str(input())
	W.append(w)
for i in range(N):
	c=0
	for j in range(N):
		if W[i]==W[j]:
			c=c+1
		if c>=2 and count==0:
			print("No")
			count=1
for i in range(N-1):
	s=0
	for j in W[i+1]:
		s=s+1
		if s==1:
			t=j
		for k in W[i]:
			r=k
	if t!=r and count==0:
		print("No")
		count=2
if count==0:
	print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
word = []
for i in range(N):
    word.append(str(input()))
flag = True
# 最初の文字列と最終文字列を比べる
# 同じならYES,違うならNo
for i in range(N):
    if i != N - 1:
        if word[i][-1] != word[i + 1][0]:
            flag = False

for i in range(N):
    searchWord = word[i]
    for k in range(N):
        if i != k and searchWord == word[k]:
            flag = False
# 同じならYES, 違うならNo
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
L=[input()for x in' '*int(input())];print('YNeos'[any(i[-1]!=j[0]*(L.count(i))for i,j in zip(L,L[1:]))::2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=[input() for i in range(N)]
ans='Yes'
if len(set(S))!=N:
    ans='No'
for i in range(N-1):
    if S[i][len(S[i])-1]!=S[i+1][0]:
        ans='No'
print(ans)

Submission status: Accepted

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

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

else:
    print("No")

Submission status: Accepted

Solution code:
N=int(input())
S=[input() for i in range(N)]
ans='Yes'
if len(set(S))!=N:
    ans='No'
for i in range(N-1):
    if S[i][len(S[i])-1]!=S[i+1][0]:
        ans='No'
print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
  
  flag = 1
  
  wordNum = int(input())
  wordAll = []

  for i in range(wordNum) :

    word = input()
    wordAll.append(word)
    wordLen = len(word)
    
    if i > 0 and wordLast != word[0]:
      flag = 0
      break
    
    
    for j in range(len(wordAll)-1):
      if wordAll[j] == word:
        flag = 0
        break
    
    
    wordLast = word[wordLen - 1]

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

Submission status: Accepted

Solution code:
N=int(input())
def x(N):
    lis= []
    for i in range(N):
        lis.append([])
    return lis
W=x(N)
W[0]=input()
flag=1
a=list(W[0])
start=a.pop()
def panduan():
    for i in range(1,N):
        W[i]=input()
        global flag
        for each in range(i):
            if W[i]==W[each]:
                flag=0
        a=list(W[i])
        start=a.pop(0)
        if flag!=0 and W[i-1].endswith(start):
            flag=1
        else:
            flag=0
panduan()
if flag==1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for i in range(N):
    Wi = input()
    if i != 0 and (Wi in W or W[-1][-1] != Wi[0]):
        flg = True
    W.append(Wi)

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

Submission status: Accepted

Solution code:

def has_duplicated_elem(word_list):
    if len(list(set(word_list))) == len(word_list):
        return False
    else:
        return True


def break_shiritori_rule(word_list):
    for i,word in enumerate(word_list):
        
        if i+1 == len(word_list):
            return False
        if word[-1] == word_list[i+1][0]:
            continue
        else:
            return True
    else:
        return False

num = int(input())
word_list = []
for i in range(num):
    word_list.append(input())

if has_duplicated_elem(word_list) or break_shiritori_rule(word_list):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a = []
flag = 1
before = ""
def is_unique(seq):
    return len(seq) == len(set(seq))
for i in range(n):
    a1 = input()
    a.append(a1)
    if i == 0:
        before = a1[len(a1)-1]
        continue
    if before != a1[0]:
        flag = 0
    before = a1[len(a1)-1]
if is_unique(a) == False:
    flag = 0
if flag==0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
 
n = int(input())
l = []
p = None
 
for i in range(n):
  s = input()
  if s not in l and (p == None or p[-1:] == s[:1]):
    l.append(s)
    p = s
  else:
    print("No")
    sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
words=[input() for _ in range(n)]
distinct_words=set(words)
if(len(words)==len(distinct_words) and
   all(pword[-1]==nword[0] for pword,nword in zip(words[:-1],words[1:]))):
   print('Yes')
else:
   print('No')

Submission status: Accepted

Solution code:
n = int(input())

old = None
w = []

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

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

old = None
w = []

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

print("Yes")

Submission status: Accepted

Solution code:
#coding: utf-8
import sys
N = int(input())
words = [input() for w in range(N)]

i = 0
if len(set(words)) != len(words):
    print("No")
    sys.exit()
else:
    while i < N-1:
        if words[i][-1] != words[i+1][0]:
            print("No")
            sys.exit()
        i += 1
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
a = [input() for i in range(N)]
 
for num in range(N):
  if num > 0:
    if a[num] in a[:num-1]:
    	print('No')
    	break
  if num < N-1:
    if a[num][-1] != a[num+1][0]:
    	print('No')
    	break
  if num == N-1:
    print('Yes')

Submission status: Accepted

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

for i in range(N-1):
    if W[i+1][0]!=W[i][-1]:
        r = r+1
for i in range(N):
    for p in range(N):
        if W[i]==W[p]:
            r = r+1
if r == N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N=int(input())
W=[input() for i in range(N)]
res = (len(set(W))==N)
for i in range(N-1):
    res &= W[i][-1] == W[i+1][0]
if res:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
L=[input()for x in' '*int(input())];b=0;p=L[0]
for i in L[1:]:b|=p[-1]!=i[0];p=i
print('YNeos'[len(set(L))<len(L)or b::2])

Submission status: Accepted

Solution code:
# N個の改行のある文字列を取得
N = int(input())
W = []
for i in range(N):
    W.append(str(input()))
#print(len(W))

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

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

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
S = set(W)
p = 0
if (len(W) != len(S)):
  print('No')
else:
  for k in range(N-1):
    a = W[k]
    b = W[k+1]
    if (a[len(a)-1] == b[0]):
      p += 1
    else:
      p += 0
  if (p == N-1):
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
def spaceinput():
    return list(map(int,input().split(" ")))



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

done.append(words[0])
for i in range(1,N):
    if words[i-1][-1]!=words[i][0]:
        print("No")
        break

    if words[i] in done:
        print("No")
        break

    done.append(words[i])
    if i==N-1:
        print("Yes")

#print(done)
#print(words)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=[]
for i in range(0,n):
    a.append(input())
d=collections.Counter(a)
flag=0
for i in a:
    if d[i]>1:
        flag=1
        break
if flag==1:
    print("No")
else:
    l=len(a[0])
    s=a[0]
    t=s[l-1]
    flag=0
    for i in range(1,n):
        s=a[i]
        m=s[0]
        if m!=t:
            flag=1
            break
        s=a[i]
        l=len(s)
        t=s[l-1]
    if flag==1:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
input_lines = int(input())
tango=[]
lastchar = ''
for i in range(input_lines):
    s = input().rstrip()
    if len(lastchar) > 0 and not s[0] in lastchar or s in tango:
        print('No')
        break
    tango.append(s)
    lastchar = s[-1]
else:
    print('Yes')

Submission status: Accepted

Solution code:
strings = []
stringed = " "
flag = 0

num = int(input())

for i in range(num):
    string = input()
    if string[0] != stringed[-1] and i != 0:
        flag = 1
    for st in strings:
        if st == string:
            flag = 1
    if flag == 1:
        break
    stringed = string
    strings.append(string)

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
   A.append(input())
S = 0
for i in range(N-1):
    if A[i][-1] == A[i+1][0]:
        S += 1
B = 0
for i in range(N):
    for j in range(N):
        if A[i] == A[j]:
            B += 1
        else:
            B += 0

if S == N-1 and B == N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
x = 0
listen = []
first = []
last = []
n = int(input())
for i in range(n):
 listen.append(input())
 first.append(listen[i][:1])
 last.append(listen[i][-1:])
 if i > 0:
  if first[i] != last[i-1]:
   x = 1
 for k in range(i):
  if listen[k] == listen[i]:
   x = 1
if x == 0:
 print ('Yes')
else:
 print ('No')

Submission status: Accepted

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

num = int(input())
x = [str(input())]

for i in range(num-1):
    # 先頭の文字は直前に発言した単語の末尾の文字と一致するか
    saigo = x[-1]
    saigoMoji = saigo[-1]

    verStr = str(input())
    tugiMoji = verStr[0]

    if saigoMoji != tugiMoji:
        print("No")
        exit()

    #その単語はまだ発言していない単語であるか
    if verStr in x:
        print("No")
        exit()
    else:
        x.append(verStr)
print("Yes")

Submission status: Accepted

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

A = set()


for i, s in enumerate(S):
    if s in A or (i - 1 >= 0 and S[i-1][-1] != s[0]):
        print('No')
        exit()
    A.add(s)

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
for i in range(n):
  if i == n-1:
    print("Yes")
  elif  w[i][-1] != w[i+1][0] or w.count(w[i]) != 1:
    print("No")
    break

Submission status: Accepted

Solution code:
n = int(input())
words = ['' for i in range(n)]
flag = True
for i in range(n):
    word = input()
    if i == 0:
        words[i] = word
    elif word not in words and words[i-1][-1] == word[0]:
        words[i] = word
    else:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Ans = True

for i in range(N):
    a =input()
    L.append(a)

for j in range(N-1):
    if list(L[j])[-1] != list(L[j+1])[0]:
        Ans = False

for k in range(N):
    if L[k] in L[:k]:
        Ans = False
        
if Ans == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

A = int(input())

wordlist = []
tmplist = []
lastword = ""

for b in range(A):
    wordlist.append(input())
    tmpstr = wordlist[-1]

    if(lastword != ""):
        if(tmpstr[0] != lastword):
            print("No")
            sys.exit()
    lastword = tmpstr[-1]

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

Submission status: Accepted

Solution code:
n=int(input())
a=input()
s={a}
r="Yes"
for i in range(1,n):
  b=input()
  if a[-1] != b[0] or b in s:
    r="No"
    break
  a=b
  s.add(b)
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n = int(input())
words = [input()]
for _ in range(n-1):
    word = input()
    if word in words or word[0] != words[-1][-1]:
        print("No")
        break
    else:
        words.append(word)
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

	for i, word in enumerate(W):
		if i != 0:
			if word[:1] != W[i-1][-1:]:
				return False
	if len(W) != len(set(W)):
		return False

	return True


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

Submission status: Accepted

Solution code:
n=int(input())
flag='OK'
maeWord=''
nowWord=''
wordList=[]

for i in range (1,n+1):
  if(i==1):
      maeWord=input()
      wordList.append(maeWord)
  else:
    nowWord=input()
    if(nowWord in wordList):
      flag='NG'
    
    if(list(maeWord)[-1] != list(nowWord)[0]):
      flag='NG'
      
    maeWord=nowWord
    wordList.append(maeWord)
    
if(flag=='NG'):
  print('No')
else:
  print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

atama=[]
oshiri=[]

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



for i in s:
    atama.append(i[0])
    oshiri.append(i[-1])



oshiri=oshiri[-1:]+oshiri[:-1]

atama.pop(0)
oshiri.pop(0)

if oshiri==atama and is_unique(s)==True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def is_unique(seq):
    return len(seq) == len(set(seq))
N = int(input())
a = []
for i in range(N):
    a.append(input())
#print a # [a1, a2, a3, ..., aN]
flag = True

if is_unique(a) == False:
  flag = False
  
for i in range(1,N):
    s1 = a[i-1]
    s2 = a[i]
    s3 = s1[len(s1)-1]
    s4 = s2[0]
    if s3 != s4:
      flag = False
      
if flag == False:
  print("No")
else:
  print("Yes")