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:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, W: "List[str]"):
    if N != len(set(W)):
        print(NO)
        exit()

    for i in range(1, len(W)):
        if W[i-1][-1] != W[i][0]:
            print(NO)
            exit()
    print(YES)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, W)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
n = int(input())
w = [input() for i in range(n)]
c = collections.Counter(w)
flag = 0
if c.most_common()[0][1] != 1:
    flag = 1
for i in range(n-1):
    if w[i+1][0] != w[i][-1]:
        flag = 1
if flag == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
w=list(input()for i in range(n))
judge=True
worddic={}
worddic[w[0]]=0
for i in range(1,n):
    if w[i-1][-1]!=w[i][0]:
        judge=False
    if not w[i] in worddic:#重複を数える
        worddic[w[i]]=0
    else:
        judge=False
print("Yes") if judge else print("No")

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
words = np.array([input() for _ in range(N)])
if len(set(words))<N:
    print('No')
else:
    count=0
    for i in range(N-1):
        if words[i][-1] == words[i+1][0]:
            count+=1
    if count==N-1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n=int(input())
word=[]
for i in range(n):
  if i==0:
    word.append(input())
    continue
  k=input()
  if k in word:
    print("No")
    exit()
  a=list(word[-1])
  b=list(k)
  word.append(k)
  if a[-1]==b[0]:
    pass
  else:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    W = [input() for _ in range(N)]
     
    # まだ発話していない
    w = set(W)
    if len(W) != len(w):
        print('No')
        return

    # 先頭は直前の単語の末尾と一致
    for i in range(len(W)-1):
        be = W[i][-1]
        af = W[i+1][0]
        if be != af:
            print('No')
            return
    print('Yes')
    return



main()

Submission status: Accepted

Solution code:
N = int(input())

cache = []
abc = ''
ngflag = False
for i in range(N):
    word = input()
    if abc == '':
        pass
    elif word[0] != abc:
        ngflag = True

    if word in cache:
        ngflag = True
    abc = word[-1]
    cache.append(word)

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = []
a_first = []
a_last = []
for i in range(n):
    b = str(input())
    a.append(b)
    a_first.append(b[0])
    a_last.append(b[-1])
c = collections.Counter(a)
if (len(c.keys()) == n):
    if (a_first[1:] == a_last[:-1]):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

said = []
n = int(input())
said.append(input())
for i in range(1, n):
    temp = input()
    if temp in said or temp[0] != said[i-1][-1]:
        print("No")
        sys.exit()
    said.append(temp)
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
S = list(input() for i in range(N))
memo = []
tmp = S[0][0]
for s in S:
    if tmp == s[0] and s not in memo:
        tmp = s[-1]
        memo.append(s)
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
W=[]
for i in range(N):
    w=input()
    W.append(w)
#print(W)
t=[]
t=set(W)
for i in range(N-1):
 if W[i][-1]!=W[i+1][0] or len(W)!=len(t):
        #W[i]の最後の文字とW[i+1]の最初の文字は同一か？
        print("No")
        exit(0)
 #elif W==W(set()):
 #入力される文字は重複していないか？
   #  print("No")
    # break
 
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
l=[]
for i in range(N):
    l.append(input())
if len(list(set(l)))!=len(l):
    print("No")
else:
    end=l[0][len(l[0])-1]
    del l[0]
    c=True
    for j in l:
        if j[0]!=end:
            c=False
            break;
        end=j[len(j)-1]
    if c:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

for i in W:
    if i[0] == InitChar:
        InitChar = i[-1]
    else:
        flag = False
        break

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

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

Submission status: Accepted

Solution code:
n=int(input())
s = [input() for _ in range(n)]
if len(set(s)) != len(s):
  print('No')
  exit()
for i in range(len(s) - 1):
  if s[i][-1] != s[i+1][0]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
N, = (int(x) for x in input().split())
W_arr = []
for _ in range(N):
    W_arr.append(input())

is_valid = True

W_set = set(W_arr)
if len(W_set) != len(W_arr):
    is_valid = False

for i in range(1, N):
    if W_arr[i][0] != W_arr[i-1][-1]:
        is_valid = False

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# S = input()
# print('Heisei' if S <= '2019/04/30' else 'TBD')

# n,m,c=map(int,input().split())
# b=list(map(int,input().split()))
# e = [[int(i) for i in input().split()] for i in range(n)]

