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:


def main():

    N = int(input())
    past=[]
    past.append(input())

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

    print('Yes')


        
    
if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(ls)

count = 0
if c.most_common()[0][1] >= 2:
    print("No")
else:
    for i in range(len(ls)-1):
        if ls[i][-1] == ls[i+1][0]:
            count += 1
    if count == len(ls)-1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
words = lambda t : list(map(t, input().split()))
n = int(input())
a = set()
c = "#"
ans = True
for _ in range(n):
    s = input()
    if (c != "#" and c != s[0]) or (s in a):
        ans = False
        break
    a.add(s)
    c = s[-1]
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

result = 'Yes'
used = []
last_char = ''
for word in words:
    if not used:
        used.append(word)
        last_char = word[-1]
        continue
    if word[0] != last_char or word in used:
        result = 'No'
        break
    used.append(word)
    last_char = word[-1]

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for a, b in zip(W, W[1:]):
    if a[-1] != b[0] or W.count(b) > 1:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
err = False
word_list = []
for i in range(n):
    s = input()
    if i == 0:
        last_letter = s[-1]
        word_list.append(s)
        continue
    if s in word_list:
        err = True
    else:
        if last_letter != s[0]:
            err = True
        else:
            last_letter = s[-1]
            word_list.append(s)
if err:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

ok = True
for i in range(len(w) - 1):
    if w[i][-1] != w[i + 1][0]:
        ok = False

if len(set(w)) != len(w):
    ok = False

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = [0] * N 
check = 0
for i in range(N):
    S[i] = input()

#同じ言葉がないか調べる
A = list(set(S))
if len(A) == len(S):
    pass
else:
    check = 1

for i in range(1, N):
    if S[i][0] == S[i-1][-1]:
        pass
    else:
        check = 1

if check == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

ans = 1
s = w[0][-1]
for x in w[1:]:
    if x[0] == s:
        s = x[-1]
    else:
        ans = 0
        break

import collections
c = collections.Counter(w)
if c.most_common()[0][1] > 1:
    ans = 0

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

Submission status: Accepted

Solution code:
n=int(input())
a = set()
pi = ""
no = 0
for i in range(n):
    x = input()
    a.add(x)
    if i > 0 and pi[-1] != x[0]:
        no = 1
    pi = x
if n != len(a):
    no = 1
print(('Yes','No')[no])

Submission status: Accepted

Solution code:
def main28():
    num = int(input())
    st = []
    for i in range(num):
        st.append(input())
    for i in range(1,num,1):
        if st[i-1][-1] != st[i][0]:
            print("No")
            return
        for j in range(i):
            if st[j] == st[i]:
                print("No")
                return
    print("Yes")

if __name__ == "__main__":
    main28()

Submission status: Accepted

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

if len(set(words)) != n:
    print("No")
else:
    can = True
    for i in range(1, n):
        if words[i-1][len(words[i-1])-1] != words[i][0]:
            can = False
    if can:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

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

#print(ans)
ans2=set(ans)
#print(ans2)

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

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

Submission status: Accepted

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

if len(a) != len(set(a)):
    print("No")
else:
    for i in range(N-1):
        aa = a[i]
        bb = a[i+1]
        if aa[-1] != bb[0]:
            print("No")
            break
    else:
        print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
a=input()
b=a[len(a)-1]
word1=[a]
word2=[b]
c=0

for i in range(n-1):
    aa=input()
    bb=aa[0]
    if aa not in word1 and word2[i]==bb:
        word1.append(aa)
        top=aa[len(aa)-1]
        word2.append(top)
    else:
        c=1
        break
        
print("Yes" if c==0 else "No")

Submission status: Accepted

Solution code:
N = int(input())
W1 = input()
past = set()
past.add(W1)
last = W1[-1]
ans = 'Yes'
for _ in range(N - 1):
    W = input()
    if W in past or not W.startswith(last):
        ans = 'No'
    else:
        past.add(W)
        last = W[-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = True
li = [input() for _ in range(n)]

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

Submission status: Accepted

Solution code:
n = int(input())
word = input()
words = [word]
for _ in range(n-1):
  word = input()
  if word in words or not word.startswith(words[-1][-1]):
    print('No')
    exit()
  words.append(word)
print('Yes')

Submission status: Accepted

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

for i in range(1, n):
    if a.count(a[i]) > 1:
        print('No')
        exit()
    if a[i-1][-1] != a[i][0]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for i in range(n)]
