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())
li = [input() for _ in range(n)]
if len(set(li)) != n:
  print('No')
  exit()
for i in range(n-1):
  if li[i][-1] != li[i+1][0]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n = int(input())
words = []
word = ""
for i in range(n):
    word = input()
    # 2個目かチェック
    if word in words:
        print("No")
        sys.exit(0)
    else:
        words.append(word)

for index, word in enumerate(words):
    if index == 0:
        continue
    if words[index - 1][-1] == list(word)[0]:
        continue
    else:
        print("No")
        sys.exit(0)
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
correct = True
past = [input()]
for n in range(N-1):
    w = input()
    if w[0] != past[-1][-1] or w in past:
        correct = False
        break
    past.append(w)

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

Submission status: Accepted

Solution code:
N = int(input())

s = []
cnt = 0

for i in range(N) : 
    s.append(input())
    
for i in range(N) : 
    for j in range(N) : 
        if i != j : 
            if s[i] == s[j] : 
                cnt += 1
                
for i in range(0, N-1, 1) : 
    if s[i][-1] != s[i+1][0] : 
        cnt += 1
        
if cnt == 0 : 
    print("Yes")
else : 
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
set=set()
bool=True
list = (list(input()for i in range(N)))
    # S=input()
    # if S in set or :
    #     bool=False
    #     break
set.add(list[0])
for i in range(1,N):
    if list[i] in set or list[i-1][-1] != list[i][0]:
        bool=False
        break
    set.add(list[i])
print('Yes' if bool else 'No')

Submission status: Accepted

Solution code:
n = int(input())
w = [input() for i in range(n)]
ans = True
for j in range(n-1):
    if w[j][-1] != w[j+1][0]:
        ans = False
for k in range(n):
    for l in range(n):
        if l != k:
            if w[l] == w[k]:
                ans = False
        else:
            continue
if ans == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
words = []
flg = 0
for i in range(n):
    tmp_word = input()
    if tmp_word not in words:
        words.append(tmp_word)
    else:
        flg =1
        
if flg ==1:
    print("No")
else:
    for i in range(n-1):
        if words[i][-1] == words[i+1][0] and i < n-2:
            pass
        elif words[i][-1] == words[i+1][0] and i == n-2:
            print("Yes")
        else:
            print("No")
            break

Submission status: Accepted

Solution code:
N = int(input())
dic = [input()]
check = 0
for n in range(N-1):
    s = input()
    if s in dic:
        print('No')
        check = 1
        break
    else:
        if dic[-1][-1] == s[0]:
            dic.append(s)
        else:
            print('No')
            check = 1
            break
if check == 0:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for _ in range(n)]
l=w[0][-1]
said=set()
said.add(w[0])
f=True
for i in range(1,n):
    if w[i][0] == l:
        l=w[i][-1]
    else:
        f=False
        break
    if w[i] in said:
        f=False
        break
    said.add(w[i])
print('Yes' if f else 'No')

Submission status: Accepted

Solution code:
#ABC 109 B
n = int(input())
first = input()
words = {first}
flag = False
for i in range(n-1):
    second = input()
    if first[-1] == second[0] and second not in words:
        words.add(second)
        first = second
    else:
        print("No")
        flag = True
        break
        
if not flag:
    print("Yes")

Submission status: Accepted

Solution code:
n= int(input())

list=[]
for i in range(n):
  list.append(input())
  
import collections
c=collections.Counter(list)
t=0
for i in range(n-1):

  if list[i][len(list[i])-1]==list[i+1][0]:
    
    t += 1
  else:
    pass

if t == n-1 and len(c) == n:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
wls =[]
for i in range(N):
    wls.append(input())
count =0
if len(wls) != len(set(wls)):
    print('No')
else:
    for i in range(N):
        if i == 0:
            continue
        else:
            if wls[i][0] != wls[i-1][-1]:
                count += 1
            
    if count == 0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lst = []
ans = "Yes"

for i in range(N):
  tmp = input()
  lst.append(tmp)

for k in range(N):
  if lst.count(lst[k]) != 1:
    ans = "No"

if ans == "No":
  ans = "No"
else:
  for j in range(N-1):
    left = lst[j]
    right = lst[j+1]
    if left[-1:] == right[:1]:
      continue
    else:
      ans = "No"
      break
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=input()
st=set()
st.add(a)
ans='Yes'
for i in range(n-1):
    s=input()
    st.add(s)
    if a[-1]!=s[0]:
        ans='No'
    a=s
