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())
rec = []
flag = True
t = input()
pre = t[-1]
rec.append(t)
for i in range(1, n):
    s = input()
    if s in rec:
        flag = False
    elif s[0] != pre:
        flag = False
    else:
        rec.append(s)
        pre = s[-1]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = []
ss = []
count = 0

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


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

s.sort()
for i in range(n-1):
  if s[i] == s[i+1]:
    count = 1

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

Submission status: Accepted

Solution code:
N = int(input())
W = [input() for _ in range(N)]
flag = True
x = W[0][-1]
for i in range(1, N):
    if x != W[i][0]:
        flag = False
        break
    x = W[i][-1]

if len(set(W)) != N:
    print("No")
elif flag == False:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

prev = ''
history = {}
for i in range(N):
  w = input()
  if w in history or (prev != '' and prev[-1] != w[0]):
    print('No')
    exit()
  history[w] = 1
  prev = w
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

ans = True
words = []
wset = set()
for i in range(n):
    word = input()
    words.append(word)
    if word in wset:
        ans = False
    wset.add(word)

last = words[0]
for w in words[1:]:
    if last[-1] != w[0]:
        ans = False
        break
    last = w

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

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())

word = input()
S = [word]
judge = True
for _ in range(N - 1):
    t = word[-1]
    word = input()
    if word[0] != t or word in S:
        judge = False
        break
    S.append(word)

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
N = int(input())

W = []
Se = set()
for i in range(N):
  st = input()
  W.append(st)
  Se.add(st)
  
if len(Se) != N:
  print("No")
  exit(0)

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

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
ws = []
ans = 'Yes'
for _ in range(n):
    w = input()
    if w in ws:
        ans = 'No'
        break
    else:
        if len(ws)>0:
            if ws[-1][-1] == w[0]:
                pass
            else:
                ans = 'No'
                break    
        ws.append(w)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
already = {}
n = int(input())
last = ''
for i in range(n):
  s = input()
  if (i != 0 and s[0] != last[-1]) or (s in already) :
    print('No')
    break
  last = s
  already[s] = 1
else:
  print('Yes')

Submission status: Accepted

Solution code:
n =int(input())
array = []
for i in range(n):
    array.append(input())
flag = True
tmp = array[0]
for j in array[1:]:
    if tmp[-1] == j[0]:
        tmp = j
    else:
        flag = False
        break
print("Yes" if flag and len(set(array)) == len(array) else "No")

Submission status: Accepted

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

cnt = 0

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

W.sort()
for i in range(1, N):
    if W[i] == W[i - 1]:
        cnt = 1

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n = ni()

word = []
words = []
for _ in range(n):
    words.append(lc())
    
ok = True
for i in range(n-1):
    if words[i][-1] != words[i+1][0]:
        ok = False
        
for i in range(n):
    for j in range(i+1,n):
        if words[i] == words[j]:
            ok = False

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

Submission status: Accepted

Solution code:
# coding=utf-8

if __name__ == '__main__':
    N = int(input())
    said_words = []

    for i in range(N):
        new_word = input()
        if said_words == []:
            said_words.append(new_word)
        elif new_word in said_words:
            print('No')
            break
        elif said_words[-1][-1] != new_word[0]:
            print('No')
            break
        else:
            said_words.append(new_word)
    else:
        print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W = input()
S = set([W])
e = W[-1]
for _ in range(N-1):
    W = input()
    if W[0] == e and not W in S:
        e = W[-1]
        S.add(W)
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
W=[input() for _ in[0]*N]
li=[]
for a, b in zip(W, W[1:]):
    if a in li or a[-1]!=b[0]:
        print('No')
        exit()
    li+=[a]
print('No'if W[-1]in li else 'Yes')

Submission status: Accepted

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

if not all([Ws.count(w) == 1 for w in Ws]):
    print('No')
else:
    f = True
    t = Ws[0][-1]
    for w in Ws[1:]:
        f &= w[0] == t
        t = w[-1]
    print('Yes' if f else 'No')

Submission status: Accepted

