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:
import sys
n = int(input())
w = [input() for _ in range(n)]
if len(w) != len(set(w)):
    print('No')
    sys.exit(0)

w.insert(0, w[0][0])
w.append(w[-1][-1])

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

Submission status: Accepted

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

end = w[0][-1]
flag = 0

memo={}
memo[w[0]] = "_"

for i in range(1,n):
  if w[i] in memo:
    flag=1
    break
  memo[w[i]] = "_"
  start = w[i][0]
  if end != start:
    flag = 1
    break
  else:
    end = w[i][-1]
    
if flag == 1:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
n = int(input());
words = []

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

if (len(words) > len(set(words))):
    print('No')
    sys.exit(0)

before_word = words.pop(0)
while( len(words) > 0 ):
    after_word = words.pop(0)
    if (before_word[-1] != after_word[0]):
        print('No')
        sys.exit(0)
    before_word = after_word
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W = []
for i in range(N):
    W.append(str(input()))
ans = "No"
startwith = []
endwith = []
if len(set(W)) == len(W):
   for i in W:
       startwith.append(i[0])
       endwith.append(i[-1])
   startwith.pop(0)
   endwith.pop(-1)
   if startwith == endwith:
    ans = "Yes"

print(ans)

Submission status: Accepted

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

done = 0
for idx, i in enumerate(W[1:], 1):
    if W[idx - 1][len(W[idx - 1]) - 1] != i[0]:
        break
    done += 1

if done + 1 == len(W) and len(set(W)) == len(W):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main(n,lst):
    if len(set(lst)) != n:
        return "No"
    last = lst[0][-1]
    for e in lst[1:]:
        if e[0]==last:
            last = e[-1]
        else:
            return "No"
    return "Yes"
n = int(input())
lst = [input() for i in range(n)]
print(main(n,lst))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
word = [input() for _ in range(N)]
s = set(word)
ok = True
if len(s) != N:
    ok = False
for i in range(1,N):
  if word[i][0] != word[i-1][-1] :
    ok = False
print('Yes' if ok else 'No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def check_dup(word_list, word):
  return word not in word_list

def check_chain(word_list, current_str):
  if len(word_list) == 0:
    return True
  return word_list[-1][-1] == current_str[0]

def main():
  input_num = int(input())
  input_str = [input().rstrip() for i in range(input_num)]
  result = 'Yes'
  word_list = []
  for word in input_str:
    if not check_dup(word_list, word) or not check_chain(word_list, word):
      result = 'No'
      break
    word_list.append(word)
  print(result)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())
a = [list(input()) for l in range(N)]
ch = []
for i in range(N):
    if i != 0:
        if a[i-1][len(a[i-1])-1] == a[i][0]:
            continue
        else:
            print('No')
            exit()




for i in a:
    if i not in ch:
        ch.append(i)
    else:
        print('No')
        exit()
else:
    print('Yes')

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'
else:
    W = [list(i) for i in W]
    for i in range(len(W)-1):
        if W[i][-1] != W[i+1][0]:
            ans = 'No'
            break
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
count=[]
a=input()
count.append(a)

for i in range(N-1):
    b=input()
    if(b[0]!=a[-1] or b in count):
        print("No")
        quit()
    count.append(b)
    a=b

print("Yes")

Submission status: Accepted

Solution code:
last = None
used = []
for _ in range(int(input())):
	w = input().rstrip()

	if last is not None:
		if last == w[0] and not(w in used):
			last = w[-1]
			used.append(w)
			continue
		else:
			print('No')
			break
	else:
		last = w[-1]
		used.append(w)

else: print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
li = []
for _ in range(n):
    li.append(input())
lastChar = li[0][0]
for word in li:
    if li.count(word) != 1 or word[0] != lastChar:
        print('No')
        exit()
    lastChar = word[-1]
print('Yes')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

#0の時正しい
ans = 0
#長さが違うと同じものがある
if(len(A) != len(set(A))):
    ans+=1

for i in range(1, len(A)):
    if(i<len(A)):
        if(A[i-1][-1] == A[i][0]):
            continue
        else:
            ans+=1
