Problem:


Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

In the first turn, a player announces any one word.

In the subsequent turns, a player announces a word that satisfies the following conditions:

That word is not announced before.

The first character of that word is the same as the last character of the last word announced.

In this game, he is practicing to announce as many words as possible in ten seconds.

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

Constraints

N is an integer satisfying 2 \leq N \leq 100.

W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

As hoge is announced multiple times, the rules of shiritori was not observed.

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No



Sample input:
4
hoge
english
hoge
enigma


Sample output:
No

Submission status: Accepted

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

say = []

flag = True

pre = ""

for s in w:
    if pre != "" and pre != s[0]:
        flag = False

    if s in say:
        flag = False
    
    say.append(s)
    pre = s[-1]

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

Submission status: Accepted

Solution code:
n = int(input())
w_dic =	{}
for i in range(n):
    w = input()
    if w_dic.get(w, False):
        print('No')
        break
    if i != 0:
        if last_word != w[0]:
            print('No')
            break
    last_word = w[-1]
    w_dic[w] = True
    if i == n-1:
        print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

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

last_str = li[0][0]

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

Submission status: Accepted

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

Submission status: Accepted

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

if len(set(W)) != N:
    print("No")
else:
    bw = W[0]
    for w in W[1:]:
        if w[0] != bw[-1]:
            print("No")
            break
        bw = w
    else:
        print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
w = []
duplication = 0
series = 1
for i in range(N):
    w.append(str(input()))
for i in range(1,N):
    if w[i-1][-1] != w[i][0]:
        series = 0
        break
for i in range(N-1):
    for j in range(i+1,N):
        if w[i] == w[j]:
            duplication = 1
            break
if duplication == 0 and series == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

seen = []
before = ''
flag = True

for i in strli:
    if before != '':
        if before[-1] != i[0]:
            flag = False
    if i in seen:
        flag = False
    if not flag:
        break
    before = i
    seen.append(i)

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

Submission status: Accepted

Solution code:
N=int(input())

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

flg=0

if len(W)!=len(set(W)):
    flg+=1

for i in range(len(W)-1):
    if W[i][-1]!=W[i+1][0]:
        flg+=1
        break

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

Submission status: Accepted

Solution code:
if __name__ == '__main__' :
    N = int(input())
    ws = []
    for i in range(0,N):
        ws.append(input())

    if len(ws) != len(set(ws)):
        print('No')
        exit()
        
    before = ws[0][0]
    for w in ws:
        if before != w[0]:
            print('No')
            exit()
        else:
            before = w[len(w)-1]
                  
    print('Yes')

Submission status: Accepted

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

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

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

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = {}
ans = "Yes"
for i in range(0,n):
    W = input()
    w[W] = w.get(W,0) + 1
    if i >= 1:
        if e != W[0]:
            ans = "No"
    if w[W] >= 2:
        ans = "No"
    e = W[-1]
print(ans)

Submission status: Accepted

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

for n in range(N-1):
  w = W[-1]
  W = input()
  if w != W[0] or W in Wlist:
    a = 0
    break
  else:
    Wlist.append(W)
    w = W[-1]
    a = 1

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

Submission status: Accepted

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

for i in range(1, N):
    if Ws[i][0] != Ws[i - 1][-1] or Ws[i] in Ws[:i]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

arr = [];
flag=0;
for i in range(n):
	arr.append(input())

for i in range(n):
	if i>0:

		j = i-1;

		if ( arr[i][0] == arr[i-1][-1] ):
			
			while( j >=0 ):

				if arr[i]==arr[j]:
					flag=1;
					break;
				j-=1;
			if flag==1:
				break;
		else:
			flag=1;
			break;


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

Submission status: Accepted

Solution code:
n=int(input())
d=set()
m=""
for i in range(n):
    s=input()
    if i>0 and (s in d or s[0]!=m[-1]):
        print("No")
        exit()
    m=s
    d.add(s)
        
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

used = []
pre = input()
for _ in range(N-1):
  used.append(pre)
  word = input()
  if word in used or pre[-1] != word[0]:
    print("No")
    exit()
  else:
    pre = word

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