if len(st)<n:
    ans='No'
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
from sys import stdin
import sys

N = int(stdin.readline().rstrip())
Ws = [ stdin.readline().rstrip() for _ in range(N) ]

def main():
    for i in range(1,len(Ws)):
        if Ws.count(Ws[i]) > 1 or Ws[i-1][-1:] != Ws[i][0:1] :
            print("No")
            sys.exit()
    print("Yes")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

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

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())
W=[]
for i in range(N):
    w=input()
    W.append(w)
words=W.copy()
words=set(words)

for k in range(N-1):
    if W[k][-1]!=W[k+1][0]:
        print('No')
        break
    elif len(W)!=len(words):
        print('No')
        break
    else:
        continue
else:
    print('Yes')

Submission status: Accepted

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

flag = True if len(W) == len(set(W)) else False
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:
N=int(input())
W=[input() for _ in range(N)]
flag=0
if N==len(set(W)):
  for i in range(N-1):
    if W[i][-1]!=W[i+1][0]:
      flag=1
      break
else:
  flag=1

print("YNeos"[flag==1::2])

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()
    wlist = [input() for _ in range(n)]

    history = []
    prev = None
    for w in wlist:

        if w in history:
            print('No')
            return
        history.append(w)

        if prev is None:
            prev = w
            continue
        if w[0] != prev[-1]:
            print('No')
            return
        prev = w

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

flag = "Yes"

for n in range(1, N):
    if W[n][0] != W[n - 1][-1] or (W[n] in W[:n]):
        flag = "No"

print(flag)

Submission status: Accepted

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

flg = True
for i in range(N-1):
    Wi = input()
    if Wi in ws:
        flg = False
    elif ws[-1][-1] != Wi[0]:
        flg = False
    ws.append(Wi)

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

Submission status: Accepted

Solution code:
import sys
N = int(input())

b = []
for i in range(N):
    a = str(input())
    if a in b:
        print ('No')
        sys.exit()
        b += [a]
    elif i != 0:
        if str(b[i-1])[-1] == a[0]:
            pass
        else:
            print ('No')
            sys.exit()
        b += [a]
    else:
        b += [a]
print ('Yes')

Submission status: Accepted

Solution code:
n = int(input())
s = [0]*n
for j in range(0,n):
    s[j] = input()
for j in range(0,n-1):
    if s[j][len(s[j])-1] != s[j+1][0]:
        print('No')
        break
    elif s.count(s[j]) >= 2:
        print('No')
        break
    elif j == n-2:
        print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
d = dict()

n = int(input())
w0 = input().strip()
d[w0] = True
c = w0[-1]

ok = True
for _ in range(n-1):
    w = input().strip()
    if w in d or w[0] != c:
        ok = False
        break

    d[w] = True
    c = w[-1]

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

Submission status: Accepted

Solution code:
N = int(input())
y = input()
W = [y]
cnt = False
for i in range(1,N):
  x = input()
  if x in W:
    cnt = True
  elif x[0]!=y[-1]:
    cnt = True
  W.append(x)
  y = x
print("Yes" if cnt==False else "No")

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
li = []
start = True
for i in range(N):
    w = input()
    if w in li:
        print('No')
        exit()

    li.append(w)
    if start:
        start = False
    else:
        if bef[-1] != w[0]:
            print('No')
            exit()
    bef = w

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:
    for i in range(N - 1):
        b = W[i]
        f = W[i + 1]
        if b[-1] != f[0]:
            print('No')
            break
        else:
            if i == N - 2:
                print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ls = [input()]
ans = 0
for i in range(n-1):
    a = input()
    if (a  in ls) or (ls[i][len(ls[i])-1] != a[0]):
        ans += 1
    ls.append(a)
if ans == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#2
n = int(input())
visited = set()
ans = "Yes"
bef = ""
for i in range(n):
    c = str(input())
    if c in visited:
        ans = "No"
        break
    else:
        if i != 0:
            if c[0] != bef[-1]:
                ans = "No"
                break
    bef = c
    visited.add(c)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
List=list(input() for i in range(n))
for i in range(n-1):
      if List[i][-1]!=List[i+1][0]:
            x=1
            break
      else:
            x=0



