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=[]
w.append(input())
c=0
for i in range(n-1):
    s=input()
    if s not in w and w[i][len(w[i])-1] == s[0]:
        c+=1
        w.append(s)
    else:
        break


if c==n-1:
    print("Yes")
else:
    print ("No")

Submission status: Accepted

Solution code:
n = int(input())
words = []
won = True
for i in range(n):
    new_word = input()
    if i > 0 and won:
        if new_word in words or new_word[0] != words[i-1][len(words[i-1])-1]:
            won = False
    words.append(new_word)

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

Submission status: Accepted

Solution code:
n = int(input())
a = [input() for i in range(n)]
ans = 'Yes'
for i in range(n):
    if a.count(a[i])!=1:
        ans = 'No'
        break
for i in range(n-1):
    if a[i][-1] != a[i+1][0]:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

N = int(input())

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

C = collections.Counter(words)
if C.most_common()[0][1] > 1:
    print('No')
    exit()

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

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
L = list()
ans = ''
for a in W:
  if W.count(a) >= 2:
    ans = 'No'
    break
  elif L == []:
    a = list(a)
    a.reverse()
    L.append(a[0])
  else:
    a = list(a)
    if a[0] == L[0]:
      a.reverse()
      L[0] = a[0]
      ans = 'Yes'
    else:
      ans = 'No'
      break
print(ans)

Submission status: Accepted

Solution code:
def is_valid(ws):
    n = len(ws)
    for i in range(1, n):
        if ws[i-1][-1] != ws[i][0]:
            return False
    return len(set(ws)) == n

def solve(ws):
    return "Yes" if is_valid(ws) else "No"

assert solve(["hoge","english","hoge","enigma"]) == "No"
assert solve(["basic","c","cpp","php","python","nadesico","ocaml","lua","assembly"]) == "Yes"
n = input()
ws = [raw_input() for i in range(n)]
print solve(ws)

Submission status: Accepted

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

for i in range(1, len(w)):
    if w[i][0] != w[i - 1][-1]:
        print('No')
        exit()
    else:
        for j in range(0, i):
            if w[j] == w[i]:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:

import collections
a=int(input())
l=[]
c=0
for x in range(a):
    l.append(input())
if len(set(l))!=a:
    print("No")
else:
    k=l.pop(0)[-1]
    for x in l:
        if k==x[0]:
            k=x[-1]
            c+=1
    if c+1==a:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
key = input()
x = {}
x[key] = None
s = list(key)[-1]
flag = True
for i in range(n - 1):
    xx = input()
    if xx not in x and s == list(xx)[0]:
        x[xx] = None
        s = list(xx)[-1]
    else:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys


def main():
    n = int(input())
    s = set()

    p = input()
    s.add(p)

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

        if w in s or w[0] != p[-1]:
            print('No')
            return
        
        p = w
        s.add(w)
    
    print('Yes')
        

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input()
a = []
for i in range(n):
	a.append(raw_input())
for i in range(1, n):
	if a[i - 1][-1] != a[i][0]:
		print 'No'
		exit()
if len(set(a)) != n:
	print 'No'
	exit()
print 'Yes'

Submission status: Accepted

Solution code:
import sys

n=int(input())
w=[]
flag=True
for i in range(n):
    w+=[input()]
if(n!=len(set(w))):
    print('No')
    sys.exit()

f=w[0][0]
e=w[0][-1]
for i in range(1,n):
    if(e==w[i][0]):
        e=w[i][-1]
        continue
    else:
        flag=False
        break
    
if(flag):print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
import sys
n=int(input())
sp=input()
l=set()
for _ in range(n-1):
    sn=input()
    if (sn in l) or (sp[-1]!=sn[0]):
        print('No')
        sys.exit()
    l.add(sp)
    sp=sn
print('Yes')

Submission status: Accepted

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

w1 = input()
L.append(w1)
for i in range(N - 1):
	w2 = input()
	if L.count(w2) == 1:
		judge = "No"
		break
	elif w1[-1] != w2[0]:
		judge = "No"
		break
	else:
		L.append(w2)
		w1 = w2

print(judge)

Submission status: Accepted

Solution code:
n = int(input())
s = set()
prev = "!"
for i in range(n):
    x = input()
    if i and prev[-1] != x[0]:
        print("No")
        exit(0)
    prev = x
    s.add(x)
print("Yes" if len(s) == n else "No")

Submission status: Accepted

Solution code:
N = int(input())

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

endOneWord = W[0][0]