check = []
check.append(w[0])
for i in range(1, n, 1):
    if(w[i-1][-1] == w[i][0]):
        if((w[i] in check) == False):
            check.append(w[i])
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
# encoding: utf-8
N = int(input())
W = list([input() for i in range(N)])

ans = "Yes"

for i, Wi in enumerate(W):
    # rule 1
    if W.count(Wi) > 1:
        ans = "No"
        break
    # rule 2
    if i == 0:
        hdr = Wi[-1]
        continue
    # i > 0
    if Wi[0] != hdr:
        ans = "No"
        break
    hdr = Wi[-1]

print(ans)

Submission status: Accepted

Solution code:

N = int(input())

ans = 1
w_set = set()
previous_word = ''
for i in range(N):
    w = str(input())
    if i != 0:
        if previous_word[-1] == w[0]:
            pass
        else:
            ans = 0
            break
    if w in w_set:
        ans = 0
        break
    previous_word = w
    w_set.add(w)

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

Submission status: Accepted

Solution code:
n = int(input())
first_word = input()
word_list = [first_word]
last_char = first_word[-1:]
flag = 0
for i in range(n-1):
    word = input()
    word_list.append(word)
    first_char = word[0]
    if first_char == last_char:
        last_char = word[-1:]
    else:
        flag = 1
        break;
if(flag):
    print("No")
else:
    if(n == len(list(set(word_list)))):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=input()
A=[]
for i in range(N):
	x=raw_input()
	if x in A:
		print "No"
		quit()
	if i==0:
		A.append(x)
		last=x[-1]
	else:
		if last!=x[0]:
			print "No"
			quit()
		else:
			A.append(x)
			last=x[-1]
else:
	print "Yes"

Submission status: Accepted

Solution code:
n=int(input())

w=[]
ans=0

for i in range(n):
    a=input()
    w.append(a)
    if i>0:
        if w[i][0]==w[i-1][-1]:
            ans+=1

li=list(set(w))
l=len(li)

if l==n and ans==n-1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import math
import sys

n = int(input())

words = list()

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


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

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

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())

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

c=[]
f=1
for i in range(len(s)):
    if i < len(s)-1:
        if s[i][-1:] != s[i+1][0]:
            print("No")
            f=0
            break
    if s[i] not in c:
        c.append(s[i])
    else:
        print("No")
        f=0
        break

if f:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    """
    はじめ、好きな単語を発言する
    以降、次の条件を満たす単語を発言することを繰り返す
        その単語はまだ発言していない単語である
        その単語の先頭の文字は直前に発言した単語の末尾の文字と一致する
    """
    N = int(input())
    W = [input() for _ in range(N)]

    ans = AC(N, W)
    print(ans)


def AC(N, W):
    for i, w in enumerate(W[1:]):
        if W.count(w) >= 2:
            return "No"

        if W[i][-1] != w[0]:
            return "No"

    return "Yes"


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
words = [input() for _ in range(n)]
prev = words[0]
memory = []
ans = 'Yes'
for i,w in enumerate(words):
  if i == 0:
    memory.append(w)
    continue
  if prev[-1] != w[0]:
    ans = 'No'
    break
  prev = w
  if w in memory:
    ans = 'No'
    break
  memory.append(w)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

say = []
word = input()
say.append(word)
ans = 'Yes'

for i in range(n-1):
    word = input()
    if word in say:
        ans = 'No'

    elif word[0] != say[-1][-1]:
        ans = 'No'

    else:
        say.append(word)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
w_set = set()
w_set.add(w[0])

ans = 'Yes'
for i in range(1, n):
    if w[i-1][-1] != w[i][0] or w[i] in w_set:
        ans = 'No'
        break
    w_set.add(w[i])

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
pw = input()
wset = set()
wset.add(pw)
for _ in range(n - 1):
    w = input()
    if pw[-1] != w[0] or w in wset:
        print('No')
        exit()
    else:
        pw = w
        wset.add(w)
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for i in range(n):
    st=input()
    if st in s:
        print('No')
        exit()
    s.append(st)

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

Submission status: Accepted

Solution code:
def solve(N, list):
    d = set()
    for i, l in enumerate(list):
        if l in d:
            return "No"
        if i > 0 and l[0] != list[i - 1][-1]:
            return "No"
        d.add(l)
    return "Yes"


