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 i in range(n)]
a = []
a.append(w[0])
now = w[0]
ans = True
for i in w[1:]:
    if i not in a and now[-1] == i[0]:
        now = i
        a.append(i)
    else:
        ans = False
        break
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N=int(input())
A=list(input()for i in range(N))
if len(A)==len(set(A)):
    if all(A[i][-1]==A[i+1][0] for i in range(N-1)):
        print('Yes')
    else:print('No')
else:print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Word = [W[0]]
for i in range(1,n):
    s = W[i-1]
    t = W[i]
    
    if(s[-1] != t[0] or t in Word): 
        flg = 0
        break
    Word.append(t)
    
if (flg): print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
N = int(input())
dic = dict()
for i in range(N):
    S = input()
    if S in dic:
        dic[S] += 1
    else:
        dic[S] = 1
    Start  = S[0]
    if i != 0:
        if Start != End or dic[S] > 1:
            print("No")
            exit()
    End = S[len(S)-1]
print("Yes")

Submission status: Accepted

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

for n in range(N-1):
  if W[n][-1]!=W[n+1][0] or W.count(W[n])!=1:
    a = "No"

print(a)

Submission status: Accepted

Solution code:
N = int(input())

list_0=[]

for i in range(N):
  W = str(input())
  if W in list_0:
    print('No')
    exit()
  else:
    list_0.append(W)

for _ in range(N-1):
  if list_0[_][len(list_0[_])-1]==list_0[_+1][0]:
    pass
  else:
    print('No')
    exit()

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

used_word = []
cher = ""
for _ in range(N):
    W = input()
    if not cher:
        used_word.append(W)
        cher = W[-1]
    else:
        if W[0] == cher and W not in used_word:
            used_word.append(W)
            cher = W[-1]
        else:
            print("No")
            break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N, *W = open(0).read().split()

is_ok = True

if len(W) != len(set(W)):
    is_ok = False
else:
    for i, w in enumerate(W):
        if i > 0:
            if before_w != w[0]:
                is_ok = False
                break
        
        before_w = w[-1]
    
if is_ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
s=[input()]
for i in range(n-1):
    w=input()
    if s[-1][-1]==w[0]:
        if not w in s:
            s.append(w)
            
if len(s)==n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list_w = []
flag = 0
N = int(input())
for i in range(N):
    W = input()
    list_w.append(W)
    if i >=1 and list_w[-2][-1] != W[0]:
        flag = 1
if len(set(list_w)) != N or flag == 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    h =[]
    for i in range(n):
        w = input()
        if i == 0:
            h.append(w)
            continue
        if w in h:
            print('No')
            exit()
        if h[i-1][-1] != w[0]:
            print('No')
            exit()
        h.append(w)
    print('Yes')


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())

lis = [""]
ans = "Yes"
for i in range(1,N+1):
    W = input()
    if i == 1:
        pass
    else:
        if ((W in lis) == False) and (W[0] == lis[i-1][-1]):
            pass
        else:
            ans = "No"
    lis.append(W)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
check=[]
s=input()
check.append(s)
ans=0
for i in range(n-1):
  keep=s[-1]
  s=input()
  if keep != s[0]:
    ans=1
  if str(s) in check:
    ans = 1
  else:
    check.append(s)
print(["Yes","No"][ans])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [input() for _ in range(N)]
now = A[0]
Done = set()
Done.add(A[0])
for a in A[1:]:
    if a in Done:
        print('No')
        exit()
    if now[-1] == a[0]:
        now = a
        Done.add(a)
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

is_ok = (len(set(W)) == N)
for i in range(1, N):
    if W[i - 1][-1] != W[i][0]:
        is_ok = False

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
apple = []
count = 0
for _ in range(n):
    apple.append(str(input()))
for i in range(1,n):
    if apple[i-1][-1] == apple[i][0] and apple[i-1] not in apple[i:]:
        pass
    else:
        count = 1
        break
if apple[-1] not in apple[:-1] and count == 0 and apple[-2][-1]==apple[-1][0]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
w = [ input() for i in range(n) ]
#n = 9
#w = ['basic', 'c', 'cpp', 'php', 'python', 'nadesico', 'ocaml', 'lua', 'assembly']