print('Yes' if x==0 and len(list(set(List)))==len(List) else 'No')

Submission status: Accepted

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

wordset = set()
last= W[0][0]

for i in W:
    if last != i[0]:
        print("No")
        exit()
    else:
        wordset.add(i)
        last = i[-1]

print("Yes" if len(wordset) == N else "No")

Submission status: Accepted

Solution code:
import sys
n = int(input())
words = []
for i in range(n):
    w = input()
    if w in words:
        print('No')
        sys.exit()
    w_list = list(w)
    if i == 0:
        last = w_list[-1]
    elif i != 0 and i != n-1:
        start = w_list[0]
        if start != last:
            print('No')
            sys.exit()
        last  = w_list[-1]
    else:
        start = w_list[0]
        if start != last:
            print('No')
            sys.exit()
    words.append(w)
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
w=[input() for s in range(n)]
k=[w[0]]
D=0
for i in range(1,n):
 if w[i] in k or w[i-1][-1]!=w[i][0]:
  D+=1
 else:
  k.append(w[i])

if D>0:
 print("No")
else:
 print("Yes")

Submission status: Accepted

Solution code:
import sys
n = int(input())
s = set([])
last = str(input())
s.add(last)
for i in range(n-1):
    tmp = str(input())
    
    if not (last[len(last)-1] == tmp[0]):
        print('No')
        sys.exit()
    
    s.add(tmp)
    last = tmp

print('Yes') if len(s) == n else print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

tmp = 'a'
ans = 'Yes'
for i in range(N):
    word = list(W[i])
    if (i > 0) and  (word[0] != tmp):
        ans = 'No' 
    #print(ans)
    tmp = word[len(word)-1]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import sys

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

dic = [W[0]]
for word in W[1:]:
    if word in dic or word[0] != dic[-1][-1]:
        print('No')
        sys.exit()
    dic.append(word)

print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
Check=[]
Key=True

for i in range(N):
    W=input()
    Check.append(W)
    W=list(W)
    if 0<i and W[0]!=tmp:
        Key=False
        break
    tmp=W[len(W)-1]
    
for i in Check:
    if 1<Check.count(i):
        Key=False
        break

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

Submission status: Accepted

Solution code:
def is_OK(W, N):
    w = {W[0]}
    for i in range(0, N-1):
        if (W[i][-1] != W[i+1][0]) or (W[i+1] in w):
            return 'No'
        else:
            w.add(W[i+1])
    return 'Yes'

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

print(is_OK(W, N))

Submission status: Accepted

Solution code:
N = int(input())
W = []
ans = True
for i in range(N):
    tmp = input()
    if tmp in W and i != 0:
        ans = False
    W.append(tmp)

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

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

Submission status: Accepted

Solution code:
n=int(input())
w=[0]*n
for i in range(n):
  w[i]=input()
count=0
for i in range(n-1):
  if w[i][-1]!=w[i+1][0]:
    count+=1
for i in range(n):
  if w[i] in w[:i]:
    count+=1
if count==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

s = input()
ss = {s}

ans = True

for i in range(1, n):
  t = input()
  if t not in ss and s[-1] == t[0]:
    s = t
    ss.add(s)
  else:
    ans = False
    break
  
  
if ans:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n = int(input())
lst = []
lst.append(input())
c = 0

for i in range(n-1):
    word = input()
    
    if word in lst:
        c=1

    if lst[-1][-1] == word[0]:
        lst.append(word)
    else:
        c=1   
  
if c==1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
_ = input()
prev = [input().strip()]
for line in sys.stdin:
  word = line.strip()
  if prev[-1][-1] == word[0] and word not in prev:
    prev.append(word)
  else:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, W: "List[str]"):
    s = set([W[0]])
    for i in range(1, len(W)):
        if (W[i] in s) or (W[i-1][-1] != W[i][0]):
            return NO
        s.add(W[i])
    return YES


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    result = solve(N, W)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = []
judge = 0

for i in range(N):
    A.append(input())

B = set(A)

if len(B) != N:
    judge = 1

for i in range(N-1):
    C = list(A[i])
    D = list(A[i+1])
    if C[-1] != D[0]:
        judge = 1

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

Submission status: Accepted