if __name__ == "__main__":
    l = input()
    N = int(l)
    list = [input() for _ in range(0, N)]
    print(solve(N, list))

Submission status: Accepted

Solution code:
N = int(input())

dic = {}
ans = 'Yes'
last = ''
for _ in range(N):
    s = input()
    if last == s[0] or last == '':
        last = s[-1]
        pass
    else:
        ans = 'No'
        break
    if dic.get(s, 0) == 0:
        dic[s] = 1
    else:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
W = [input().strip() for _ in range(N)]
is_already_said = [W[0]]
ans = 'Yes'
for word in W[1:]:
    if is_already_said[-1][-1] != word[0] or word in is_already_said:
        ans = 'No'
        break
    is_already_said.append(word)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

w=[]

for i in range(n):
    s=input()
    w.append(s)
    
w2 = list(set(w))

f=1

if len(w)>len(w2):
   f=-1

pre = list(w[0])

for i in range(1, n):
   now = list(w[i])
   
   if not pre[len(pre)-1]==now[0]:
       f=-1
   pre = []
   pre = now
       
if f>0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
#A,B= list(map(int,input().split()))	


words=[]
N=int(input())
ok=1
for i in range(N):
    s=input()
    if s in words:
        ok = 0
#        print("double",s)
        break
    
    if i != 0 and words[-1][-1] != s[0]:
        ok=0
#        print(words[-1][-1], s[0],i)
        break

    words.append(s)

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

Submission status: Accepted

Solution code:
N = int(input())

judge = True
w = input()

word_list = [w]
count = 0

while judge and count < N-1:
    w = input()
    if w[0] == word_list[count][-1] and not(w in word_list):
        count += 1
        word_list.append(w)
    else:
        judge = False
        break

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

Submission status: Accepted

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

for i in range(N):
  w = input()
  words.append(w)
  
signal=1

for j in range(1,N):
  for k in range(j):
    if words[k]==words[j]:
      signal=0
  if words[j-1][-1]!=words[j][0]:
    signal=0
    
if signal==1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n=int(input())
ans='Yes'
s=input()
alist=[s]
for i in range(n-1):
    new=input()
    if new in alist:ans='No'
    if new[0]!=alist[-1][-1]:ans='No'
    alist.append(new)
print(ans)

Submission status: Accepted

Solution code:
n =  int(raw_input())
dic = {}
flag = 0
lis = []
for i in xrange(n):
    s = raw_input()
    lis.append(s)
    if s in dic:
        flag = 1
    else:
        dic[s] = 1
for i in range(1, n):
    #print lis[i][len(lis[i])-1:]
    #print lis[i]
    #print lis[i][0:1]
    #print lis[i-1][len(lis[i-1])-1:]
    if lis[i][0:1] != lis[i-1][len(lis[i-1])-1:]:
        flag = 1
        break
if flag == 1:
    print "No"
else:
    print "Yes"

Submission status: Accepted

Solution code:
g=0
x=0
w=[input() for i in range(int(input()))]
if len(set(w))==len(w):
   n=w[0][::-1][0]
   for i in range(1,len(w)):
      if w[i][0]==n:
         n=w[i][::-1][0]
      else:break
      x=i
if x==len(w)-1:g=1

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

Submission status: Accepted

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


def main():
    n = int(input())
    word = list()
    pre_word = input()
    word.append(pre_word)

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

        if w not in word:
            word.append(w)

            if pre_word[-1] != w[0]:
                print('No')
                exit()
        else:
            print('No')
            exit()

        pre_word = w

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

out = False
word1 = input()
words = [word1]
for i in range(n-1):
    next_w = input()
    if next_w in words:
        out = True
        break
    if next_w[0:1] != words[-1][-1]:
        out = True
        break
    words.append(next_w)
if out:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
word = input()
W = [input() for i in range(N-1)]
used = set()
used.add(word)

for w in W:
    if w[0] == word[-1] and w not in used:
        used.add(w)
        word = w
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

dic = [input()]

flag = "Yes"

for i in range(0,N-1):
    k = input()
    if (k in dic) or (dic[-1][-1] is not k[0]):
        flag = "No"
        break
    else:
        dic.append(k)

print(flag)