for i in range(N):
    # 重複チェック
    if(W.count(W[i]) > 1):
        print("No")
        exit()

    # 最初と最後の文字が一致するかチェック
    if(endOneWord != W[i][0]):
        print("No")
        exit()

    endOneWord = W[i][-1]

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
w=[input()for i in range(n)]
w_set=set(w)
if len(w_set)!=n:
    print("No")
    exit()
for i in range(1,n):
    if 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)]
ans = "Yes"

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
word=[]
word.append('０')
for i in range(1,n+1):
    word.append(input())
    for j in range(0,i):
        if word[j]==word[i]:
            print('No')
            sys.exit()
        else:
            j+=1
    if (i>1)& (word[i-1][len(word[i-1])-1]!=word[i][0]):
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys

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

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

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
W = ['']*N
ans = True
for i in range(N):
    W[i] = input()
    if i >= 1 and W[i-1][-1] != W[i][0]:
        ans = False
        
if len(set(W)) != len(W):
    ans = False

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

Submission status: Accepted

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


def get_line():
    return input()


def get_tokens():
    return get_line().split()


def get_ints():
    return [int(_) for _ in get_tokens()]


def main():
    n, = get_ints()
    w = []
    for i in range(n):
        v = get_line()
        w.append(v)

    s = set()
    ok = True
    s.add(w[0])
    last_v = w[0]
    for i in range(1, n):
        v = w[i]
        if v[0] != last_v[-1]:
            ok = False
        if v in s:
            ok = False
        s.add(v)
        last_v = v

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


if __name__ == '__main__':
    main()

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][-1]!=S[i+1][0]:
        ans='No'
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

x = 0

for i in range(n-1):
	if w[i][len(w[i])-1] != w[i+1][0] or w.count(w[i])!=1:
		x +=1
if x==0:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
import sys
#N 単語数を登録。そのあと、wordをいんぷｔ（）
c=[]
N=int(input())
word = [input() for l in range(N)]
#ようやく文字を区切れた。。。同じことやったと思うけどな。。。
#print(word[0])
#print(word[1])


#最初のリストの最後文字と次の文字の最初文字が同じかチェック
for i in range(0,N-1):
    letter1=list(word[i])
#    print(letter1)
    letter2=list(word[i+1])
#    print(letter2)
#    print(i)
    if letter1[-1]==letter2[0]:
#        print("OK")
        continue
    else:
        print("No")
        sys.exit()
#文字が同じものがないかチェック
for i in range(N):
    for j in range(N):
#        print(word[i],word[j])
        if i==j:
            continue
        elif word[i]==word[j]:
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
#109B
N=int(input())
W=[]
flag=0
for i in range(N):
    W.append(input())
for i in range(N-1):
    if W[i][-1]!=W[i+1][0]:
        flag=1
        break
if len(set(W))!=N:
    flag=1
if flag==1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
# Shiritori
n = int(input())
li = []
for i in range(n):
    li.append(list(input()))
for j in range(n-1):
    if li[j][-1] == li[j+1][0]:
        for k in range(j):
            if li[j] == li[k] or li[-1] == li[k]:
                print('No')
                exit()
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
siritori_list = list()
for i in range(n):
    siritori_list.append(input())
for ii in range(n):
    word = siritori_list.pop(0)
    if siritori_list:
        if not(word[-1] == siritori_list[0][0]) or word in siritori_list:
            print("No")
            break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
L =[]
count = 0
for i in range(N):
    Str = str(input())
    L.append(Str)

for i in range(N):
    for k in range(N):
        if L[i] == L[k] and i != k:
            count += 1
            break

for i in range(N):
        if i < N-1:
            if L[i][len(L[i])-1] != L[i+1][0]:
                count += 1


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

Submission status: Accepted

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

import collections

for i in range(n):
    if i < n-1:
        if w[i][-1] == w[i+1][0]:
            a = a
        else:
            a = 0

c = collections.Counter(w)
if c.most_common()[0][1] > 1:
    a = 0
else:
    a = a

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

Submission status: Accepted

Solution code:
import sys

N = int(input())

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

ret = "Yes"
# 重複チェック
dict = {}
for w in W:
    if w in dict:
        dict[w] += 1
        if dict[w] >= 2:
            # print("Duplicated!")
            ret = "No"
    else:
        dict[w] = 1
# print(dict)

if ret != "No":
    current = W[0]
    for i in range(1, N):
        if (current[-1] != W[i][0]):
            # print("Not Connected: " + current + "," + W[i])
            ret = "No"
            break
        current = W[i]