Solution code:
N=int(input())
said = set()
char = ""
flag = True
for i in range(N):
    word = input()
    if char != "" and word[0] != char:
        flag = False
    if word in said:
        flag = False
    said.add(word)
    char=word[len(word)-1]
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    
    tmp = ""
    f = True
    st = []
    for i in range(n):
        w = input()
        st.append(w)
        if i > 0:
            if tmp[-1] == w[0]:
                pass
            else:
                f = False
        tmp = w
    if len(list(set(st))) != n:
        f = False
    
    print("Yes" if f else "No")

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 'Yes'
w = ws[0]
end = w[-1]
w_map = {w:1}
for i in range(1, n):
    w_next = ws[i]
    if not w_next in w_map.keys():
        w_map[w_next] = 1
    else:
        ans = 'No'
        break
    if w_next[0] != end:
        ans = 'No'
        break
    w = w_next
    end = w[-1]
print(ans)

Submission status: Accepted

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

for _ in range(N):
    words.append(input())

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

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

Submission status: Accepted

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

for i in range(n):
    w[i] = input()
    if i > 0 and w[i-1][-1] != w[i][0]:
        print("No")
        exit()
    else:
        for j in range(i):
            if w[j] == w[i]:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
prev = input()
lst = [prev]
flg = True
for i in range(N-1):
    w = input()
    lst.append(w)
    if w[0] != prev[-1]:
        flg = False
    prev = w

lst.sort()
for i in range(N-1):
    if lst[i+1] == lst[i]:
        flg = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

if N == len(set(W)):
    s = W[0]
    c = True
    for wi in W[1:]:
        if s[-1] != wi[0]:
            c = False
            break
        s = wi
    if c:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
'''input
9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly
'''
from sys import exit
s = set()
n = input()
arr = [raw_input().strip() for i in range(n)]
l = arr[0][-1]
s.add(arr[0])
for i in range(1,n):
	if arr[i][0] == l and (arr[i] not in s):
		s.add(arr[i])
		l = arr[i][-1]
	else:
		print "No"
		exit(0)
print "Yes"

Submission status: Accepted

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

from collections import Counter
counter = Counter(W).most_common()

Ans = "Yes"
if counter[0][1]>1:
    Ans = "No"
else:
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            Ans = "No"

print(Ans)

Submission status: Accepted

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

Submission status: Accepted

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

from collections import deque
import itertools as it
import sys
import math
import re

sys.setrecursionlimit(1000000)

N = input()
ls = []
m = {}
for i in range(N):
    S = raw_input()
    ls.append(S)
    m[S] = 1

if len(m) != N:
    print "No"
    exit()

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

print "Yes"

Submission status: Accepted

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

result = True

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

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

Submission status: Accepted

Solution code:
n=int(input())
dict1={}
flag=0
arr=[]
for i in range(n):
    s=str(input())
    if(i==0):
        dict1[s]=1
        arr.append(s)
    else:
        if(arr[-1][-1]!=s[0]):
            flag=1
        else:
            try:
                dict1[s]+=1
                flag=1
            except:
                KeyError
                dict1[s]=1
            arr.append(s)
if(flag==0):
    print("Yes")
else:
    print('No')

Submission status: Accepted

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

flag = 1
for i in range(n):
    oi = str(input())
    if oi in siritolist:
        flag = 0
        
    else:
        if len(siritolist) == 0:
            siritolist.append(oi)
        else:
            if list(siritolist[-1])[-1] == list(oi)[0]:
                siritolist.append(oi)
            else:
                flag = 0

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

Submission status: Accepted

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

used = [w[0]]
check = True
for i in range(1,n):
    if w[i] in used:
        check = False
        break
    if w[i-1][-1] != w[i][0]:
        check = False
        break
    else:
        used.append(w[i])
if check:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

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

res = len(W) == len(set(W)) and all(W[i][-1] ==W[i+1][0] for i in range(N-1))
print("Yes" if res else "No")

Submission status: Accepted

Solution code:
na = lambda: list(map(int, input().split()))
n = int(input())
w = [input() for _ in range(n)]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
ret = "Yes"
n = input()
z = []
for i in xrange(n):
    s=raw_input()
    if z and z[-1][-1]!=s[0] or s in z:ret = "No"
    z.append(s)