# array=[None]*3
# print(array)

# print('{0:.10f}'.format(11))

n=int(input())
b=[]
#b=list(map(str,input().split()))
for i in range(0,n):
	str=input()
	b.append(str)

flag=0

for i in range(1,n):
	str1=b[i-1]
	str2=b[i]

	if str1[-1:]!=str2[:1]:
		flag=1
	else:
		for k in range(0,i):
			# print("b[k] is "+b[k])
			# print("str2 is "+str2)
			# print(b[k]==str2)
			if b[k]==str2:
				flag=1
			#print("flag is ",flag)


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

Submission status: Accepted

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

def main():
    c = ''
    for w in W:
        abort = c != '' and w[0] != c or W.count(w) > 1
        if abort == True:
            break
        c = w[len(w) - 1]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
w = [str(input()) for _ in range(n)]
w_split = [0]*n
res = "Yes"
for i in range(n) :
  w_split[i] = list(w[i])
for i in range(n-1) :
  if(w_split[i][-1] != w_split[i+1][0]) : res = "No"

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

Submission status: Accepted

Solution code:
n = int(input())
word_list = []
ans = "Yes"
preword = input()
word_list.append(preword)
for i in range(n-1):
    w = input()
    if w in word_list:
        ans = "No"
    if preword[-1] != w[0]:
        ans = "No"
    word_list.append(w)
    preword = w
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
check = set(w)
counter = [w.count(i) for i in check]
if 2 <= max(counter):
    print('No')
else:
    tail = w[0][-1]
    cnt = 0
    for i in w[1:]:
        if tail == i[0]:
            cnt += 1
        tail = i[-1]
    print('Yes' if cnt == n-1 else 'No')

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
W=[input() for i in range(N)]
flag=True
a=Counter(W)
b=a.most_common()
if b[0][1]>1:
    flag=False
for i in range(len(W)-1):
    if W[i][-1]!=W[i+1][0]:
        flag=False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
t = set(w)
q = max([w.count(i) for i in t])
if q > 1:
    print('No')
else:
    cnt = n - 1
    tail = w[0][-1]
    for i in w[1:]:
        if tail == i[0]:
            cnt -= 1
        tail = i[-1]
    print('Yes' if cnt == 0 else 'No')

Submission status: Accepted

Solution code:
N = int(input())
W = []
judge = 1

for i in range(N):
  w = input()    
  W.append(w)
  if(i != 0):
   tmp1 = list(W[-2])
   tmp2 = list(w)
   if(tmp1[-1] != tmp2[0]):
     judge = 0
     break

len1 = len(W)
len2 = len(list(set(W)))
if(len1 != len2):
  judge = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
L=[]
for i in range(N):
    L.append(input())
S=set(L)
if len(S)<len(L):
    print('No')
else:
    p=0
    for i in range(N-1):
        a=L[i]
        A=a[-1:]
        b=L[i+1]
        B=b[:1]
        if A!=B:
            print('No')
            break
        else:
            p+=1
    if p==N-1:
        print('Yes')

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
A = []
ans = 'Yes'
for i in range(N):
    s = input()
    if s not in A:
        A.append(s)
        if A[i - 1][-1] != s[0] and i > 0:
            ans = 'No'
            break
    else:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

last = ""
all_set = set()
result = True
for i in range(N):
    w = input()
    if i > 0:
        if w[0] != last[-1] or w in all_set:
            result = False
    all_set.add(w)
    last = w
if result:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

used = [a[0]]
pre = a[0]
for i in a[1:]:
    if i not in used and pre[-1] == i[0]:
        used.append(i)
        pre = i
    else:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = []
for _ in range(N):
    W.append(input())
D = []
for i in range(N):
    if W[i] in D:
        print('No')
        exit()
    else:
        if i == 0:
            pass
        else:
            if D[-1][-1] != W[i][0]:
                print('No')
                exit()
        D.append(W[i])
print('Yes')

Submission status: Accepted

Solution code:
#ABC109 B 
N = int(input())
words = []
for i in range(N):
	words.append(str(input()))

msg = 'Yes'

#重複チェック
if len(list(set(words))) != len(words):
	msg = 'No'

#しりとりチェック
for i in range(N-1):
	if words[i][-1] == words[i+1][0]:
		continue
	else:
		msg = 'No'
		break
		