Submission status: Accepted

Solution code:
import sys

N = int(input())

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

WW = set(W)

if len(W) != len(WW):
    print("No")
    sys.exit()
else:
    for i in range(N-1):
        a = W[i][-1]
        b = W[i+1][0]
        if a != b:
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

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


def check():
    for i in range(N):
        w = input()
        if (i != 0 and prev[-1] != w[0]) or (w in words):
            return "No"
        prev = w
        words.append(w)
    return "Yes"


print(check())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def run(n, w):
    for i in range(n-1):
        if w[i] in w[i+1:]:
            return 'No'
        if w[i][len(w[i])-1] != w[i+1][0]:
            return 'No'
    return 'Yes'


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

words = []

shiritori = True

first = input()
end = first[len(first)-1]
words.append(first)


for i in range(1,N):
    w = input()
    beg = w[0]
    if beg != end:
        shiritori = False
    if w in words:
        shiritori = False
    end = w[len(w)-1]
    words.append(w)

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    W = []
    for i in range(N):
        W.append(input())
    
    alr = [W[0], ]
    for i in range(1, N):
        if W[i] in alr:
            return "No"
        elif W[i][0] != W[i-1][-1]:
            return "No"
        else:
            alr.append(W[i])
    return "Yes"

if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

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

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

print('Yes')

Submission status: Accepted

Solution code:
N=int(input())

word=['a']*N
word[0]=input()




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

wordunique=list(set(word))

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

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for _ in range(n)]
setw = set(w)
if(len(setw)!=len(w)):
    print("No")
    exit()

endw=w[0][-1]
for ww in w[1:]:
    if(endw!=ww[0]):
        print("No")
        exit()
    endw=ww[-1]

print("Yes")

Submission status: Accepted

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

l = []
c = False
o = ""
for a in w:
    if a in l:
        print("No")
        exit()
    if c == False or o == a[0]:
        l.append(a)
        o = a[-1]
        c = True
    else:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
used=[]
start=input()
used.append(start)
flag=0
for i in range(n-1):
    tmp=input()
    if start[-1]!=tmp[0] or tmp in used:
        flag=1
        break
    used.append(tmp)
    start=tmp

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

Submission status: Accepted

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

ans = "Yes"
check = []
head = W[0][0]
for word in W:
	if (word[0] == head) and (not (word in check)):
		check.append(word)
		head = word[-1]
	else:
		ans = "No"
		break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ktb = []
error = 0
for i in range(n):
    ktb.append(list(input()))
    if i != 0:
        if ktb[i - 1][-1] != ktb[i][0]:
            error = 1
        for j in range(i - 1):
            if ktb[i] == ktb[j]:
                error = 1
                break
if error == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())

W = set()
S = input()
W.add(S)
for _ in range(N - 1):
    C = input()
    if S[-1] != C[0] or (C in W):
        print("No")
        break
    S = C
    W.add(C)
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
before = ""
all = set()
check = True
for i in range(N):
    s = input()
    if i == 0:
        before = s
        all.add(s)
    else:
        if before[-1] == s[0]:
            before = s
            all.add(s)
        else:
            check = False
if check:
    print("Yes" if len(all)==N else "No")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
W = [0 for i in range(N)]
for i in range(N):
    W[i] = input()
shiritori = True
S = set(W)
if len(S) != N:
    shiritori = False


for i in range(N-1):
    length = len(W[i])
    if W[i][length-1] != W[i+1][0]:
        shiritori = False

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

Submission status: Accepted

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

Submission status: Accepted

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


def judge(ws):
    used_words = {ws[0]}
    n = len(ws)
    for i in range(1, n):
        if ws[i] in used_words or ws[i - 1][-1] != ws[i][0]:
            return False
        used_words.add(ws[i])
    return True