a=0
for i in range(1,n):  
  if w[i-1][-1] == w[i][0]:
    if w[i] not in w[:i]:
      a=a
    else:
      a+=1
  else:
    a+=1
if a==0:print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
N=int(input())
A=list()
for i in range(N):
  B=str(input())
  if i!=0:
    if A[i-1][len(A[i-1])-1]!=B[0] or B in A:
      print('No');exit()
  A.append(B)

print('Yes')

Submission status: Accepted

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

vocab = {W[0]}
for i in range(1, N):
    if W[i] in vocab:
        print("No")
        exit()
    vocab.add(W[i])

    if W[i-1][-1] != W[i][0]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

pre = W[0][0]
ok = True
for w in W:
    if w[0] != pre[-1] or w in checked:
        ok = False
        break
    pre = w
    checked.append(w)

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
WLst = [0] * N

for i in range(N):
    WLst[i] = input()

if WLst.count(WLst[0]) != 1:
    print('No')
    sys.exit()

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

print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if (a * b) % 2:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    w = SR(n)
    d = []
    for i in w:
        d.append("".join(i))
    if len(set(d)) != n:
        print("No")
        return
    for i in range(n - 1):
        if w[i][-1] != w[i + 1][0]:
            print("No")
            return
    print("Yes")
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

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

c = 0
for j in range(N-1):
    if W.count(W[j+1]) == 1:
        if W[j+1][0] == W[j][-1]:
            c += 1

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

Submission status: Accepted

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

past = []
flag = 0
for i in range(n):
    if i == 0:
        past.append(w[i])
    else:
        if w[i] in past:
            flag = 1
            break
        else:
            if w[i-1][-1] == w[i][0]:
                past.append(w[i])
            else:
                flag = 1
                break
if flag == 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = input()
memo = {s:1}
flag = True
for i in range(N-1):
  t = input()
  if s[-1] != t[0]:
    flag = False
  if t not in memo:
    memo[t] = 1
  else:
    flag = False
  s = t
print('Yes' if flag else 'No')

Submission status: Accepted

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

res='Yes'

su=set(s)
if len(su)<n:
	res='No'

#print(res)   
    
for i in range(n-1):
	f=s[i][len(s[i])-1]
	#print(f)
	b=s[i+1][0]
	#print(b)
	if f!=b:
		#print(i)
		res='No'
		break

print(res)

Submission status: Accepted

Solution code:
n = int(input())
w = []
st = set()
for i in range(n):
    s = input()
    st.add(s)
    w.append(s[0] + s[-1])
if len(st) != n:
    print('No')
    exit()
for i,j in zip(w, w[1:]):
    if i[-1] != j[0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
ws = []
flag = 0
for i in range(n):
  w = input()
  if ws != []:
    if w in ws:
      print("No")
      flag = 1
      break
    elif ws[-1][-1] != w[0]:
      print("No")
      flag = 1
      break
    else:
      ws.append(w)
  else:
    ws.append(w)

if flag == 0:
  print("Yes")

Submission status: Accepted

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

for i in range(N-1):
    for j in range(i+1, N):
        if W[i]==W[j]:
            print('No')
            exit()

    if W[i][-1]!=W[i+1][0]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lst = []
for i in range(n):
  x = input()
  if i==0:
    lst.append(x)
    continue
  else:
    if (x not in lst)&(str(lst[i-1])[-1:] == x[0]):
      lst.append(x)
      continue
    else:
      print("No")
      quit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
ws = [input() for i in range(n)]
if len(Counter(ws)) < len(ws):
    print("No")
    exit(0)

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

Submission status: Accepted

Solution code:
# ABC 109, B - shiritori

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


used = []

for i in range(n):
    if i == 0:
        used.append(w[i])
        tail = w[i][-1]
    else:
        # no if the same word is used
        if w[i] in used:
            print('No')
            break
        # no if the hean and tail is not equal
        elif w[i][0] != tail:
                print('No')
                break
        else:
            used.append(w[i])
            tail = w[i][-1]
else:
    print('Yes')

Submission status: Accepted

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

    W = []
    for i in range(n):
        tmp = list(input())
        W.append(tmp)

    c = ""
    for w in W:
        if W.count(w) > 1:
            return False

    for w in W:
        cc = w[len(w) - 1]
        if c == "" or c == w[0]:
            c = cc
        else:
            return False
    
    return True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
Ws = []
for x in range(100):
  Ws.append(str(input()))
  if x+1 == N:
    break

words = [Ws[0]]
tmp = list(Ws[0])[-1]
Ws.remove(Ws[0])

for y in Ws:
  if y in words:
    print('No')
    break
  elif tmp == list(y)[0]:
    words.append(y)
    tmp = list(y)[-1]
  else:
    print('No')
    break

if len(words) == N:
  print('Yes')

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    W = [str(input()) for _ in range(N)]

    mem = set([W[0]])

    answer = 'Yes'
    for i in range(1, N):
        if len(mem & set([W[i]])) == 0 and W[i-1][-1::] == W[i][0:1:]:
            mem.add(W[i])
        else:
            # print(W[i-1])
            # print(W[i-1][-1::])
            # print(W[i])
            # print(W[i][0:1:])
            # print(mem)
            # print(set([W[i]]))
            # print(len(mem & set(W[i])))
            answer = 'No'
            break
    print(answer)

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for i in range(n)]
a=0
for i in range(1,n):  
  if w[i-1][-1] == w[i][0]:
    if w[i] not in w[:i]:
      a=a
    else:
      a+=1
  else:
    a+=1