print(msg)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
w_ls = list()
for i in range(N):
  w_ls.append(input())
def main(w_ls):
  last = ""
  for i, w in enumerate(w_ls):
    if i > 0:
      if last != w[0]:
        return False
    last = w[-1]
  return True
if main(w_ls) and len(w_ls) == len(set(w_ls)):
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

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

n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip() for _ in range(n)]
c_data = Counter(data)
if len(c_data.keys()) < n:
    print('No')
    sys.exit()
for i, d in enumerate(data):
    if i == 0:
        continue
    if list(d)[0] != list(data[i-1])[-1]:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
s=defaultdict(lambda: 0)
l=list([input() for i in range(n)])
f='Yes'
i=-1
for v in l:
  s[v]+=1
  if s[v] >= 2:
    f='No'
  if i!=-1 and l[i][-1] != v[0]:
    f='No'
  i+=1
print(f)

Submission status: Accepted

Solution code:
N = int(input())
W_list = [input() for _ in range(N)]
mae = W_list[0]
flg = "Yes"
for w in W_list[1:]:
    if mae[-1]==w[0]:
        mae = w
    else:
        flg = "No"
W_set = set(W_list)
if len(W_list)!=len(W_set):
    flg = "No"

print(flg)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#S=input()
N=int(input())
#N,M,X,Y=map(int,input().split())
W=[]
can=True
for i in range(N):
    w=input()
    if i==0:
        W.append(w)
        e=w[-1]
        continue
    s=w[0]
    if e==s and not(w in W):
        W.append(w)
        e=w[-1]
        continue
    else:
        can=False
        break
if can:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N=ri()
W=[0]*N
ans = 1
for i in range(N):
    W[i] = input()
    if ans == 1 and i != 0 and W[i-1][-1] != W[i][0]:
        ans = 0

if ans == 1 and len(set(W)) != N:
    ans = 0

yn(ans)

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N=ri()
W=[0]*N
ans = 1
for i in range(N):
    W[i] = input()
    if i != 0 and W[i-1][-1] != W[i][0]:
        ans = 0

import collections
Wc = collections.Counter(W).most_common()
if Wc[0][1] != 1:
    ans = 0

yn(ans)

Submission status: Accepted

Solution code:
N=int(input())

s=input()
l=[]
l.append(s)
check=0
for i in range(N-1):
  t=input()
  if t not in l and t[0]==s[-1]:
    l.append(t)
    s=t[:]
  else:
    check=1
print("Yes" if check==0 else "No")

Submission status: Accepted

Solution code:
n=int(input())
l=[str(input()) for i in range(n)]
flag=0
for i in range(n-1):
    if l[i][-1]!=l[i+1][0]:
        flag=1
        break

s_l=set(l)
if len(l)!=len(s_l):
    flag=1

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

Submission status: Accepted

Solution code:
N = int(input())
word_list = []
ans = "Yes"
for i in range(N):
  word = input()
  word_list.append(word)
  if i != 0:
    if not(word[0] == word_list[i - 1][-1] and word_list.count(word) == 1):
      ans = "No"
      break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def shiritori(N: int, W: list)->bool:
    used = []
    head = W[0][0]

    for w in W:
        if w in used or head != w[0]:
            return False
        used.append(w)
        head = w[-1]

    return True


if __name__ == "__main__":
    N = int(input())
    W = [input() for _ in range(N)]
    yes = shiritori(N, W)
    print('Yes' if yes else 'No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list()
cnt = 0
A.append(input())
for i in range(N-1):
  x = input()
  if x in A:
    cnt = 1
  elif A[i][-1:] != x[0]:
    cnt = 1
  A.append(x)
print('Yes' if cnt == 0 else 'No')

Submission status: Accepted

Solution code:
N = int(input())
flag = True
shiritori_dict = {}
new_word = ""
old_word = input()
shiritori_dict[old_word] = True
for i in range(1, N):
    new_word = input()
    if old_word[-1] != new_word[0]:
        flag = False
    if new_word not in shiritori_dict:
        shiritori_dict[new_word] = True
    else:
        flag = False
    old_word = new_word
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict(int)
n = int(input())
lst = [input() for _ in range(n)]
last = lst[0]
dic[last] = 1
flag = True
for i in range(1, n):
  if lst[i][0] != last[-1]:
    flag = False
    break
  dic[lst[i]] += 1
  if dic[lst[i]] > 1:
    flag = False
    break
  last = lst[i]
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for i in range(n)]
def C(w):
    for i in range(1, n):
        if not(list(w[i])[0]==list(w[i-1])[-1]):
            return False
        if any(w[i]==w[j] for j in range(i)):
            return False
    return True