def main():
    ws = [input() for _ in range(int(input()))]
    print("Yes" if judge(ws) else "No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
flag = 0
l = []
for i in range(n):
    w = input()
    # print(w)
    if i != 0:
        if (w[0] != before[-1]) or (w in l):
            flag = 1

    l.append(w)
    before = w
    # print(flag, l)


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

Submission status: Accepted

Solution code:
n = int(input())
w = []

ans = 0

for i in range(n):
    W = input()
    s = set(w)
    if W in s:
        ans = 1
    w.append(W)


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


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

Submission status: Accepted

Solution code:
N = int(input())
ans = True
said = []
for i in range(N):
    word = input()
    if word in said:
        ans = False
        break
    if i != 0:
        if said[i - 1][-1] != word[0]:
            ans = False
            break
    said.append(word)
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def main():
    n = int(input())
    arry = [input() for _ in range(n)]
    for i in range(1, n):
        if arry[i-1][-1] != arry[i][0] or len(arry) != len(set(arry)):
            print('No')
            exit()
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n=int(input())
wordList=[input()]
for _ in range(n-1):
    word =input()
    if word in wordList:
        print("No")
        sys.exit()
    elif wordList[-1][-1]!=word[0]:
        print("No")
        sys.exit()
    wordList.append(word)
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
w = input()

l = w[-1]
a = []

a.append(w)

f_no = False

for n in range(N-1):
    w = input()
    if l != w[0]:
        f_no = True
    a.append(w)
    l = w[-1]

if f_no == False:
    if len(a) == len(list(set(a))):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math

# K = int(input())
# N, K = map(int, input().split())
# A = list(map(int, input().split()))

N = int(input())

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

    if new in W:
        # print('duplicate', new)
        print('No')
        exit(0)
    W.append(new)

    if n > 0:
        first = W[n][0]
        if first is not last:
            # print('no shiri', first, new)
            print('No')
            exit(0)
        
    last = new[len(W[n]) - 1]
    # print('new, last=', new, last)

print('Yes')

Submission status: Accepted

Solution code:
n=int(input())

def judge(n):
    preword = input()
    words=[preword]

    for _ in range(n-1):
        word = input()
        if word[0] != preword[-1]: return "No"
        elif word in words: return "No"
        else:
            words.append(word)
            preword=word
    return "Yes"
        
print(judge(n))

Submission status: Accepted

Solution code:
N = int(input())
W = input()
L = []
L.append(W)
last = W[-1]
ans = 'Yes'
for _ in range(N-1):
    w = input()
    if w in L:
        ans = 'No'
    if last == w[0]:
        last = w[-1]
        L.append(w)
    else:
        ans = 'No'
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    words = []
    for i in range(n):
        words.append(input())
    if len(words) != len(set(words)):
        print('No')
        return
    for w1, w2 in zip(words, words[1:]):
        if w1[-1] != w2[0]:
            print('No')
            return
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

isok = True
w = input()
W.add(w)
back = w[-1]
for i in range(N-1):
    w = input()
    if w in W or w[0]!=back: isok=False
    W.add(w)
    back = w[-1]
    
if isok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
prev = None
ok = True
seen = set()
for n in range(N):
    w = input()
    if prev is None:
        prev = w
    else:
        if prev[-1] != w[0]:
            ok = False
    if w in seen:
        ok = False
    seen.add(w)
    prev = w
if ok:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
m = {}
prv = "!"
ok = True
for i in range(N):
    s = input()
    
    try:
        m[s]
        ok = False
    except:
        m[s] = True
        
        if prv == "!" or prv[-1] == s[0]:
            prv = s
        else:
            ok = False

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

Submission status: Accepted

Solution code:
N=int(raw_input())

W_list = []
flag=True
before = ""
for i in range(N):
    W = raw_input()
    if W in W_list:
        flag=False
    if i!=0 and W[0]!=before:
        flag=False
    W_list.append(W)
    before = W[-1]

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

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
from collections import defaultdict
d = defaultdict(int)
s="Yes"
for i in range(n):
 x=input()
 if i>0 and y[-1]!=x[0]:
   s="No"
 d[x]+=1
 if d[x]>1:
   s="No"
 y=x
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
rule = True
pre = input()
used = [pre]
for i in range(N-1):
    temp = input()
    if pre[-1] != temp[0] or temp in used:
        rule = False
    used.append(temp)
    pre = temp

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

Submission status: Accepted

Solution code:
N = int(input())

Flag = True
words = []
for i in range(N):
    word = str(input())
    if not i==0:
        if word[0] != l:
            Flag =  False
        if word in words:
            Flag = False
    l = word[-1]
    words.append(word)

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