print(ret)

Submission status: Accepted

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

flag = "Yes"

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

if len(W) != len(set(W)):
    flag = "No"
    
print(flag)

Submission status: Accepted

Solution code:
shi_num = int(input())
words = [input() for _ in range(shi_num)]
result = [words[0]]
last_alph = words[0][-1]
for word in words[1:]:
    if (word not in result) and word[0] == last_alph:
        last_alph = word[-1]
        result.append(word)
    else:
        break

if len(result) == shi_num:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

if len(set(W)) != 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:
n = int(input())

w = []

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

#print(w)

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

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
words = list(input() for _ in range(N))
done = []
for w in words:
  if len(done) == 0:
    done.append(w)
  else:
    if w in done or (done[-1])[-1] != w[0]:
      print('No')
      exit()
    else:
      done.append(w)
print('Yes')

Submission status: Accepted

Solution code:
def solution(w):
    pre = { }
    cur = w[0]
    pre[cur] = True
    for i in xrange(1, len(w)):
        if cur[-1] != w[i][0]:
            return False
        cur = w[i]
        if cur in pre:
            return False
        pre[cur] = True
    return True

def main():
    n = int(raw_input().strip())
    a = [raw_input().strip() for i in xrange(n)]
    if solution(a):
        print 'Yes'
    else:
        print 'No'

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
W = []
Hantei = True

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

for i in range(n):
    if W.count(W[i]) > 1:
        Hantei = False
        break

for i in range(n-1):
    if W[i][-1] != W[i+1][0]:
        Hantei = False

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

Submission status: Accepted

Solution code:
N=int(input());W=[input()for _ in range(N)];print("No"if len(set(W))!=N or[i[0]for i in W[1:]]!=[i[-1]for i in W[:N-1]]else"Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
s_ = w[0][-1]
for s in w[1:]:
    if w.count(s) != 1 or s[0] != s_:
        print('No')
        exit()
    else:
        s_ = s[-1]
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())


def f():
  used = set()
  prev = input()
  used.add(prev)
  for i in range(n-1):
    word = input()

    if word in used:
      return 'No'
    else:
      used.add(word)
    
    if word[0] == prev[-1]:
      prev = word
      continue
    else:
      return 'No'
    
  return 'Yes'

print(f())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(W)

cnt = 0
for i in range(N-1):
    #print(i)
    if (W[i][-1] == W[i+1][0]):
        #print("yes")
        cnt += 1
    else:
        break