if C(w):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())

l = []

c = 0
d = 0

for i in range(n):
	a = str(input())
	l.append(a)
  
for i in range(n-1):
	if l[i][-1] == l[i+1][0]:
		c += 1

for i in range(n):
	if l.count(l[i]) != 1:
		d += 1

if c == n-1 and d == 0:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc109/tasks/abc109_b
n = int(input())
w = []
for _ in range(n):
    w.append(input())
if len(w) != len(set(w)):
    print("No")
    exit()
for i in range(1, len(w)):
    if w[i][0] != w[i - 1][-1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import collections

N = int(input())
W = [input() for i in range(N)]
w = collections.Counter(W)
if len(w.values()) != len(W):
  print('No')
else:
  for i in range(len(W)-1):
    s = W[i]
    tmp = s[len(s)-1]
    s_next = W[i+1]
    if tmp != s_next[0]:
      print('No')
      break
  else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
li = []
c = 0
for i in range(n):
    w = input()
    if w in li:
        c = 1
    
    li.append(w)

for i in range(1,n):
    if li[i-1][-1] != li[i][0]:
        c = 1

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

Submission status: Accepted

Solution code:
N = int(input())

W = []

counter = 0
for i in range(N):
    W.append(input())

if not (len(W)==len(set(W))): #同じ単語
    print("No")

else:
    for i in range(N-1):
        if(W[i][::-1][0] != W[i+1][0]):
            counter +=1

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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
if len(set(W)) != 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())
wl = []

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

ans = 0

for i in range(n):
    if wl.count(wl[i]) > 1:
        ans += 1
    else:
        ans+=0

for i in range(n-1):
    a = list(wl[i])
    b = list(wl[i+1])
    if a[-1] == b[0]:
        ans += 0
    else:
        ans += 1

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

Submission status: Accepted

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

ans = 'Yes'
if len(words) != len(set(words)):
    ans = 'No'
else:
    next_words = words[1:]+['']
    for s1,s2 in zip(words,next_words):
        if s2 and s1[-1] != s2[0]:
            ans = 'No'
            break

print(ans)

Submission status: Accepted

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

ans = 'Yes'

if len(setw)!=len(W):
    ans='No'
    
for i in range(N):
    if i==0:
        continue
    if W[i][0] != W[i-1][-1]:
        ans='No'
        
print(ans)

Submission status: Accepted

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

for x in range(0,N):
    w = input()
    W.append(w)

alphabet = W[0][0]
answer = True

for x in W:
    if not alphabet == x[0]:
        answer = False
        break
    if not W.count(x) == 1:
        answer = False
        break
    alphabet = x[len(x)-1]

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

Submission status: Accepted

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

history = []
judge = True
for w in W:
    if w in history or (history != [] and history[-1][-1] != w[0]):
        judge = False
        break
    history.append(w)
print('Yes' if judge else 'No')

Submission status: Accepted

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

for i in range(N):
    if i == 0:
        word_list.append(W[i])
        continue
    elif W[i][0]==W[i-1][-1] and W[i] not in word_list:
        word_list.append(W[i])
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import copy

def solve():
    N=int(input())
    W=[]
    for i in range(N):
        W.append(input())
    history = []
    for i in range(N):
        w = W[i]
        if i > 0:
            if p[-1] != w[0]:
                return False
        if w in history:
            return False
        #print(history)
        history.append(copy.copy(w))
        p = w
    return True

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

Submission status: Accepted

Solution code:
n=int(input())
s=set()
flag=True
buf=""
for i in range(n):
    str=input()
    if buf!="" and str[0]!=buf[-1:]:
        flag=False
    if str in s:
        flag=False
    s.add(str)
    buf=str

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

Submission status: Accepted

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

if len(words)!=len(set(words)):
  print('No')