Solution code:
a=int(input())
c="0"
d=2
e=[]
for i in range(a):
    b=input()
    if b[0]!=c[-1]:
        d-=1
    e.append(b)
    c=b
print(["No","Yes"][(len(set(e))==a) and d==1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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


w = [list(x) for x in Words]

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



if len(set(Words)) == n:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for i in range(N)]
S = set([W[0]])
ans = "Yes"
for i in range(1,N):
  if W[i] in S:
    ans = "No"
  if W[i][0] != W[i-1][-1]:
    ans = "No"
  S.add(W[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
ws =[input() for i in range(N)]
word = collections.defaultdict(int)
flag = True
for i in range(N-1):
    if ws[i][-1] != ws[i+1][0]:
        flag = False
        break
    word[ws[i]] += 1
word[ws[-1]] += 1
for n in word.values():
    if n >= 2:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
s_list = [s]
for i in range(n-1):
    tem = input()
    if s[-1] == tem[:1] and not tem in s_list:
        s = tem
        s_list.append(s)
        continue
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

W = input()

last = W[-1]
word_list = {W}
result = 'Yes'

for i in range(1, N):
    W = input()

    if W[0] == last:
        last = W[-1]
    else:
        result = 'No'

    if W in word_list:
        result = 'No'
    else:
        word_list.add(W)

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
data = [input().rstrip() for _ in range(n)]
used = [data[0]]
 
for i in range(1, n):
    if data[i][0] == data[i - 1][-1] and data[i] not in used:
        used.append(data[i])
    else:
        print("No")
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC109B - Shiritori
n = int(input())
data = [input().rstrip() for _ in range(n)]
used = [data[0]]

for i in range(1, n):
    if data[i][0] == data[i - 1][-1] and data[i] not in used:
        used.append(data[i])
    else:
        print("No")
        exit()
        
print("Yes")

Submission status: Accepted

Solution code:
# ABC109B - Shiritori
n = int(input())
data = [input().rstrip() for _ in range(n)]
used = [data[0]]

for i in range(1, n):
    if data[i][0] == data[i - 1][-1] and data[i] not in used:
        used.append(data[i])
    else:
        print("No")
        break
        
if len(used) == n:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = [input().rstrip() for _ in range(N)]
W_set = set(tuple(W))
for i in range(N-1):
  if W[i][-1] == W[i+1][0]:
    continue
  else:
    print("No")
    exit()
for word in W_set:
    if W.count(word) != 1:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
flag=1 

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

for i in range(N-1):
  #print(words[i])
  if words[i][-1] != words[i+1][0]:
    flag=0

sets=set(words)
if len(sets) != len(words):
  flag=0
  
if flag:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n=int(input())
lstw=[input() for _ in range(n)]
string=[]
flag=False
cnt=0

if len(lstw)==1:
    flag=True
elif len(lstw)==len(set(lstw)):
    for i in range(n):
        string.append(lstw[i][:1])
        string.append(lstw[i][-1:])
    for i in range(1,n):
        if string[2*i-1]==string[2*i]:
            cnt+=1
    if cnt==(n-1):
        flag=True

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

Submission status: Accepted

Solution code:
n = int(input())
f = [input()]
for i in range(1,n):
    w = input()
    if w in f or f[i-1][-1] != w[0]:
        print('No')
        break
    else:
        f.append(w)
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(1, N):
	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)]
ans = "Yes"
for i in range(1, N):
	if W[i] in W[: i] or W[i][0] != W[i - 1][-1]:
		ans = "No"
		break
print(ans)

Submission status: Accepted

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

def endgame():
    print("No")
    exit()

if len(list(set(W))) != len(W):
    endgame()
for i in range(N-1):
    if W[i+1][0] != W[i][-1]:
        endgame()
print("Yes")

Submission status: Accepted

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

for i in range(N):
    roop = True
    for j in range(i + 1, N):
        if W[i] == W[j]:
            flag = False
            roop = False
    if not roop:
        break

for i in range(N - 1):
    if W[i][-1] != W[i + 1][0]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:

def main():
    num = int(input())
    data = [input() for i in range(num)]

    if len(data) != len(set(data)):
        print('No')
    else:
        flg = 1
        for i in range(num - 1):
            if data[i + 1][0] != data[i][-1]:
                flg = 0
                break

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




if __name__ == '__main__':
    main()

Submission status: Accepted

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