if (len(c.keys())) == N and (cnt == N-1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
n = int(input())
dic=[]
for i in range(n):
    inp = input()
    if inp in dic:
        print("No")
        sys.exit()
    else:
        if len(dic) > 0 and inp[0] != dic[-1][-1]:
            print("No")
            sys.exit()
        dic += [inp]
print("Yes")

Submission status: Accepted

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

flag = 1
if len(set(w)) == n:
    f = w[0][-1]
    for i in range(1, len(w)):
        if f != w[i][0]:
            flag = 0
        f = w[i][-1]
else:
    flag = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
L={}
for i in range(N):
    if i>0:
        prev = t[-1]
    t = input()
    if t in L:
        print("No")
        break
    L[t] = 1
    if i>0:
        if t[0] != prev:
            print ("No")
            break
            
else:
    print ("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = []
ans = 'Yes'
for i in range(n):
    w.append(input())
    if len(w) > 1:
        if w[-2][-1] != w[-1][0]:
            ans = 'No'
            break
if len(w) != len(list(set(w))):
    ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

n = int(input())

words = [str(input()) for _ in range(n)]

_word = str()
able = True

for index, word in enumerate(words):
    if index == 0:
        _word = word
    else:
        if ( word not in words[:index]) & (word[0] == _word[-1]):
            _word = word
        else:
            able = False
            break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
def is_unique2(seq):
    seen = []
    unique_list = [x for x in seq if x not in seen and not seen.append(x)]
    return len(seq) == len(unique_list)

n=int(input())

line=[]

for i in range(n):
    line.append(list(input()))
    
#print(line)
flag=is_unique2(line)
#print(flag)

for i in range(n-1):
    if line[i][-1]!=line[i+1][0]:
        flag=False  #outならfalse

#print(flag)

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

Submission status: Accepted

Solution code:
N = int(input())
s = set()
pre = ""
flag = True
for i in range(N):
    w = input()
    if len(s) == 0:
        pre = w[-1]
        s.add(w)
        continue
    else:
        if w[0] != pre:
            flag = False
        elif w in s:
            flag = False
        else:
            pre = w[-1]
            s.add(w)

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

Submission status: Accepted

Solution code:
n=int(input())
lis=[]
for _ in range(n):
  lis+=[input()]
lis2=list(set(lis))
if len(lis2)!=n:
  print("No")
else:
  correct=True
  i=0
  while correct and i<n-1:
    if lis[i][-1]!=lis[i+1][0]:
      correct=False
    i+=1
  if correct:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
strings = [input()]
judge = 0
for i in range(1, N):
  final_character = strings[i - 1][-1]
  strings.append(input())
  initial_character = strings[i][0]
  if final_character == initial_character:
    continue
  else:
    judge = 1
    break

if len(strings) != len(set(strings)):
  judge = 1
  
if judge == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
#! /usr/bin/python
from sys import stdin
n = int(input())
W = stdin.read().splitlines()
if n != len(set(W)):
    print("No")
    exit()
for i in range(n-1):
    if W[i][-1] != W[i+1][0]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
s_list = []

n = int(stdin.readline().rstrip())

for i in range(n):
    s = stdin.readline().rstrip()
    if i == 0:
        s_shiri = s[-1]
        s_list.append(s)
    else:
        if s[0] == s_shiri:
            s_shiri = s[-1]
            s_list.append(s)
        else:
            print("No")
            exit()
            
s_check =  list(set(s_list))

if len(s_list) == len(s_check):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
words = [ input() for _ in range(n) ]
ans = True
if len(set(words)) != n:
    ans = False
for i in range(n - 1):
    if words[i][-1] != words[i + 1][0]:
        ans = False
print(['No', 'Yes'][ans])

Submission status: Accepted

Solution code:
import sys

n = int(input())

used = []  # 使用した単語
for i in range(n):
    cur = input()
    if i != 0:
        if cur[0] != gobi or cur in used:
            print("No")
            sys.exit()
    used.append(cur)
    gobi = cur[-1]
    
print("Yes")

Submission status: Accepted

Solution code:
def func():
    n = int(input())
    w = []
    for i in range(n):
        w.append(input())
    if len(set(w)) != n:
        print("No")
        return
        
    before = ""
    for wn in w:
        if before != "" and wn[0] != before[-1]:
            print("No")
            break
        before = wn
    else:
        print("Yes")
func()

Submission status: Accepted

Solution code:
"""
A,B = map(int,input().split())
answer = 'Yes'

if A%2 == 0:
	answer = 'No'
if B%2 == 0:
	answer = 'No'
	
print(answer)
"""

N = int(input())
W = list(map(str,[input() for i in range(N)]))

answer = 'Yes'

#重複がないか判定する
ww = set(W)
if len(W) != len(ww):
	answer = 'No'

#前の単語の最後の文字を、listから取り出す→最後の文字を指定で無理矢理取り出す。
#これと、次の単語の文字を比較。
for i in range(1,N):
	wnext = W[i]
	wforword = W[i-1]
	
	if wnext[0] != wforword[len(wforword)-1]:
		answer = 'No'

print(answer)

Submission status: Accepted

Solution code:
n = int(input())

w = []

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

flag = True

if len(w) != len(set(w)):
    flag = False

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

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

Submission status: Accepted

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

res = 'Yes'
temp = []
tail = w[0][0]
for word in w:
    if word in temp:
        res = 'No'
        break

    temp.append(word)

    if tail != word[0]:
        res = 'No'
        break

    tail = word[-1]

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def shiritori(n, string_list):

    if len(string_list)!=len(set(string_list)):
        return False

    for i in range(1,n):
        if string_list[i-1][-1]!=string_list[i][0]:
            return False

    return True


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

    if shiritori(n, string_list):
        print('Yes')
    else :
        print('No')

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    sameFlag = False
    N = int(input())
    words = []
    for i in range(N):
        s = input()
        if(s in words):
            sameFlag = True
        words.append(s)
    if(sameFlag):
        print('No')
        return
    current = ''
    for i in range(N):
        if(i != 0):
            if(words[i][0] != current):
                print('No')
                return
        current = words[i][-1]
    print('Yes')

solve()

Submission status: Accepted

Solution code:
n = int(input())
seq = []
seq.append(str(input()))
count = 1
while count < n:
  seq.append(str(input()))
  if seq[-2][-1] != seq[-1][0]:
    print("No")
    break
  count += 1
else:
  if len(seq) != len(set(seq)):
    print("No")
  else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
words = []
 
for i in range(n):
  word = input()
  if i >= 1:
    if word in words or word[0] != words[-1][-1]:
      print('No')
      break
      
  words.append(word)

else:
  print('Yes')

Submission status: Accepted

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

for i, e in enumerate(A):
    if i == 0: continue
    if A.count(e) != 1 or A[i - 1][-1] != A[i][0]:
        print('No')
        break
    if i == n - 1:
        print('Yes')

Submission status: Accepted

Solution code:
w = []
c = int(raw_input())
for i in xrange(c):
    hatugen = raw_input()
    w.append(hatugen)
last = ''
first = ''
ruled = True
if len(set(w)) != len(w):
    ruled = False
for i in w:
    if i == w[0]:
        last = i[-1]
    else:
        first = i[0]
        if first == last:
            pass
        else:
            ruled = False
        last = i[-1]
print('Yes' if ruled else 'No')

Submission status: Accepted

Solution code:
n = int(input())

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

def shiritori(s):
  if len(s) != len(set(s)):
    return False
  
  for i in range(n-1):
    if s[i][-1] != s[i+1][0]:
      return False
  
  return True

if __name__ == '__main__':
  if shiritori(s):
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
def si():

    n = int(input()) 
    tk = [input() for i in range(n)]
    tu = len(set(tk))
    l =[]
    k = []

 
        
    oo = 0


    while oo < tu:
        t = tk[oo]
        l.append(t[0])
        k.append(t[-1])
        oo += 1
        
    oo = 0


    while oo < tu-1:
        if k[oo] != l[oo+1]:
            return False
        
        oo += 1


    if tu != n:
        return False
    
    return True
    
if si():
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
result = "Yes"
for i in range(1, N):
    if W[i][0] != W[i-1][-1] or W[i] in W[:i]:
        result = "No"
print(result)

Submission status: Accepted

Solution code:
n = int(input())
w = [""] * n 
result = "Yes"

for i in range(n):
    tmp = input()
    if tmp in w:
        result = "No"
    w[i] = tmp 
for i in range(n-1):
    if w[i][-1] == w[i+1][0]:
        pass
    else:
        result = "No"
print(result)

Submission status: Accepted

Solution code:
n = int(input())
list = []
for i in range(n):
    a = input()
    list.append(a)
def is_unique(seq):
    return len(seq) == len(set(seq))

if is_unique(list) == False:
    print('No')

else:
    s = 0
    for k in range(n-1):
        a = list[k]
        b = list[k + 1]
        if a[-1] == b[0]:
            s += 1
        else:
            print('No')
            break
    if (s+1) == n:
        print('Yes')
    else:
        pass

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = list()
for i in range(n):
    a.append(input())
b = list()
for i in range(n):
    if a[i] not in b:
        b.append(a[i])
    else:
        continue
if len(b) != len(a):
    print("No")
    sys.exit()
for i in range(len(b)-1):
    if b[i][-1] == b[i+1][0]:
        pass
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
l = []
e = "abcdefghijklmnopqrstuvwxyz"
ans = "Yes"
for i in range(n):
  w = input()
  if w[0] not in e or w in l : ans = "No" 
  l.append(w)
  e = w[-1]
print(ans)

Submission status: Accepted

Solution code:
import sys

n = int(input())

words = {}
latest = ''

for i in range(n):
    text = input()
    if latest != '':
        if latest[len(latest) -1] != text[0]:
            print("No")
            sys.exit()
    latest = text
    if text in words:
        print("No")
        sys.exit()
    words[text] = 1

print("Yes")

Submission status: Accepted

Solution code:
d = {}

i = int(input())

for m in range(i):
	word = input()
	d[m] = word
for n in range(1, i):
	a = d[n-1]
	b = d[n]
	if a[-1] != b[0]:
		print('No')
		exit()
for x in range (i-1):
	for j in range (x+1, i):
		if d[x] == d[j]:
			print('No')
			exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
d = {}

i = int(input())

for m in range(i):
	word = input()
	d[m] = word
for n in range(1, i):
	h = n - 1
	a = d[h]
	b = d[n]
	if a[-1] == b[0]:
		continue
	else:
		print('No')
		exit()
for x in range (i - 1):
	for j in range (x + 1, i):
		if d[x] == d[j]:
			print('No')
			exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

for i in range(1, N):
    if word[i][0] != word[i - 1][-1] or word.count(word[i]) != 1:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:

N = int(input())

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

for i in range(1, N):
    if word[i][0] != word[i - 1][-1] or word.count(word[i]) != 1:
        print('No')
        exit()

print('Yes')