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

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

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

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

print('Yes')

Submission status: Accepted

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

used.add(W_list[0])
ans = True
for i in range(1, N):
    if W_list[i-1][-1] != W_list[i][0]:
        ans = False
    if W_list[i] in used:
        ans = False
    used.add(W_list[i])

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

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for i in range(n)]
p=list(s[0])[0]
from collections import Counter
c=Counter(s)
if [1 for i in range(n)]!=list(c.values()):
    print("No")
    exit()
else:
    for i in s:
        a=list(i)[0]
        b=list(i)[-1]
        if p==a:
            p=b
        else:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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

for i, word in enumerate(w):
    if i is not 0:
        if word[0] is not w[i-1][-1] or word in history:
            print("No")
            exit()
    history.append(word)
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
words = []
word = ""
for i in range(N):
  moji = input()
  if moji in words:
    print('No')
    exit()
  else:
    if word=="":
      word=moji
      words.append(moji)
    else:
      if word[-1]==moji[0]:
        words.append(moji)
        word=moji
      else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(input())
b=[]
flag=0
for i in range(n):
    s=a[i]
    if i!=0:
        if s[0]!=last:
            flag=1
    last=s[len(s)-1]
    if s in b:
        flag=1
        break
    b.append(s)
    
    
if flag==1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
N=int(input())
w=[]
flag="Yes"

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

if len(set(w))<len(w):
  flag="No"

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

print(flag)

Submission status: Accepted

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

Submission status: Accepted

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

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

    for i in range(n):
        for j in range(i + 1, n):
            if w[i] == w[j]:
                print("No")
                exit()

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

    print("Yes")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

N = int(input())

result = ""

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

if not len(words) == len(set(words)):
    result = "No"
    print(result)
    sys.exit()

for i in range(N-1):
    before = words[i]
    after = words[i + 1]

    if before[-1] == after[0]:
        continue

    else:
        result = "No"
        print(result)
        sys.exit()

result = "Yes"
print(result)

Submission status: Accepted

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

def solve():
	
	for i in range(n): 
		for j in range(i+1,n): 
			if l[i] == l[j]:
				print("No")
				return 

	for i in range(n-1):
		actual = l[i+1]
		next_word = l[i]
		if actual[0] != next_word[len(next_word)-1]:
			print("No")
			return 

	print("Yes")

solve()

Submission status: Accepted

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

flag = "Yes"
N = int(input())
word = input()
list = [word]
for i in range(N - 1):
    word = input()
    if list[i][len(list[i]) - 1] != word[0]:
        flag = "No"
        break
    list.append(word)
if not is_unique(list):
    flag = "No"
print(flag)

Submission status: Accepted

Solution code:
def hasMultiWord(W):
    for i in range(len(W)-1):
            if W[i] in W[i+1:]:
                return True
    return False


def isPrevTailEqualNextHead(W):
    for i in range(1, len(W)):
        if W[i-1][-1] != W[i][0]:
            return False
    return True


def main():
    W = []
    N = int(input())
    for _ in range(N):
        W.append(input())
    print(['No', 'Yes'][not hasMultiWord(W) and isPrevTailEqualNextHead(W)])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections, os, re


n = int(input())

words = set()
last = ''

ans = True

for i in range(n):
    s = input()
    if (i > 0 and last[-1] != s[0]) or s in words:
        ans = False

    words.add(s)


    last = s

print('{}'.format('Yes' if ans else 'No'))

Submission status: Accepted

Solution code:
N = int(input())
ls = []
flag = True
bChar = ""
for n in range(0, N):
  ch = input()
  if n == 0:
    ls.append(ch)
  else:
    if (ch in ls) or (bChar[-1:] != ch[0:1]):
      flag = False
  ls.append(ch)
  bChar = ch