a = set()
a.add(w[0])
ck = 0
for i in range(1,n):
  if w[i] in a:
    break
  else:
    a.add(w[i])
  
  if w[i][0] != w[i-1][-1]:
    break

else:
  ck = 1

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    W = [input() for _ in range(N)]
    if len(set(W)) != N:
        print("No")
        return
    l = W[0][0]
    for w in W:
        if w[0] != l:
            print("No")
            return
        l = w[-1]
    print("Yes")

resolve()

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
N=int(input())
s=input()
d[s]+=1
x=s[-1]
for i in range(N-1):
  s=input()
  if s[0]==x and d[s]==0:
    x=s[-1]
    d[s]+=1
  else:
    print('No')
    exit(0)
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
words = [input() for i in range(n)]
mae = ''
ans = 'Yes'

for i in range(n):
    if i == 0:
        word = words[0]
        leng = len(word)
        mae = word[leng-1]
    else:
        word = words[i]
        if mae != word[0:1] or words.count(word) >= 2:
            ans = 'No'
            break
        else:
            leng = len(word)
            mae = word[leng-1]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for _ in range(n)]
e = w[0][-1]
cnt = 1

for i in range(1, n):
    if w[i][0] == e:
        cnt += 1
        e = w[i][-1]

if cnt == n and len(set(w)) == n:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l = [l]

ans = 0
for i in range(n-1):
    x = str(input())
    if x not in l and l[i][-1]==x[0]:
        l.append(x)
        continue
    else:
        ans = -10000000000
        break
if ans == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for i in range(N):
    s = input()
    if i == 0:
        end_w = s[0]

    if s in lis:
        print("No")
        exit()
    else:
        if s[0] == end_w:
            lis.append(s)
            end_w = s[-1]
        else:
            print("No")
            exit()

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
word_list = []
flag = True
for i in range(n):
    word = input()
    if word_list == []:
        word_list.append(word)
    else:
        if (word_list[-1][-1] == word[0]) and (word not in word_list):
            word_list.append(word)
        else:
            flag = False
            break
            
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
flag=True
a=0
l=[]
for i in range(n):
    b=a
    l.append(b)
    a=list(input())
    if i>0:
        if a[0]!=b[-1] or a in l:
            flag=False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N=int(input())
W=[input() for i 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 _ in range(N)]
words = [''] * N
for i in range(N):
    if i == 0:
        words[i] = W[i]
        continue
    if (W[i] in words) or (W[i - 1][-1] != W[i][0]):
        print('No')
        break
    words[i] = W[i]
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

lis = []
for _ in range(n):
    lis.append(input())
    
if len(lis) != len(set(lis)):
    print("No")
    exit()
 
tmp = lis[0][-1]
for i in range(1,n):
    if lis[i][:1] != tmp:
        print("No")
        exit()
    else:
        tmp = lis[i][-1]

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
w=[]
flag=True
for i in range(n):
    w.append(input())
    
for i in range(n-1):
    if w[i][-1]!=w[i+1][0]:
        #print(i,"out1")
        flag=False

for i in range(n-1):
    for j in range(i+1,n):
        if(w[i]==w[j]):
            #print(i,j,"out2")
            flag=False

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

Submission status: Accepted

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

resolve()

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
def actual(n, W):
    # 重複があればアウト
    if len(set(W)) != len(W):
        return 'No'

    for i in range(len(W) - 1):
        word_now, word_next = W[i], W[i + 1]

        tail = word_now[-1]
        head = word_next[0]

        if tail != head:
            return 'No'

    return 'Yes'

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

print(actual(N, W))

Submission status: Accepted

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

already = [W[0]]
out='Yes'
for i in range(1,N):
    if W[i-1][-1] != W[i][0]:
        out='No'
        break
    elif W[i] in already:
        out='No'
        break
    already.append(W[i])

print(out)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
ok=True
W2=input()
lis=[W2]
for i in range(N-1):
    W=W2
    W2=input()
    if W2 in lis:
        ok=False
        break
    lis.append(W2)
    if(W2[0]!=W[len(W)-1]):
        ok=False
        break