if(ans==0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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


def main():
    n = int(input())
    words = list()
    word = input()
    words.append(word)
    prev = word[-1]

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

        if cur in words:
            print('No')
            exit()

        if prev != cur[0]:
            print('No')
            exit()

        words.append(cur)
        prev = cur[-1]

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x=int(input())
words=[]
found=0
word_1=''
word_2=''
for i in range(x):
    words.append(input())

for j in range(x-1):
    for k in range(j+1,x):
        if words[j]==words[k]:
            found=-1
for c in range(x-1):
    word_1=words[c]
    word_2=words[c+1]
    if word_1[-1]!=word_2[0]:
        found=-1
if found==-1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N=input()
W=[]
for i in range(N):
    a=raw_input()
    if i==0:
        W.append(a)
        continue
    if a not in W and a[0]==W[-1][-1]:
        W.append(a)
    else:
        print "No"
        break
if len(W)==N:
    print "Yes"

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

L = []

ans = "Yes"
for i in range(N):
    w = input()
    if i != 0:
        if w in L or L[-1][-1] != w[0]:
            ans = "No"
            break
    L.append(w)

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
W=[input()for i in'0'*N]
print('YNeos'[any(a[0]!=b[-1]for a,b in zip(W[1:],W))or len(set(W))!=N::2])

Submission status: Accepted

Solution code:
N = int(input())
shiri = []
flag = 0
for i in range(N):
    tugi = str(input())
    tlist = list(tugi)
    if i!=0:
        if tugi in shiri:
            flag = 1
            break
        else:
            mae = list(shiri[i-1])
            if tlist[0]!=mae[-1]:
                flag = 1
                break
            else:
                shiri.append(tugi)
    else:
        shiri.append(tugi)
if flag == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def main():
    """Function."""
    n = int(input())

    flag = 0
    check = set()
    temp = str(input())
    check.add(temp)
    for _ in range(n-1):
        dum = str(input())
        if temp[-1] == dum[0] and dum not in check:
            check.add(dum)
            temp = dum

        else:
            flag = 1

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
W = [0 for _ in range(N)]
for i in range(N):
    W[i] = input()
W_set = set(W)
        
for i in range(N - 1):
    # print(W[i][-1:])
    if W[i][-1:] != W[i + 1][0]:
        print('No')
        break
    elif len(W_set) != len(W):
        print('No')
        break
    else:
        if i == N - 2:
            print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

def shiritori(last, now):
    if mem.get(now) is not None:
        return False
    else:
        if last[-1] != now[0]:
            return False
    mem[now] = 1
    return True


last = words.pop()
mem = {last: 1}

ok = True
for i in range(N-1):
    now = words.pop()
    if not shiritori(last, now):
        ok = False
        break
    last = now

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

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    n = int(input())
    ws = [input() for _ in range(n)]
    counts = Counter(ws)
    if any(v > 1 for v in counts.values()):
        print('No')
        return
    for i in range(1, n):
        if ws[i - 1][-1] != ws[i][0]:
            print('No')
            return
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
w = input()
word = [w]
before = w[-1]
flag = True

for i in range(N-1):
    w = input()
    if w not in word and before == w[0]:
        word.append(w)
        before = w[-1]
    else:
        flag = False
        break

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

Submission status: Accepted

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

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

for i in range(N):
    if i == 0:
        wlist.append(input())
    
    else:
        bef = wlist[i-1]
        tmp = input()

        if bef[-1] == tmp[0]:
            wlist.append(tmp)
        
        else:
            print("No")
            exit()

if is_unique(wlist) == False:
    print("No")

else:
    print("Yes")

Submission status: Accepted

Solution code:
import collections
N=int(input())
W=[]
for i in range(N):
    W.append(input())
a=collections.Counter(W)
a=sorted(a.items(),key=lambda x:x[1],reverse=True)
if a[0][1]>1:
    print('No')
else:
    c=0
    for i in range(N-1):
        if W[i][-1]!=W[i+1][0]:
            c=1
            break
    if c==0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N = int(input())
W = []
for i in range(0,N):
    W.append(input())
    
result = 'Yes'

for i,w in enumerate(W):
    if i>0 and W[i-1][-1] != W[i][0]:
        result = 'No'

Wset = set(W)

if len(W) != len(Wset):
    result = 'No'
    
print(result)

Submission status: Accepted

Solution code:
N = int(input())
inputs = [input() for _ in range(N)]
compare_inputs = [inputs[0]]

for n in range(1, N):
    if inputs[n] in compare_inputs:
        print('No')
        break
    else:
        if not inputs[n][0] == inputs[n-1][-1]:
            print('No')
            break
    compare_inputs.append(inputs[n])
else:
    print('Yes')

Submission status: Accepted

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

for i in range(N):
    answer.append(input())
    
if(len(set(answer))!=len(answer)):
    print("No")
else:
    for j in range(N-1):
        if(answer[j][-1]==answer[j+1][0]):
            if(j==N-2):
                print("Yes")
            else:
                continue
        else:
            print("No")
            break

Submission status: Accepted

Solution code:
a = int(input())
x = input()
ar = [x]
for i in range(a-1):
    l = input()
    if x[len(x)-1] == l[0] and l not in ar:
        x = l
        ar.append(x)
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import sys
import math
import fractions
def j(a):
    if a: print("Yes")
    else :print("No")


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

x = ip()                              #入力整数1つ
#x,y = (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

a = []
a.append(input())
s = 1
for i in range(1,x):
    l = input()
    if l in a: s =0
    a.append(l)
    if l[0] != a[i-1][len(a[i-1])-1]: s=0
j(s)

Submission status: Accepted

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

for i in range(1,n):
    if A[i][0:1] != A[i-1][-1:] or A.index(A[i]) < i:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [input() for x in range(n)]
start = a[0][0]
if len(set(a)) != n:
    print("No")
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

R = "Yes"
pr = input()
W = []
for i in range(1, N):
  W.append(pr)
  s = input()
  if pr[len(pr)-1:] != s[:1]:
    R = "No"
    break
  if s in W:
    R = "No"
    break
  pr = s
    
print(R)

Submission status: Accepted

Solution code:
n=int(input())
k=[input()]
a="Yes"
for i in [0]*(n-1):
  x=input()
  if k[-1][-1]!=x[0] or x in k:
    a="No"
    break
  k.append(x)
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
W=[]
end=""
for i in range(int(input())):
    w=input()
    if w in W:
        print("No")
        exit()
    else:
        if 0 < i and end != w[0]:
            print("No")
            exit()
        end=w[-1::]
        W.append(w)
else:
    print("Yes")

Submission status: Accepted

Solution code:
# coding: utf8

if __name__ == "__main__":
    n = int(input())
    w = []
    flag = True
    for _ in range(n):
        a = input()
        if len(w) == 0:
            w.append(a)
            continue
        last = w[len(w)-1]
        if a[0] != last[len(last)-1] or a in w:
            flag = False
            break
        w.append(a)
    if flag == True:
        print("Yes")
    else:
        print("No")

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'
print(ans)

Submission status: Accepted

Solution code:
import sys
# N,M = [int(n) for n in input().split()]
# S = str(input())
# T = str(input())

N = int(input())
SS = [0]*N
s = set()
SS[0] = str(input())
s.add(SS[0])
for i in range(1,N):
    SS[i] = str(input())
    if(SS[i] in s):
        print('No')
        sys.exit()
    s.add(SS[i])
for i in range(1,N):
    if(SS[i-1][-1] != SS[i][0]):
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

d = {}
last = None
result = True
for i in range(n):

    h = input()
    if h in d:
        result = False
    d[h] = 1
    if last:
        if last[-1] != h[0]:
            result = False
    last = h
if result:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

N = int(input())
words = [input()]

for i in range(1, N):
  w = input()
  if ((w[0] == words[i - 1][-1]) & (w not in words)):
    words.append(w)
  else:
    print("No")
    sys.exit()
    
print("Yes")

Submission status: Accepted

Solution code:
import sys
N, = map(int, raw_input().split())
s = raw_input()
k = set([s])
l = s[-1]
for i in range(N-1):
  s = raw_input()
  if s[0]!=l or s in k:
    print "No"
    sys.exit(0)
  k.add(s)
  l = s[-1]
print "Yes"

Submission status: Accepted

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

for i in range(N):
    word = input()
    word_list.append(word)
    if i > 0:
        if word_list[i - 1][-1] != word_list[i][0] or word_list.count(word) > 1:
            print("No")
            break
else:
    print("Yes")

Submission status: Accepted

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

ans = 'Yes'
for _ in range(N-1):
    w = input()
    if w[0] == W[-1][-1] and w not in W:
        W.append(w)
    else:
        ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

p = {}
pre = str(input())
p[pre] = 1
pre = pre[len(pre)-1]

ret = True

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

    if pre != w[0] :
        ret = False

    if w in p :
        ret = False
    else:
        p[w] = 1
        
    pre = w[len(w)-1]

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    w = []
    for i in range(N):
        w.append(input())
        if i == 0:
            continue
        if w[i][0] != w[i-1][-1]:
            print('No')
            return

    if N == len(set(w)):
        print('Yes')
    else:
        print('No')

main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
count=0
m=[]
s=input()
m.append(s)
for i in range(N-1):
    l=input()
    if l not in m and m[i][-1]==l[0]:
        count+=1
    m.append(l)
if count==N-1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
w = list(str(input()) for _ in range(N))
res = 'Yes'
if len(w) != len(set(w)):
    print('No')
    exit()
last = (w[0])[0]
for i, x in enumerate(w):
    if last != x[0]:
        print('No')
        exit()
    last = x[-1]
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
word = list(str(input()) for _ in range(N))
res = 'Yes'
if len(word) != len(set(word)):
    print('No')
    exit()
last = (word[0])[0]
for i, x in enumerate(word):
    if last != x[0]:
        print('No')
        exit()
    last = x[-1]
print('Yes')

Submission status: Accepted

Solution code:
# Nを取得
N = int(input())
# 単語取得
word = list(str(input()) for _ in range(N))
# 結果用の変数
res = 'Yes'
# 重複チェック
if len(word) != len(set(word)):
    print('No')
    exit()
# 前後のチェック用の変数
last = (word[0])[0]
# 前後のチェック
for i, x in enumerate(word):
    if last != x[0]:
        print('No')
        exit()
    last = x[-1]
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    n=int(input())
    s = set()
    tmp = input()
    s.add(tmp)
    for i in range(n-1):
        tmp2 = input()
        if tmp[-1] != tmp2[0] or tmp2 in s:
            print('No')
            return 
        
        s.add(tmp2)
        tmp = tmp2
    print('Yes')
    
main()

Submission status: Accepted

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

s = set([])
s.add(w[0])
word = w[0][-1]

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

print("Yes")

Submission status: Accepted

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

for a,b in zip(W,W[1:]):
    if a[-1] != b[0]:
        print('No')
        exit()

sl = len(set(W))
print('Yes' if N == sl else 'No')

Submission status: Accepted

Solution code:
import sys

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

from collections import Counter
counter=Counter(W)

if max(counter.values())>1:
    print("No")
    sys.exit()

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

print("Yes")

Submission status: Accepted

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

announced_before = set()

announced_before.add(w_list[0])
for i in range(1, N):
    prev_w = w_list[i - 1]
    w = w_list[i]
    if w in announced_before:
        print("No")
        break
    elif prev_w[-1] != w[0]:
        print("No")
        break
    else:
        announced_before.add(w)

else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
s = [str(input())]
for i in range(1, N):
    x = str(input())
    if x[0] != s[i-1][-1]:
        break
    s.append(x)
if len(set(s)) == N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
W = list(input() for _ in range(N))
message = 'Yes'

for i in range(N-1):
    if W.count(W[i]) > 1 or W[i][-1] != W[i+1][0]:
        message = 'No'
        break

print(message)

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
s = set(W)
if len(s) != 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:
n=int(input())
w=[]
flg=0
for i in range(n):
    w.append(input())
    if i != 0:
        if w[i][0] != w[i-1][-1]:
            flg=1
if len(w) != len(set(w)):
    flg=1
print("YNeos"[flg::2])

Submission status: Accepted

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


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

    if len(words) is not len(set(words)):
        print('No')
        exit()

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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


def solve():
    n = int(input())

    words = []
    words.append(input())

    for _ in range(n-1):
        word = input()
        # duplicated
        if word in words:
            print('No')
            exit()
        else:
            prev = words[-1]
            # print('prev, word', prev, word)
            if prev[-1] == word[0]:
                words.append(word)
                pass
            else:
                # not matches
                print('No')
                exit()
    else:
        print('Yes')


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

    for i in range(n):
        w = input()
        if w in s:
            print("No")
            break
        s.add(w)

        if i != 0:
            if w[0] != last:
                print("No")
                break
                
        if i == n-1:
            print("Yes")
            break

        last = w[-1]

if __name__ == "__main__":
    main()

Submission status: Accepted

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

v = [W[0]]

for i in range(1, N):
    if W[i-1][-1] != W[i][0] or W[i] in v:
        print("No")
        sys.exit()
    v.append(W[i])
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
w=[]
w1=[]
w2=[]
for i in range(n):
    a=input()
    w1.append(a)
    w.append(list(a))
if len(set(w1))!=n:
    print("No")
    sys.exit()
for i in range(n):
    if i==0:
        w2.append(w[i][-1])
    elif i==(n-1):
        w2.append(w[i][0])
    else:
        w2.append(w[i][0])
        w2.append(w[i][-1])
for i in range(0,((n-1)*2),2):
    x=w2[i:2+i]
    if len(set(x))!=1:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
n = int(raw_input())
s = []
for _ in xrange(n):
    s.append(raw_input())

ss = set()
last = None
ret = 'Yes'
for w in s:
    if w in ss:
        ret = 'No'
        break
    if last is None:
        ss.add(w)
        last = w
        continue
    if last[-1] != w[0]:
        ret = 'No'
        break
    ss.add(w)
    last = w

print ret

Submission status: Accepted

Solution code:
n = int(input())

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

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

print(ret)

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for i in range(n)]
#print(n)
#print(w)
flag=0
if len(w)==len(set(w)):
    flag=0
else:
  flag=1

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

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