else:
  f=True
  for i in range(N-1):
    f&=(words[i][-1]==words[i+1][0])
  print('Yes' if f else 'No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    used = set()
    last = ""
    for _ in range(N):
        w = input()
        if w in used or not w.startswith(last):
            print("No")
            return
        last = w[-1]
        used.add(w)
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if len(set(wordlist)) != N:
    print('No')
else:
    for idx in range(1, N):
        if wordlist[idx-1][-1] != wordlist[idx][0]:
            print('No')
            break
    else:
        print('Yes')

Submission status: Accepted

Solution code:
flag = 0
n = int(input())
s = [input() for i in range(n)]
if len(set(s)) != n:
    flag = 1
for i in range(n-1):
    if s[i][-1] != s[i+1][0] :
        flag = 1
if flag == 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
lst = [input() for x in range(N)]
if len(lst) != len(set(lst)):
    print('No')
    exit(0)

s = lst[0][-1]
for x in lst[1:]:
    if s != x[0]:
        print('No')
        exit(0)
    s = x[-1]
print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
L=[]
a=True
for i in range(n):
  L.append(input())
if len(L)!=len(set(L)):
  print('No')
else:
  for i in range(1,len(L)):
    if L[i][0]==L[i-1][-1]:
      continue
    else:
      a=False
  if a is True:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())

w = [input() for _ in range(n)]
f = True
lis = []
for i in range(0, n-1):
    end = w[i][-1:]
    next = w[i+1][:1]
    if end != next or w[i] in lis:
        f= False
        break
    else:
        lis.append(w[i])
if w[n-1] in lis:
    f = False
if f:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())

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

for i in range(N):
    if i != 0:
        tmp = list(W[i-1])
        last_end = tmp[-1]

        tmp = list(W[i])
        current_start = tmp[0]
        if (last_end != current_start) or (len(W) != len(list(set(W)))):
            print('No')
            exit()
print('Yes')

Submission status: Accepted

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

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

if all(map(lambda a,b: a[-1]==b[0], words[:-1],words[1:])):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n = int(input())
li = []
c = 1
for i in range(n):
    w = input()
    if w in li:
        c = 0
        
    else:
        li.append(w)

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

Submission status: Accepted

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

w_u = sorted(set(w), key=w.index)
flag=False
if len(w_u)!=len(w):
    flag=True
else:
    for i in range(1,len(w)):
        if w[i-1][-1]==w[i][0]:
            pass
        else:
            flag=True
            break

print("YNeos"[flag::2])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
a=[]
r=True
l=""
for i in range(0,n):
  w=input()
  if w in a:
    r=False
    break
  if l!="" and l!=w[0]:
    r=False
    break
  l=w[-1]
  a.append(w)
if r:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
_,*l=open(0).readlines();print('YNeos'[any(a[-2]!=b[0]*l.count(a)for a,b in zip(l,l[1:]))::2])

Submission status: Accepted

Solution code:
_,*a=open(0).readlines()
if len(set(a))<len(a):
  print("No")
  exit()
b=[(i[0],i[-2]) for i in a]
for k in range(len(b)-1):
  if b[k][1]!=b[k+1][0]:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
# https://abc109.contest.atcoder.jp/tasks/abc109_b

def solve(words):
    word = words[0]
    uniq_words = {word: True}

    ans = "Yes"
    for key in range(1, len(words)):
        next_word = words[key]
        if next_word in uniq_words:
            ans = "No"
            break
        uniq_words[next_word] = True
        if word[-1] != next_word[0]:
            ans = "No"
            break
        word = next_word

    return ans

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

    ans = solve(words)
    print(ans)

main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    words = [input() for _ in range(N)]
    past = [words[0]]
    for i in range(1, N):
        prev, now = words[i-1], words[i]
        if (now in past or prev[-1] != now[0]):
            print("No")
            return
        else:
            past.append(now)
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
for i in range(len(w)):
	for j in range(i + 1, len(w)):
		if w[i] == w[j]:
			print('No')
			exit()

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

Submission status: Accepted

Solution code:
l=open(0).readlines()[1:];print('YNeos'[any(a[-2]!=b[0]*l.count(a)for a,b in zip(l,l[1:]))::2])

Submission status: Accepted

Solution code:
n = int(input())

lastch = ''
answer = 'Yes'
words = []

for i in range(n):
    word = input()
    words.append(word)
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(words) != len(set(words)):
    answer = 'No'

print(answer)

Submission status: Accepted

Solution code:
n = int(input())

lastch = ''
answer = 'Yes'
words = []
for i in range(n):
    word = list(input())
    words.append(''.join(word))
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(set(words)) != len(words):
    answer = 'No'

print(answer)