if(ok):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

# In[10]:


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


# In[11]:


if len(set(W)) != N:
    print("No")
else:
    for i,word in enumerate(W):
        if i > 0:
            if W[i-1][-1] != word[0]:
                print("No")
                break
    else:
        print("Yes")


# In[ ]:

Submission status: Accepted

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

if len(w) != len(set(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())
w = []
for i in range(n):
    w.append(input())
ok = True
for i in range(n-1):
    sz = len(w[i])
    if w[i][sz-1] != w[i+1][0]: ok = False
for i in range(n):
    for j in range(n):
        if i != j and w[i] == w[j]:
            ok = False
if ok: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    now =""
    list=[]
    flag =True

    for i in range(n):
        s =input()
        if now =="":
            now=s
            list.append(s)
        elif now[len(now)-1] != s[0] or s in list:
            flag=False
            break
        else:
            now=s
            list.append(s)
    if flag:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for _ in range(N):
    W=input()
    if W in A:
        print('No')
        exit()
    else:
        A.append(W)

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

Submission status: Accepted

Solution code:
n = int(input())
ws = [str(input()) for i in range(n)]
t = ws[0][0]
for w in ws:
  if ws.count(w) > 1:
    print('No')
    break
  if t[-1] != w[0]:
    print('No')
    break
  else:
    t = w
    n-=1
if n == 0:
  print('Yes')

Submission status: Accepted

Solution code:
def f(l):
  prev = l[0][0]
  memo = []
  for i in range(len(l)):
    next = l[i]
    if next[0] != prev or next in memo:
      return "No"
    prev = next[-1]
    memo.append(next)
  return "Yes"

N = int(input())
l = [input() for _ in range(N)]
print(f(l))

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
    l.append(input())
    
x=set(l)
x=list(x)
c=0
if len(x)!=n:
    print('No')
else:
    for i in range(n-1):
        if l[i][-1]==l[i+1][0]:
            c+=1
    if c==n-1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n=int(input())
l=[input() for _ in range(n)]
b=l[0][-1]
for w in l[1:]:
    if l.count(w)>1 or not w[0]==b:
        print('No')
        exit()
    b=w[-1]
print('Yes')

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    W = []
    for _ in range(N):
        w = input()
        W.append(w)
    ans = [W[0]]
    for i in range(N-1):
        if ans.count(W[i+1]) != 0 or ans[i][-1] != W[i+1][0]:
            print("No")
            exit()
        else:
            ans.append(W[i+1])
    print("Yes")
resolve()

Submission status: Accepted

Solution code:
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

n = readInt()
d = defaultdict(int)
p="0"
for i in range(n):
	x = input()
	if p[-1]!=x[0]:
		if p!="0":
			print("No")
			exit()
	d[x]+=1
	p = x

for i in d:
	if d[i]>1:
		print("No")
		exit()

print("Yes")

Submission status: Accepted

Solution code:
def mi():
    return map(int, input().split())

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
itta=set()
flag=True
s=input()
owari=s[-1]
itta.add(s)
for i in range(n-1):
    s=input()
    if s[0]!=owari:
        flag=False
    owari=s[-1]
    if s in itta:
        flag=False
    itta.add(s)
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
x = False
if n == len(set(w)):
    if all(w[i-1][-1] == w[i][0] for i in range(1,n)):
        x = True
print('Yes' if x else 'No')

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
x = False
if n == len(set(w)):
    if all([w[i-1][-1] == w[i][0] for i in range(1,n)]):
        x = True
print('Yes' if x else 'No')

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

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

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
said = []
Wnow = input()
said.append(Wnow)

for i in range(N-1):
  Wnxt = input()
  if Wnow[-1] != Wnxt[0]:
    print('No')
    exit()
  if Wnxt in said:
    print('No')
    exit()
  said.append(Wnxt)
  Wnow = Wnxt
  
print('Yes')

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
words = []
chk = True
for i in range(n):
    w = input()
    if i == 0:
        next = w[-1]
        words.append(w)
    else:
        if w[0] != next:
            chk = False
            words.append(w)
        else:
            if w in words:
                chk = False
                words.append(w)
            else:
                next = w[-1]
                words.append(w)
if chk == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
W1 = input()
A = [W1]
c = W1[-1]
for i in range(N-1):
    W = input()
    if W in A:
        print('No')
        exit()
    elif c != W[0]:
        print('No')
        exit()
    A.append(W)
    c = W[-1]
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
l=[input()]
c=0
for i in range(n-1):
    s=input()
    if all([s not in l,s[0]==l[-1][-1]]):
        l.append(s)
    else:
        c+=1
print("Yes"if c==0 else "No")

Submission status: Accepted

Solution code:
N = int(input())
Already = []
W = input()
Already.append(W)
prevWord = W
flag = True
for i in range(N-1):
    W = input()
    for j in Already:
        if j == W:
            flag = False

    if W[0] != prevWord[-1]:
        flag = False
    
    Already.append(W)
    prevWord = W

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

Submission status: Accepted

Solution code:
n = int(input())
st = set([])

tail = ''
for i in range(n):
    w = input()
    if w in st:
        print('No')
        break
    if i != 0 and w[0] != tail:
        print('No')
        break
    st.add(w)
    tail = w[-1]
else:
    print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

s = W[0][-1]

ok = True
used = set()
used.add(W[0])
for w in W[1:]:
    if s != w[0] or w in used:
        ok = False

    s = w[-1]
    used.add(w)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()

used = {s}
ex = s[-1]

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

Submission status: Accepted

Solution code:
n=int(input())
s=set()
w=input()
s.add(w)
tmp=w[-1]
can=True
for i in range(n-1):
    w=input()
    if w in s:
        can=False
    s.add(w)
    if w[0]==tmp:
        tmp=w[-1]
    else:
        can=False
if can:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
words = []
for i in range(n):
  words.append(input())
words_set = list(set(words))
ans = 'Yes'
if len(words) == len(words_set):
  b = words[0][-1]
  for i in range(1, n):
    if b == words[i][0]:
      b = words[i][-1]
    else:
      ans = 'No'
      break
else:
  ans = 'No'
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = [str(input()) for i in range(n)]
used = []
count = 0
for i in range(n-1):
    if((w[i] not in used) and (w[i][-1] == w[i+1][0])):
        count += 1
        used.append(w[i])
if count == n-1 and w[-1] not in used:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

wordset = set()

for i, word in enumerate(W):
    if i == 0:
        wordset.add(word)
        continue
    # print(f"i:{i} word:{word[0]} W[i - 1][-1]:{W[i-1][-1]}", file=sys.stderr)
    if word in wordset or word[0] != W[i - 1][-1]:
        print("No")
        break

    wordset.add(word)
else:
    print("Yes")

Submission status: Accepted

Solution code:
# B - Shiritori

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

word = set()
word.add(W[0])
ans = 'Yes'
for i in range(1, N):
    if W[i] in word:
        ans = 'No'
        break
    if W[i-1][-1] != W[i][0]:
        ans = 'No'
        break
    word.add(W[i])

print(ans)

Submission status: Accepted

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

if len(W) != len(set(W)):
    print('No')
else:
    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 = [str(input()) for _ in range(n)]

if len(set(w)) != n:
	print('No')
	exit()
memo = w[0][0]
for i in range(n):
	a = w[i]
	if a[0] != memo:
		print('No')
		exit()
	memo = a[-1]
print('Yes')

Submission status: Accepted

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

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

if len(W) ==  len(set(W)) and flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

Submission status: Accepted

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

for w in range(len(Ws)):
    if Ws.count(Ws[w])>=2:
        print("No")
        exit()
        
for x in range (1,len(Ws)):
    if Ws[x][0] != Ws[x-1][-1]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
N=int(input())

out=False
w=set([])
tmp=input()
end=tmp[-1]
w.add(tmp)

for i in range(N-1):
  tmp=input()
  if end!=tmp[0]:
    out=True
  end=tmp[-1]
  w.add(tmp)

if out or len(w)!=N:
  print("No")
else:
  print("Yes")