if a==0:print("Yes")
else:print("No")

Submission status: Accepted

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

for _ in range(n-1):
    t = input()
    if (t in l) or l[-1][-1]!=t[0]:
        print("No")
        exit()
    l.append(t)
print("Yes")

Submission status: Accepted

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

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    W = [input().strip() for _ in range(N)]
    m = {}
    for i in range(N-1):
        if W[i][-1] != W[i+1][0] or W[i+1] in m:
            print("No")
            return
        m[W[i]] = True
    print("Yes")

main()

Submission status: Accepted

Solution code:
a = int(input())
b = list(input() for i in range(a))
c = set(b)
d = 0

if len(c)!=a:
  print("No")
else:
  for i in range(a-1):
    if b[i][-1]!=b[i+1][0]:
      d = 1
  else:
    if d==0:
      print("Yes")
    else:
      print("No")

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
word_set = set()
valid = True
words = ["" for i in range(N)]
for i in range(N):
    words[i] = input()

word_set.add(words[0])
for i in range(1, N):
    if words[i-1][-1] != words[i][0] or words[i] in word_set:
        valid = False
        break
    word_set.add(words[i])
    
if valid:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
#n, m = map(int,input().split())
#ls = list(map(int,input().split()))
#ls = [list(map(int,input().split())) for i in range(n)]
ls = [input() for i in range(n)]

for i in range(1,len(ls)):
  if ls[i][0] != ls[i-1][-1]:
    print("No")
    quit()
  if ls.count(ls[i]) >= 2:
    print("No")
    quit()
    
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
words = []
l = []
for i in range(N):
    a = input()
    if i == 0:
        l.append(a)
        b = list(a)
        words.append(b[len(b)-1])
    elif i > 0:
        b = list(a)
        if i == N-1:
            words.append(b[0])
        else:
            words.append(b[0])
            words.append(b[len(b)-1])
        l.append(a)

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

for h in range(0,len(words),2):
    if words[h] != words[h+1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

done = []

for i in range(n):
    if i == 0:
         before = str(w[i])
         done.append(w[i])
    else:
        target = str(w[i])
        if before[-1] != target[0]:
            print("No")
            exit()
        else:
            if w[i] in done:
                print("No")
                exit()
        before = target
        done.append(w[i])
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

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

def siritori(n, words):
    if len(set(words)) != n:
        return print("No")
    for i in range(n-1):
        if words[i][-1] != words[i+1][0]:
            return print("No")
    return print("Yes")

siritori(n, words)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for _ in range(n)]
check=0
if len(w) > len(set(w)):
    print('No')
    check = 1
else:
    wl=w[0][-1]
    for i in w[1:]:
        if wl==i[0]:
          	wl = i[-1]
        else:
            print('No')
            check = 1
            break
if check==0:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
w = list(input() for i in range(n))
set_w = list(set(w))
ans = 'Yes'
if len(set_w) != n:
    ans = 'No'
else:
    tmp = w[0][-1]
    for i in range(1,n):
        # print('tmp{}:{}'.format(i,tmp))
        if tmp != w[i][0]:
            ans = 'No'
        else:
            tmp = w[i][-1]
print(ans)

Submission status: Accepted

Solution code:
def resolve():
	n=int(input())
	w=[input() for i in range(n)]
	if len(list(set(w)))<n:
		print('No')
	else:
		for i in range(1,n):
			if w[i-1][-1]!=w[i][0]:
				
				print('No')
				break
		else:
				print('Yes')
		
