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)]

flag = len(W) == len(list(set(W)))

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

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

Submission status: Accepted

Solution code:
noOfWords= int(input())
words = []
satisfactor = True
for i in range(noOfWords):
    word = input()
    words.append(word)

if len(set(words)) < len(words):
    print("No")    
    satisfactor = False 
else:
    for i in range(len(words)-1):
        if words[i][len(words[i])-1] ==  words[i+1][0]:
            continue
        else:
            satisfactor = False
            print("No")
            break
if satisfactor :
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
W = [ input() for _ in range(n) ]
if sorted(W) != sorted(list(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:
# -*- coding: utf-8 -*-
N = int(input())
w = []
for i in range(N):
  w.append(input())

flag = 0
ss = set(w)
if(len(ss) != N):
  flag = 1
for i in range(N-1):
  if(w[i][-1] != w[i+1][0]):
    flag = 1
    break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def taka():
    n = int(input())
    listofwords =[]
    for i in range(n):
        strTEMP = input()

        if i == 0:
            listofwords.append(strTEMP)
            continue
        else:
            if strTEMP in listofwords:
                return "No"
            else:
                cmp = listofwords[-1]
                if strTEMP[0] != cmp[-1]:
                    return "No"
                else:
                    listofwords.append(strTEMP)
    return "Yes"

print(taka())

Submission status: Accepted

Solution code:
def game():
    n = int(input())
    listofwords =[]
    for i in range(n):
        strTEMP = input()

        if i == 0:
            listofwords.append(strTEMP)
            continue
        else:
            if strTEMP in listofwords:
                return "No"
            else:
                cmp = listofwords[-1]
                if strTEMP[0] != cmp[-1]:
                    return "No"
                else:
                    listofwords.append(strTEMP)
    return "Yes"

print(game())

Submission status: Accepted

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

Submission status: Accepted

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

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

print('Yes')

Submission status: Accepted

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

for i in range(1, N):
    if s[i][0] != last:
        print("No")
        break
    last = s[i][-1]
    if s.count(s[i]) > 1:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

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

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

#重複なしかチェック
hasNoDuplicate = True
if len(set(w)) == len(w):
    pass
else:
    hasNoDuplicate = False

#しりとりになっているかチェック
isShiritori = True
for i in range(n):
    if i == 0:
        last = list(w[i])[-1]
    else:
        #前のlastと同じか確認
        if last == list(w[i])[0]:
            pass
            #文字を更新
            last = list(w[i])[-1]
        else:
            isShiritori = False
            break

if (isShiritori) and (hasNoDuplicate):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
words = [input() for i in range(N)]
preword =words[0]
se = set([words[0]])
hantei = True
for w in words[1:]:
  if w in se:
    hantei = False
  if preword[-1] != w[0]:
    hantei = False
  se.add(w)
  preword = w
print('Yes' if hantei else 'No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

    print("Yes")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = [str(input().rstrip('\n')) for _ in range(n)]
    d = collections.defaultdict(int)
    d[s[0]]
    b = True
    for i in range(1, n):
        if s[i] not in d:
            d[s[i]]
            if s[i][0] != s[i-1][-1]:
                b = False
                break
        else:
            b = False
            break
    print("Yes" if b else "No")


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

now = W[0][-1]
flag = True
for i in range(1, N):
    if now == W[i][0]:
        now = W[i][-1]
    else:
        flag = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

W = [input() for w in range(N)]

for i in range(1,len(W)):
  if (W[i-1][-1] != W[i][0]) or (W[i] in W[:i]):
    print("No")
    break
else:print("Yes")

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
w=[input() for i in range(n)]
li=[]
for i in range(n):
    if w[i] in li:
        print("No")
        quit()
    elif i>0 and w[i][0]!=w[i-1][-1]:
        print("No")
        quit()
    else:
        li.append(w[i])
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def has_duplicates(words):
  if len(words) == len(set(words)):
    return False
  return True

a = int(input())
words = []
for i in range(a):
  words.append(input())
if has_duplicates(words) == True:
  print('No')
  exit()
for i in range(a-1):
  if words[i][len(words[i])-1] != words[i+1][0]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

ans=True
if all(a.count(w) <2  for w in a):
    for i in range(n-1):
        if a[i][-1]!=a[i+1][0]:
            ans=False
else:
    ans=False
    
if ans:    
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

N = int(input().split()[0])
w_list = []
is_ok = True
for i in range(N):
    w = input()

    if w in w_list:
        is_ok = False
        break

    w_list.append(w)
    if i == 0:
        tail = w[-1]
        continue

    if w[0] != tail:
        is_ok = False
        break
    tail = w[-1]


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

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
  s.append(input())
  
ans = "Yes"

for i in range(n-1):
  if s[i] in s[i+1:n]:
    ans = "No"
  elif s[i][len(s[i])-1] != s[i+1][0]:
    ans = "No"
    
print(ans)

Submission status: Accepted

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

print("Yes")

Submission status: Accepted

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

    for word in words:
        count = 0
        for w in words:
            if w == word:
                count += 1
        if count > 1:
            print('No')
            exit()
    
    for i in range(n):
        if i + 1 <= n - 1:
            x = words[i+1][0]
            y = words[i][-1]
            if x == y:
                continue
            else:
                print('No')
                exit()
    
    print('Yes')


if __name__ == '__main__':
    shiritori()

Submission status: Accepted

Solution code:
N = int(input())

W = []
for i in range(N):
    if i == 0:
        x = input()
        W.append(x)
    else:
        x = input()
        if x in W:
            print("No")
            exit()
        elif W[i-1][-1] != x[0]:
            print("No")
            exit()
        else:
            W.append(x)

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
shiritori = []
ans = 1
for i in range(n):
    if i == 0:
        shiritori.append(input())
    else:
        shiritori.append(input())
        if shiritori.count(shiritori[i]) >= 2 or shiritori[i-1][-1] != shiritori[i][0]:
            ans = 0
if ans == 1: print("Yes")
else: print("No")

Submission status: Accepted

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

def check() :
    siri = W[0][-1]
    double = [W[0]]
    for i in range(1, N) :
        if W[i] in double :
           return 'No'
        double.append(W[i])
        
        atama = W[i][0]
        if atama != siri :
            return 'No'
            
        siri = W[i][-1]
    return 'Yes'
    
print(check())

Submission status: Accepted

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

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

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

print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
w=[]
for i in range(n):
    w.append(input())
    
if len(set(w)) < n:
    print("No")
    sys.exit(0)
else:
    for j in range(n-1):
        if w[j][-1:] != w[j+1][:1]:
            print("No")
            sys.exit(0)
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')
else:
    ans=0
    for j in range(n-1):
        if w[j][-1]==w[j+1][0]:
            ans+=1
    if ans==n-1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

# input
N = int(input())
W = list()
for i in range(N):
    W.append(input())

# solve
ans = True
if len(set(W)) != N:
    ans = False
else:
    for i in range(N - 1):
        if W[i][-1] != W[i + 1][0]:
            ans = False

# output
print('Yes' if ans else 'No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
f=True
s=set()
last=input();s.add(last)
for i in range(N-1):
    w=input()
    if w in s or last[-1]!=w[0]:
        f=False
        break
    else:
        s.add(w)
        last=w
print('Yes' if f else 'No')

Submission status: Accepted

Solution code:
n=int(input())
S=[input() for _ in range(n)]
ans=1
for i in range(n-1):
    if (S[i][-1] == S[i+1][0])*(S[i+1] not in S[:i+1]):
        ans += 1
print("Yes" if ans == n else "No")

Submission status: Accepted

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    lstr = ""
    d = collections.defaultdict(int)
    for i in range(n):
        s = str(input().rstrip('\n'))
        if s not in d:
            d[s]
            if lstr == "" or lstr == s[0]:
                lstr = s[-1]
            else:
                print("No")
                exit()
        else:
            print("No")
            exit()
    print("Yes")


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

Submission status: Accepted

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

word = []
end = S[0][0]
for i in range(n):
	val = S[i]
	if val[0] != end or val in word:
		print ("No")
		exit()
	else:
		end = val[-1]
		word.append(val)
print ("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

word_set = set()
W = str(input())
word_set.add(W)
last_char = W[len(W)-1]
#print(last_char,W,last_char)

for i in range(N-1):
  W = str(input())
  #print(last_char,W,last_char)
  if W in word_set:
    print("No")
    break
  elif W[0]!=last_char:
    print("No")
    break
  
  last_char = W[len(W)-1]
  word_set.add(W)
else:
  print("Yes")

Submission status: Accepted

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    d = collections.defaultdict(int)
    s = [str(input().rstrip('\n')) for _ in range(n)]
    for i in range(n):
        if i != 0:
            if s[i][0] != s[i-1][-1] or s[i] in d:
                print("No")
                exit()
        d[s[i]]
    print("Yes")


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

for i in range(N):
  W = str(input())
  if i > 0:
    if y != W[0]:
      print("No")
      quit()
  y = W[-1]
  if W in S:
    print("No")
    quit()
  else:
    S.append(W)  
    
print("Yes")

Submission status: Accepted

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

check = True
for i in range(N-1):
    s = W[i]
    s_1 = W[i+1]
    if s[-1] == s_1[0]:
        continue
    else:
        check = False
        break
for i in range(N):
    if W[i] in w_dic:
        check = False
        break
    else:
        w_dic[W[i]] = 1
if check:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict
 
N = int(input())
W = [input().strip() for _ in range(N)]
 
dic = defaultdict(int)
 
for i in range(N):
  if i == 0:
    tmp = W[i][-1]
    dic[W[i]] += 1
  else:
    if tmp != W[i][0] or dic[W[i]]:
      print("No")
      break
    else:
      dic[W[i]] += 1
      tmp = W[i][-1]
else:
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

W = [input()]
s = W[0][-1]
flag = True

for i in range(n-1):
    w = input()
    if w[0] != s:
        flag = False
        break
    W.append(w)
    s = w[-1]

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

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

Submission status: Accepted

Solution code:
n = int(input())
w = [input()]
ans = "Yes"
for _ in range(n-1):
    _w = input()
    if _w in w or w[-1][-1] != _w[0]:
        ans = "No"
    w.append(_w)

print(ans)

Submission status: Accepted

Solution code:
import sys
N=int(input())
lst=[]
for i in range(N):
  if i==0:
    lst.append(list(str(input())))
  else:
    s=list(str(input()))
    if s not in lst and lst[-1][-1]==s[0]:
      lst.append(s)
    else:
      print('No')
      sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
s=set()
wp=input()
s.add(wp)

f=True
for i in range(n-1):
  wn=input()
  if wp[-1]!=wn[0]:
    f=False
  elif wn in s:
    f=False
  wp=wn
  s.add(wn)

print('Yes' if f==True else 'No')

Submission status: Accepted

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

if len(set(W))!=N:
    f=0

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

print('NYoe s'[f::2])

Submission status: Accepted

Solution code:
def valid(words):
  used = set()
  last = ""

  for w in words:
    if w in used:
      return False
    if last != "" and last[-1] != w[0]:
      return False
    last = w
    used.add(w)

  return True


n = int(input())
words = [input() for _ in range(n)]
print("Yes" if valid(words) else "No")

Submission status: Accepted

Solution code:
N = int(input())
x = set()
last = ""

for i in range(N):
    W = input()
    if W in x:
        print("No")
        exit()
    elif i != 0:
        if last != W[0]:
            print("No")
            exit()

    last = W[-1]
    x.add(W)
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
ary = []
s = 'Yes'
for i in range(N):
  w = input()
  if w in ary:
    s = 'No'
    break
  if len(ary) > 0 and w[0] != ary[-1][-1]:
    s = 'No'
    break
  ary.append(w)
    
print(s)

Submission status: Accepted

Solution code:
# coding: utf-8
n=int(input())
l = []
last = ""
for i in range(n):
    s = input()
    if i == 0:
        last = s[-1]
        l.append(s)
        continue
    if last != s[0]:
        print("No")
        exit()
    last = s[-1]
    l.append(s)

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

Submission status: Accepted

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

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

if len(w)!=len(set(w)):
  flag*=0

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

Submission status: Accepted

Solution code:
n = int(input())
w = [str(input()) for _ in range(n)]
set_w = set(w)
checker = True
if len(set_w) == n:
    for i in range(n-1):
        if w[i][-1] == w[i+1][0]:
            continue
        else:
            checker = False
            break
    if checker:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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()
for i in range(1,n):
  for j in range(i):
    if w[i] == w[j]:
      print('No')
      exit()
  if w[i][0] != w[i-1][-1]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

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

before=input()
words.append(before)
N=N-1

for i in range(N):
    s=input()
    if before[-1] != s[0]:
        flg=False
    words.append(s)
    before=s
if len(words) != len(set(words)):
    flg=False
print("Yes" if flg else "No")

Submission status: Accepted

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

before = "kt"

for i in range(N):
    tmp = input()
    tmp2 = list(tmp)

    if before != "kt":
        if tmp2[0] == before and tmp not in W:
            before = tmp2[-1]
            W.append(tmp)
            continue
        else:
            print("No")
            exit()
    else:
        before = tmp2[-1]
        W.append(tmp)

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

W = [input() for _ in range(n)]

#print(W)

dict = {}

for i in range(n):
    if W[i] in dict:
        print("No")
        exit()
    else:
        dict[W[i]] = 1 
header = (list(W[0]))[0]
footer = (list(W[0]))[len(list(W[0]))-1]
#print(header)
#print(footer)
for i in range(1,n):
    header = (list(W[i]))[0]
    if footer != header:
        print("No")
        exit()
    footer = (list(W[i]))[len(list(W[i]))-1]

print("Yes")

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
w.sort()
for i in range(n-1):
  if w[i] == w[i+1]:
    ans = 'No'
    break
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
said={}
ans="Yes"
s=input()
said[s]=1
pre=s
for _ in range(n-1):
    s=input()
    if s not in said:
        if pre[len(pre)-1] == s[0]:
            said[s]=1
            pre=s
        else:
            ans="No"
            break
    else:
        ans="No"
        break


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p = ''
d = {}
for _ in range(n):
  w = input()
  if p and p[-1] != w[0]:
    print('No')
    exit()
  if w in d:
    print('No')
    exit()
  p = w[-1]
  d[w] = 1
print('Yes')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    word_list=[input() for i in range(N)]
    already_list = []
    for i, word in enumerate(word_list):
        if(i==0):
            already_list.append(word)
            continue
        if(word not in already_list and word[0] == word_list[i-1][len(word_list[i-1])-1]):
            already_list.append(word)
        else:
            print('No')
            return
    print('Yes')




if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

ans = "Yes"

for i in range(1, N):
    if W[i - 1][-1] != W[i][0] or W.count(W[i]) >= 2:
        ans = "No"
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
k = []
result=[]
for i in range(n):
    a = input()
    k.append(a)
ans = collections.Counter(k)
for i in range(1,n):
    if k[i-1][-1] == k[i][0] and ans.most_common()[0][1] == 1:
        result.append("1")
    else:
        result.append("0")
aim = collections.Counter(result)
if aim.most_common()[0][1] != n-1 or aim.most_common()[0][0] =='0':
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

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

print("Yes")

Submission status: Accepted

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    lw = ""
    d = collections.defaultdict(list)
    for i in range(n):
        w = str(input().rstrip('\n'))
        if lw != "":
            if w[0] != lw or w in d:
                print("No")
                exit()
        lw = w[-1]
        d[w]
    print("Yes")


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
N = int(input())
words = set()
_w = input()
words.add(_w)
for _ in range(N-1):
    w = input()
    if w not in words and _w[-1] == w[0]:
        words.add(w)
        _w = w
        continue
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
words = [input() for _ in range(N)]
s = set()
for i, word in enumerate(words):
    if word in s:
        print('No')
        exit()
    if i != 0:
        if words[i-1][-1] == word[0]:
            s.add(word)
        else:
            print('No')
            exit()
    else:
        s.add(word)
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n=int(input())
w=[input() for i in range(n)]
flug=1
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        flug=0
for i in range(n-1):
    for j in range(i+1,n):
        if w[i]==w[j]:
            flug=0
print('Yes' if flug else 'No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
      c=input()
      a.append(list(c))
      b.append(c)
      
if len(list(set(b))) != len(a):
      print('No')
      exit()

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

Submission status: Accepted

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

t=[]
last=A[0][0]
f=True
for a in A:
	if last==a[0] and a not in t:
		last=a[-1]
		t.append(a)
	else:
		f=False
print('Yes' if f else 'No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
ans = True
for i in range(1, N):
    if W[i][0] != W[i-1][-1]:
        ans = False
for i in range(N):
    for j in range(i+1, N):
        if W[i] == W[j]:
            ans = False
if ans:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline


def main():
    N = int(input())

    ans = "Yes"
    W = [input()[:-1]]
    for _ in range(N-1):
        w = input()[:-1]
        p = W[len(W)-1]
        if w in W or w[:1]!=p[-1:]:
            ans = "No"
            break
        W.append(w)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(n-1):
    x=input()
    if x in list or x[0]!=list[-1][-1]:
        print('No')
        exit()
    list.append(x)
print('Yes')

Submission status: Accepted

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

check_list = []
for i in range(N):
    if word_list[i] in word_list[0:i] or word_list[i] in word_list[i + 1:]:
        print('No')
        break
    else:
        for i in range(N - 1):
            if word_list[i][-1] == word_list[i + 1][0]:
                pass
            else:
                print('No')
                break
        else:
            continue #外側のループに対するもので，以降の処理をスキップする
    break
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    w = [input().strip() for _ in range(n)]
    if len(w) == len(set(w)) and all([i[-1] == j[0] for i, j in zip(w[:-1], w[1:])]):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

flg = True
if len(l) != len(set(l)):
    flg = False


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N,*W = map(str,open(0).read().split())
N = int(N)
for i in range(N-1):
    if list(W[i])[-1] != list(W[i+1])[0]:
        print("No")
        sys.exit()
if len(W) != len(set(W)):
    print("No")
    sys.exit()
print("Yes")

Submission status: Accepted

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