if flag == True:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
il = lambda: list(map(int, input().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
w = ils(n, "input()")
ans = 1
if len(set(w)) != n:
    ans = 0
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        ans = 0
print("Yes" if ans else "No")

Submission status: Accepted

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

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

if len(W) == len(set(W)):
    is_unique = True
else:
    is_unique = False

shiri = True
if is_unique:
    for i in range(N-1):
        shiri = W[i][-1] == W[i+1][0]
        if not shiri:
            break

if shiri and is_unique:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import io
import sys
def solve(lista):    
    listb = []
    hantei = "true"
    for i in lista:
        if i not in listb:
            listb.append(i)
        else:
            hantei = "false"
    for i in range(len(listb)-1):
        if listb[i][-1] != listb[i+1][0]:
            hantei = "false"
    if hantei == "true":
        return("Yes")
    else:
        return("No")
# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line1 = sys.stdin.readline().rstrip()
    lista = []
    for i in range(int(line1)):
        line2 = sys.stdin.readline().rstrip()
        lista.append(line2)
    return (lista)

def main():
    a = readQuestion()
    answer = solve(a)
    print(answer)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve(string):
    ins = string.split("\n")
    if len(set(ins[1:])) < int(ins[0]):
        return "No"
    for _p, _n in zip(ins[1:], ins[2:]):
        if _p[-1] != _n[0]:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    tmp = [str(n)]
    for _ in range(n):
        tmp.append(input())
    print(solve("\n".join(tmp)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
a=int(input())
b=[]
b=[input() for i in range(a)]
    
# 重複        
if len(b) != len(set(b)):
    print("No")
    sys.exit()

for x in range(a):
    if b[x]!=b[a-1]:
        
        if b[x][len(b[x])-1] != b[x+1][0]:
            print("No")
            break


else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = []
Ws = []
first = []
count = 0
for i in range(N):
    W.append(input())
    Ws.append(list(W[i]))
else:
    first.append(len(W))
    first.append(len(set(W)))
    if first[0] != first[1]:
        print("No")
    else:
        for i in range(N-1):
            maxw = len(Ws[i]) - 1
            if Ws[i][maxw] == Ws[i + 1][0]:
                count += 1
        else:
            if count == N - 1:
                print("Yes")
            else:
                print("No")

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")
	exit()

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

print("Yes")

Submission status: Accepted

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

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

success = True

if len(set(words)) != len(words):
    success = False

if success:
    last = words[0][0]
    for word in words:
        if last[-1] != word[0]:
            success = False 
            break
        last = word

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

Submission status: Accepted

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


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

    for i in range(n-1):
        if w[i][-1] != w[i + 1][0] or not is_unique(w):
            valid = False
            break
        else:
            valid = True

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
 
 
def is_unique(seq):
    return len(seq) == len(set(seq))
 
 
def main():
    n = int(input())
    shiri = True
 
    w = []
    for i in range(n):
        w.append(input())
 
    for i in range(n-1):
        if w[i][-1] != w[i + 1][0]:
            shiri = False
            break
 
    if not is_unique(w):
        shiri = False
 
    if shiri:
        print('Yes')
    else:
        print('No')
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ret = "Yes"
if len(Ws) != len(list(set(Ws))):
    ret = "No"
    
for i in range(N-1):
    if Ws[i][-1] != Ws[i+1][0]:
        ret = "No"
    
    
print (ret)

Submission status: Accepted

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

if len(Ws) != len(list(set(Ws))):
    print("No")
    exit(0)

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

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
s=[input()for _ in[0]*n]
f=0
for i in range(1,n):
    f+=s[i-1][-1]!=s[i][0]
print("No"if f or len(set(s))<n else"Yes")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    W = [input() for _ in range(N)]
 
    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]
 
    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math


def main():
    N = int(input())
    W = [input() for _ in range(N)]

    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
pre_w = input()
his = [pre_w]
for i in range(N-1):
    w = input()
    if pre_w[-1] != w[0]:
        print("No")
        break
    elif w in his:
        print("No")
        break
    his.append(w)
    pre_w = w
    if i == N-2:
        print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w0 = str(input())
list = [w0]
count = 0
for i in range(n-1):
  w = str(input())
  list.append(w)
  if len(list) != len(set(list)) or w0[-1:] != w[:1]:
    print("No")
    count = 1
    break
  w0 = w
if count == 0:
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
mojilist = []
ans = "No"
for x in range(n):
    moji = input()
    if moji in mojilist:
        break
    mojilist.append((moji))

if len(mojilist) == n:
    mae = list(mojilist[0])
    for x in range(1, n):
        tugi = list(mojilist[x])
        if mae[-1] != tugi[0]:
            break
        else:
            mae = tugi
        if x == n-1:
            ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
listS = [input() for i in range(N)]
ans = "Yes"
for j in range(1, N):
    if listS.count(listS[j]) == 1 and listS[j - 1][-1] == listS[j][0]:
        continue
    else:
        ans = "No"
        break

print(ans)

Submission status: Accepted

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

rule_length = True
rule_2time = True
rule_startEnd = True

for i in range(N):
    word = input()
    if 1 > len(word) or len(word) > 10:
         rule_length = False
    if word in words:
        rule_2time = False
    if i !=0 and words[-1][-1] != word[0]:
        rule_startEnd = False    
    words.append(word)

if rule_length and rule_2time and rule_startEnd:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
flag = "Yes"
N = int(input())
W = input()
words = [W]
while len(words) < N:
    a = input()
    if W[-1] == a[0] and (a not in words):
        W = a
        words.append(a)
    else:
        flag = "No"
        words.append(a)

    #print(flag,words)

print(flag)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
W = set()
W.add(s)

for i in range(n-1):
  ns = input()
  if s[-1] != ns[0] or (ns in W):
    print('No')
    break
  s = ns
  W.add(ns)
else:
  print('Yes')

Submission status: Accepted

Solution code:
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

arr=[]
for i in range(1,1+n):
    
    arr.append(arr_data[i][0])

chkflg=True
if len(arr)!=len(set(arr)):
    chkflg=False
    
for i in range(0,n-1):
    
    if arr[i][-1]!=arr[i+1][0]:

        chkflg=False
        break
        
print("Yes" if chkflg else "No")

Submission status: Accepted

Solution code:
num_word = int(input())
word_list=[]
word_list = [str(input()) for i in range(num_word)] 
 
word_list_temp=[]
for j in range(len(word_list)):
  if j == len(word_list)-1:
    print ("Yes")
    break
  else:
    old_word=word_list[j]
    old_word_sep=list(old_word)
    word_list_temp.append(old_word)
    new_word=word_list[j+1]
    new_word_sep=list(word_list[j+1])
    if old_word_sep[len(old_word)-1]!=new_word_sep[0]:
      print ("No")
      break
    elif new_word in list(word_list_temp):
      print ("No")
      break
    else:
      continue

Submission status: Accepted

Solution code:
import sys
n = int(input())
words=[]
for i in range(n):
	words += [input()]
for i in range(n-1):
	for j in range(i+1, n):
		if words[i] == words[j]:
			print('No')
			sys.exit()
	if words[i][-1] != words[i+1][0]:
		print('No')
		sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
n = int(input())
words=[]
for i in range(n):
    words += [input()]
for i in range(n-1):
    for j in range(i+1, n):
        if words[i] == words[j]:
                print('No')
                sys.exit()
    if words[i][-1] != words[i+1][0]:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
last = input()
wds = set([last])
res = "Yes"
for i in range(N-1):
    wd = input()
    if wd in wds or last[-1]!=wd[0]: 
        res = "No"
        break
    last = wd
    wds.add(wd)
print(res)

Submission status: Accepted

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

n = input()
n = int(n)

w = []
for i in range(n):
    _w = input()
    w.append(_w)
ans = "Yes"
for i in range(0,len(w)-1):
    for j in range(i+1,len(w)):
        if w[i] == w[j]:
            ans = "No"
for i in range(0,len(w)-1):
    if w[i][-1] != w[i+1][0] :
        ans ="No"

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
word_list = []
yes_or_no = []
for i in range(N):
    w = str(input())
    if w not in word_list:
        word_list.append(w)
    elif w in word_list:
        yes_or_no.append('No')
        
    if i == 0:
        continue
    else:
        if w[0] == word_list[i-1][-1]:
            yes_or_no.append('Yes')
        else:
            yes_or_no.append('No')
if 'No' in yes_or_no:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

stock = []
last = W[0][0]

for i in range(0,len(W)):
    #過去の発言に含まれない
    if W[i] in stock:
        print('No')
        break
    #前の単語の最後と次の単語の最初が一致する
    if W[i][0] != last:
        print('No')
        break
    stock.append(W[i])
    last = W[i][-1]
    #最後まで回り切ったらyesを表示
    if i+1 == len(W):
        print('Yes')

Submission status: Accepted

Solution code:
list_length = int(input())
word_list = list()
for i in range(list_length):
  w = input()
  try:
    if w[0] != word_list[-1][-1]:
      break                
  except IndexError:
  	pass
  word_list.append(w)

if len(set(word_list)) == list_length:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

# print(w,w_alter)

for i in range(n-1):
    w_alter.append(w.pop(0))
    if w_alter[i] in w:
        # print(w_alter[i])
        print("No")
        exit()
    if w_alter[i][-1] != w[0][0]:
        # print(i)
        # print(w,w_alter)
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
import sys
N = int(input())
s = []
for i in range(N):
    s.append(input())
for i, s0 in enumerate(s):
    for j, s1 in enumerate(s):
        if i != j and s0 == s1:
            print('No')
            sys.exit()
s0 = s[0]
for i in range(1, len(s)):
    s1 = s[i]
    if s0[-1] != s1[0]:
        print('No')
        sys.exit()
    s0 = s1
print('Yes')

Submission status: Accepted

Solution code:
n = input()
d = set()
pre = ""
for i in range(n):
    s = raw_input()
    if s in d:
        print "No"
        exit()
    if pre == "" or pre[-1] == s[0]:
        d.add(s)
        pre = s
    else:
        print "No"
        exit()
print "Yes"

Submission status: Accepted

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

ok = True

for i in range(N-1):
    w = input()
    if ok:
        ok = ok and (not w in ws) and (w[0] == ws[-1][-1])
    ws.append(w)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
cap=int(input())
word_list=[str(input()) for i in range(cap)]

#check Duplication
li_uniq = list(set(word_list))
if( not len(li_uniq)==len(word_list) ):
    print ('No')
    sys.exit()
lastc=word_list[0][0:1]
for string in word_list:
    if(not string[0:1]==lastc):
        print('No')
        sys.exit()
    lastc = string[-1:]
print('Yes')

Submission status: Accepted

Solution code:
count = input()
inputed = []
last = ""
judge = "Yes"
for i in range(int(count)):
    new_inputed = input()
    if i != 0 and (new_inputed[0] != last or new_inputed in inputed):
        judge = "No"
    last = new_inputed[-1]
    inputed.append(new_inputed)
print(judge)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())

word_set = set()

chaine = []
for i in range(n):
  w = input()
  word_set.add(w)
  if chaine == []: 
    chaine.append( w[0] + w[-1] )
  else:
    if chaine[-1][-1] == w[0]:
      chaine.append( w[0] + w[-1] )

if len(word_set) == n and len(chaine) == n:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
N = int(input())
lastWord = input()
unique = {lastWord}

for i in range(N-1):
    nextWord = input()
    if nextWord in unique or lastWord[-1] != nextWord[0]:
        print("No")
        raise SystemExit
    lastWord = nextWord
    unique.add(nextWord)

print("Yes")

Submission status: Accepted

Solution code:
length = int(input())

words = []

for i in range(length):
  words.append(input())
  
flg = 'Yes'
pre = words[0]
for word in words[1:]:
  if pre[-1] != word[0]:
    flg = 'No'
  pre = word

if len(words) != len(set(words)):
  flg = 'No'
  
print(flg)

Submission status: Accepted

Solution code:
n = int(input())

ws = [input()]
f = True

for _ in range(n-1):
    w = input()
    if w not in ws and ws[-1][-1] == w[0]:
        ws.append(w)
    else:
        f = False
        break

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

Submission status: Accepted

Solution code:
n=int(input())
line=[input() for i in range(n)]
if n==len(set(line)):
    for i in range(n-1):
        if not line[i][-1]==line[i+1][0]:
            print("No")
            break
    else:print("Yes")
else:print("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = "Yes"
inp = int(input())
s = [];
shiri = input()
s.append(shiri)

for i in range(inp-1):
    shiri = input()
    
    shiri_s = list(shiri)
    shiri_s = shiri_s[0]
    
    s_e = list(s[-1])
    s_e = s_e[-1]
    if shiri in s or shiri_s != s_e:
        ans = "No"
        break
    s.append(shiri)
    
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return input()
def n():
    return int(input())

N = n()
che = 0
name = []
name.append(s())
for i in range(1,N):
    tmp = s()
    if tmp in name or tmp[0] != name[-1][-1]:
        print('No')
        exit()
    else:
        name.append(tmp)
print('Yes')

Submission status: Accepted

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

if len(set(w)) != 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:
result = True
words = []
n = int(input())

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

for i in range(n-1):
    word = words.pop(0)

    if word[-1] != words[0][0] or word in words:
        result = False
        break

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()

dic = {}

bf = raw_input()
dic[bf] = 1

frag = True

for i in range(N - 1):
    nw = raw_input()
    if bf[len(bf) - 1] != nw[0] or nw in dic:
        frag = False
    else:
        dic[nw] = 1
        bf = nw

if frag:
    print "Yes"
else:
    print "No"

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lst = []
dlst = []
ans = "Yes"
for i in range(n):
    lst.append(input())
st = set(lst)
for i in st:
    if lst.count(i) != 1:
        ans = "No"
for i in range(1, n):
    if lst[i-1][-1] != lst[i][0]:
        ans = "No"
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
li=[]
for i in range(0,n):
    n=input()
    li.append(n)
flag=0
chck=1
temp=li[0]
for j in li:
    t=li.count(j)
    if(t>1):
        flag=1
        break
    if(chck!=1):
        p=len(temp)
        ch=temp[p-1]
        
        ch1=j[0]
        if(ch==ch1):
            flag=0
            temp=j
        else:
            flag=1
            break
    chck=chck+1
if(flag==1):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
# coding:utf-8

# 要素数取得
a = int(raw_input())
#print a
# 要素を拾って配列に
i=0
l = [0]*a
for i in range(0, a):
    b = str(raw_input())
    l[i] = list(b)
#print l

cnt = 0

#print l
#print cnt

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 is_unique(l)== True:
    #先頭末尾
    if all(l[i][-1] == l[i+1][0] for i in range(a-1)):
        print "Yes"
    else:
        print "No"
else:
    print "No"

Submission status: Accepted

Solution code:
num      = int(input())
is_valid = True
words    = []
words.append(input())
for i in range(1, num):
    word = input()
    words.append(word)
    if words[i-1][-1] != word[0]:
        print('No')
        quit()

if len(words) != len(set(words)):
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#109b
n=int(input())
l=[input() for _ in range(n)]
la=l[0][-1]
flag=True

for i in range(1,n):
    if la==l[i][0]:
        la=l[i][-1]
    else:
        flag=False
        break

if len(set(l))!=n:
    flag=False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
words = []
flag = True

for i in range(n):
    word = input()
    if word in words:
        flag = False
        break
    else:
        words.append(word)
if not flag:
    print("No")
    quit()

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

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

Submission status: Accepted

Solution code:
length = int(input())
wset = set()
flag = 1
word = input()
wset.add(word)
for i in range(length - 1):
	add = word[-1]
	word = input()
	if add != word[0] or word in wset:
		flag=0
		break
	wset.add(word)
if flag == 1:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
# coding: utf-8


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


def main():
    n = int(input())
    shiri = True

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

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

    if not is_unique(w):
        shiri = False

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
counter = 0
old_list = []
for i in range(N):
    word = input()
    if i == 0:
        old = word
        counter += 1
        old_list.append(word)
    else:
        if old[-1] == word[0] :
            if not (word in old_list):
                counter +=1
        old_list.append(word)
        old = word
if counter == N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
W = input()
used = {W:True}
prev = W
for i in range(N-1):
    W = input()
    if W in used.keys() or W[0] != prev[-1]:
        print("No")
        break
    used[W] = True
    prev = W
else:
    print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
list=[input() for i in range(N)]
list2=[list[i].endswith(list[i+1][0]) for i in range(N-1)]
if False in list2 or len(list)!=len(set(list)):
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input())
Word = []
flag = True
for i in range(N):
    a = list(input())
    if a in Word:
        flag = False
        break
    Word.append(a)
if flag:
    for i in range(N-1):
        if Word[i][len(Word[i])-1] != Word[i+1][0]:
            flag = False
if flag:
    print("Yes")
else:
    print("No")