resolve()

Submission status: Accepted

Solution code:
N = int(input())
s=[input() for i in range(N)]
c=[]
for i in range(N-1):
    c.append([0,1][s[i][-1]==s[i+1][0]])
print(["No","Yes"][len(set(s))==len(s)and not(0 in c)])

Submission status: Accepted

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

from collections import Counter

dic = Counter(W)
flg = 0
for i in range(N):
    if dic[W[i]]!=1:
        flg=1
        

for j in range(N-1):
    if W[j][-1]!=W[j+1][0]:
        flg = 1

if flg!=1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lst = []
for i in range(n):
    w = input()
    if w in lst: #唯一性の確認
        print('No')
        exit()
    else:
        lst.append(w)
    if i==0:
        h = w[-1]
    elif w[0] != h:
        print('No')
        exit()
    else:
        h = w[-1]
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
cnt = 1
w = [input() for i in range(n)]
if len(set(w)) != len(w):
    cnt *= 0
else:
    for j in range(len(w)-1):
        if w[j][len(w[j])-1] != w[j+1][0]:
            cnt *= 0

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

Submission status: Accepted

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

if len(w)!=len(w_set):
    print("No")
    sys.exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
W=[input() for _ in range(N)]
ans="Yes"
for i in range(N-1):
    if W[i][-1]!=W[i+1][0]:
        ans="No"
        break
for j in range(N):
    for k in range(N):
        if W[j]==W[k] and j!=k:
            ans="No"
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
w = []
hantei = []
ans = ''
for i in range(n):
    w.append(input())
hantei.append(w[0])
for i in range(1,n):
    if w[i - 1][-1] == w[i][0] and w[i] not in hantei:
        ans = 'Yes'
        hantei.append(w[i])
    else:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
seen = set()
W = s()
seen.add(W)
prev_c = W[-1]
for i in range(N-1):
    W = s()
    if W in seen or W[0] != prev_c:
        print('No')
        import sys
        sys.exit()
    seen.add(W)
    prev_c = W[-1]
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
last = ""
a = set()
for i in range(N):
    if i == 0:
        last = input()
        a.add(last)
        continue
    tmp = input()
    if tmp[0] != last[-1] or tmp in a:
        print("No")
        exit(0)
    a.add(tmp)
    last = tmp
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for x 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')
        exit()
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] in W[i+1:]:
        print("No")
        break
    elif W[i][-1]!=W[i+1][0]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

word = set()
last = ""
blnOk=True
for i in range(n):
    s = input()
    word.add(s)
    if last != "" and last != s[0]:
        print('No')
        exit()
    last = s[-1]
print('Yes' if len(word) == n else 'No')

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
w=[None]*N
a=1
for i in range(N):
    w[i]=input()
for i in range(1,N):
    if w[i-1][-1]==w[i][0]:
        for j in range(0,i-1):
            if w[j]==w[i]:
                a=0
                break
    else:
        a=0
    if a==0:
        break
if a==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

pre = ''
for i,w in enumerate(W_list):
    if W_list.count(w) > 1:
        print('No')
        exit(0)
    if i == 0:
        pre = w[-1:]
        #print(pre)
        continue
    if pre != w[0:1]:
        print('No')
        exit(0)
    pre = w[-1:]
    #print(w)
    #print(pre)

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def abc():
    n = int(input())
    words = []
    for i in range(n):
        words.append(input().rstrip())
    if len(words) != len(set(words)):
        print('No')
        return
    for i in range(n-1):
        if words[i][-1] != words[i+1][0]:
            print('No')
            return
    print('Yes')


abc()

Submission status: Accepted

Solution code:
# INPUT
n = int(input())
words = [input() for _ in range(n)]

# PROCESS
answer = "Yes"
already_taken = []
for idx in range(len(words)):
  
  if (idx == 0):
    already_taken.append(words[idx])
    continue

  if (words[idx] in already_taken):
    answer = "No"
    break
  if (words[idx][0] != already_taken[-1][len(already_taken[-1])-1]):
    answer = "No"
    break
  already_taken.append(words[idx])

# OUTPUT
print(answer)

Submission status: Accepted

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

unilen = len(list(set(lst)))
if unilen != len(lst):
    print("No")
    exit()


for i in range(1, n):
    if lst[i-1][-1] == lst[i][0]:
        pass
    else:
        print("No")
        exit()

print("Yes")