print  ret

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

def main():
    N = int(input())
    pw = []
    for i in range(N):
        w = input().strip()
        if i > 0 and (w in pw or w[0] != pw[-1][-1]):
            return "No"
        pw.append(w)
    return "Yes"

print(main())

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
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 inpls(): return list(input().split())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input())
W = [input() for _ in range(n)]
dic = {}
for word in W:
    if word not in dic:
        dic[word] = True
    else:
        print('No')
        exit()
for i in range(n-1):
    if W[i][-1] != W[i+1][0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
lis = []
n = int(input())
for i in range(n):
  s = str(input())
  if s not in lis:
    lis.append(s)
  else:
    print("No")
    exit()
for i in range(n-1):
  if lis[i][-1] != lis[i+1][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()
if len(set(W)) != N:
    print('No')
    exit()
for i in range(N - 1):
    w1 = W[i]
    w2 = W[i+1]
    if w1[-1] != w2[0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


# --------------------------------------------

dp = None


def main():
    N = int(input())
    S = [input() for _ in range(N)]

    if len(set(S)) != N:
        print("No")
        return

    i = 0
    while i < len(S) - 1:
        if S[i][-1] != S[i + 1][0]:
            print("No")
            return
        i += 1
    
    print("Yes")


main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    ws = [S() for _ in range(n)]
    s = set(ws)
    if len(s) != n:
        return 'No'
    for i in range(n-1):
        if ws[i][-1] != ws[i+1][0]:
            return 'No'

    return 'Yes'


print(main())

Submission status: Accepted

Solution code:
N = input()
S = set()
last = '.'
for i in xrange(N):
    s = raw_input()
    if s in S:
        print "No"
        exit()
    if last != '.' and s[0] != last:
        print "No"
        exit()
    last = s[-1]
    S.add(s)
print "Yes"

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import collections as cl
import itertools as it
# import more_itertools as mit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(100000)

n = int(readline())
w = list(readlines().split())
dic = set()

for i in w:
    if i == 0:
        dic.append(i)
        continue
    if i in dic or dic[i-1][-1] != dic[i][0]:
        print('No')
        sys.exit()
    dic.append(i)
print('Yes')

Submission status: Runtime Error

Solution code:
N = int(input())
m = dict()

prev = input()
m[prev] = True
flg = True

for _ in range(N - 1):
  s = input()
  flg = all(flg, s not in m, prev[len(prev) - 1] == s[0])
  m[s] = True
  prev = s

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(n):
  if all(alist[i][-1]==alist[i+1][0]):
    if len(set(alist))==n:
      print("Yes")
    else:
      print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
alist = [list(input()) for i in range(n)]
for i in range(n):
  for j in range(i+1,n):
    if alist[i] == alist[j]:
      print("No")
      exit()
for i in range(n):
  if all(alist[i][-1]==alist[i+1][0]):
    print("Yes")
  else:
    print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
alist = [str(input()) for i in range(n)]
for i in range(n):
  for j in range(i+1,n):
    if alist[i] == alist[j]:
      print("No")
      exit()
for i in range(n):
  if all(alist[i][-1]==alist[i+1][0]):
    print("Yes")
  else:
    print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
alist = [input() for i in range(n)]
for i in range(n):
  for j in range(i+1,n):
    if alist[i] == alist[j]:
      print("No")
      exit()
for i in range(n):
  if all(alist[i][-1]==alist[i+1][0]):
    print("Yes")
  else:
    print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
used = list(input() for x in range(n))
ans = "Yes"
for i in range(n): 
  if used.count(used[i]) == 2:
    ans = "No"
    break
  if used[i][-1] != used[i+1][0]:
    ans = "No"
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if l.most_common()[0][1] != 1:
  ans="No"
else:
  l_head = [i[0] for i in l]
  l_tail = [i[-1] for i in l]
  if l_head == l_tail:
    ans="Yes"
  else:
    ans="No"
    
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc109/tasks/abc109_b
import collections
N = int(input())
Word_List = []
SP = ""
for i in range(N):
    CW = str(input())
    if i == 0:
        Word_List.append(CW)
        SP = CW[-1]
    elif SP != CW[0]:
        break
    else:
        Word_List.append(CW)
        SP = CW[-1]
else:
    Word_List = collections.Counter(Word_List))
    if len(Word_List) != N:
        print("No")
    else:
        print("Yes")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
x=str(input())
a[0]=x
d=bool(True)
for i in range(1, n):
  y=str(input)
  if x[len(x)]!=y[0]:
    d=False
  for i in range(a.size()):
    if y==a[i]:
      d=False
  a.append(y)

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

Submission status: Runtime Error

Solution code:
# abc109_b.py
# https://atcoder.jp/contests/abc109/tasks/abc109_b

# B - Shiritori /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 高橋くんは今日も 1人でしりとりの練習をしています。
# しりとりとは以下のルールで遊ばれるゲームです。
#     はじめ、好きな単語を発言する
#     以降、次の条件を満たす単語を発言することを繰り返す
#         その単語はまだ発言していない単語である
#         その単語の先頭の文字は直前に発言した単語の末尾の文字と一致する
# 高橋くんは、10秒間にできるだけ多くの単語を発言する練習をしています。
# 高橋くんが発言した単語の個数 Nと i 番目に発言した単語 Wiが与えられるので、
# どの発言もしりとりのルールを守っていたかを判定してください。

# 制約
#     Nは 2≤N≤100を満たす整数である
#     Wiは英小文字からなる長さ 1 以上 10以下の文字列である

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# W1
# W2
# :
# WN

# 出力
# 高橋くんのどの発言もしりとりのルールを守っていたなら Yes、そうでなければ No を出力せよ。

# 入力例 1
# 4
# hoge
# english
# hoge
# enigma

# 出力例 1
# No

# hoge が複数回発言されているのでしりとりのルールを守っていません。

# 入力例 2
# 9
# basic
# c
# cpp
# php
# python
# nadesico
# ocaml
# lua
# assembly

# 出力例 2
# Yes

# 入力例 3
# 8
# a
# aa
# aaa
# aaaa
# aaaaa
# aaaaaa
# aaa
# aaaaaaa

# 出力例 3
# No

# 入力例 4
# 3
# abc
# arc
# agc

# 出力例 4
# No


def calculation(lines):
    N = int(lines[0])
    # A, B = list(map(int, lines[0].split()))
    last_letter = lines[1][0]
    values = list()
    for i in range(1, N+1):
        line = lines[i]
        if line[0] != last_letter:
            return ['No']
        last_letter = line[-1:]
        if line in values:
            return ['No']
        values.append(line)
    return ['Yes']


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4', 'hoge', 'english', 'hoge', 'enigma']
        lines_export = ['No']
    if pattern == 2:
        lines_input = ['9', 'basic', 'c', 'cpp', 'php', 'python', 'nadesico', 'ocaml', 'lua', 'assembly']
        lines_export = ['Yes']
    if pattern == 3:
        lines_input = ['8', 'a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa', 'aaa', 'aaaaaaa']
        lines_export = ['No']
    if pattern == 4:
        lines_input = ['3', 'abc', 'arc', 'agc']
        lines_export = ['No']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

for i in range(N):
    Ws.append(W[i])
    for j in range(1,N+1)
        if W[i][-1] == W[j][0]:
            break
        else:
            ans = 'No'
            break
        
#print(Ws)

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

Submission status: Runtime Error

Solution code:
Row = int(input())
flag = True
List = []
for i in range (Row):
  List.append(int(input()))
s_l = set(List)
if len(List) != len(s_l):
  print("No")
for i in range(Row-1):
  n = len(List[i])-1
  if List[i][n] != List[i+1][0]:
    flag = False
if flag:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input_[0])
S=[]

for n in range(N):
    s=input_[n+1]
    S.append(s)
S_set=set(S)

ans='Yes'
if len(S_set) != N:
    ans='No'

for n in range(N-1):
    n_ = n+1
    s_0=S[n][-1]
    s_1=S[n_][0]
    
    if s_0 != s_1:
        ans='No'
print(ans)