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:
# 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():
    line = input()
    N = int(line)
    lines = list()
    lines.append(line)
    for _ in range(N):
        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: 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] or W.count(W[i]) != 1:
        ans = "No"

print(ans)

Submission status: Accepted

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

if n != len(Counter(w)):
    print('No')
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

last_letter = w[0][0]
for word in w:
    if word in words_hist:
        print('No')
        exit()
    if not word.startswith(last_letter):
        print('No')
        exit()
    
    words_hist.add(word)
    last_letter = word[-1]

print('Yes')

Submission status: Accepted

Solution code:
# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
N = int(input())
w =[]
for i in range(N):
    x =input().strip()
    w.append(x)

#重複回答チェック
from collections import Counter
c =Counter(w)
c_k =list(c.values())
ans =""
if max(c_k) >=2:
    print("No")
    sys.exit()
    
ans ="Yes"
for i in range(N-1):
    if w[i][-1] != w[i+1][0]:
        ans ="No"
        break
print(ans)

Submission status: Accepted

Solution code:
Row = int(input())
flag = True
List = []
for i in range (Row):
  List.append(input())
s_l = set(List)
if len(List) != len(s_l):
  print("No")
else:
  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: Accepted

Solution code:
n = int(input())
l = [input() for _ in range(n)]
flg1 = len(l) == len(set(l))
flg2 = all(l[i][-1] == l[i + 1][0] for i in range(n - 1))
print(["No", "Yes"][flg1 and flg2])

Submission status: Accepted

Solution code:
#54
import sys
N = int(input())
word = [] 

w = input()
word.append(w)

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

Submission status: Accepted

Solution code:
import sys

n = int(input())
l = [input() for i in range(n)]
for i in range(n):
  if i > 0:
    if l[i-1][-1] != l[i][0]:
      print("No")
      sys.exit()
  if l.count(l[i]) > 1:
    print("No")
    sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = [input()]
ans = 1
for i in range(N-1):
    new_word = input()
    if new_word in W:
        ans = 0
        break
    W.append(new_word)
    if W[i][-1]!=W[i+1][0]:
        ans = 0
        break

for j in range(N-i-2):
    input()

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

Submission status: Accepted

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

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

flag = 1

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

# print(w)
moji = w[0][-1]
for i in w[1:]:
    # print(i)
    if moji != i[0]:
        flag = 0
    moji = i[-1]

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

Submission status: Accepted

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

    memo = set()
    prev = ''
    for _ in range(N):
        s = input()
        if prev and ((prev[-1] != s[0]) or (s in memo)):
            print('No')
            return
        memo.add(s)
        prev = s

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a_word = input()
words = [a_word]
judge = 'Yes'
for i in range(N-1):
  b_word = input()
  if not a_word[-1] == b_word[0]:
    judge = 'No'   
  elif b_word in words:
    judge = 'No'
  words.append(b_word)
  a_word = b_word

print(judge)

Submission status: Accepted

Solution code:
N = int(input())

words_list = [input()]
c = 1

for i in range(1,N):
    new_word = input()
    words_list.append(new_word)
    
    if new_word in words_list[:i-1]:
        c += 0
        
    elif new_word[0] != words_list[i-1][len(words_list[i-1])-1]:
        c += 0
        
    else:
        c += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
_,*W = open(0).read().split()

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

s = W[0][0]
for w in W:
    if s != w[0]:
        print('No')
        sys.exit()
    s = w[-1]

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    has_said = set()
    n = int(input())
    last = ""
    for i in range(n):
        w = input()
        if i > 0 and (w[0] != last or w in has_said):
            print("No")
            break
        last = w[-1]
        has_said.add(w)
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
C = {}
flag = 0
for i in range(N):
    W = input().strip()
    if W not in C:
        C[W] = 0
    C[W] += 1
    if i==0:
        a = W
    else:
        if W[0]!=a[-1]:
            flag = 1
        a = W
if len(C)<N or flag==1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

n = ini()
w = [ins() for _ in range(n)]


def solve():
    p = set()
    p.add(w[0])
    for i in range(1, n):
        if w[i] in p:
            return False
        if w[i - 1][-1] != w[i][0]:
            return False
        p.add(w[i])
    return True


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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
w = read().decode().rstrip().split()

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

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

prev = s_list[0][-1]
ans = "Yes"
tmp = [s_list[0]]
for s in s_list[1:]:

    if s in tmp:
        ans = "No"
        break

    if s[0] != prev:
        ans = "No"
        break

    tmp.append(s)
    prev = s[-1]
print(ans)

Submission status: Accepted

Solution code:
# B - Shiritori
N = int(input())
W = [str(input()) for _ in range(N)]

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

s = []
for _ in range(n):
    s.append(input())

it = iter(s)
for p, ne in zip(it, it):
    if p[-1] != ne[0]:
        print("No")
        exit()

if s[-2][-1] != s[-1][0]:
    print("No")
    exit()

if len(set(s)) == n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = [input() for _ in range(N)]
print("Yes" if L.count(L[0])==1 and all(L.count(L[i])==1 \
                  and L[i][0]==L[i-1][-1] for i in range(1, N)) else "No")

Submission status: Accepted

Solution code:
N = int(input())
first = input()
seen = {first}
for _ in range(N-1):
    w = input()
    if w[0] != first[-1]:
        print("No")
        break
    if w in seen:
        print("No")
        break
    seen.add(w)
    first = w
else:
    print("Yes")

Submission status: Accepted

Solution code:
import math
def main():
  n = int(input())
  w = [input() for i in range(n)]
  flg=0
  
  for i in range(1,n):
    if w[i][0]!=w[i-1][len(w[i-1])-1]:
      flg=1
      break

  if flg==1 or len(set(w))!=n:
    print("No")
  else:
    print("Yes")
main()

Submission status: Accepted

Solution code:
import sys
N = int(input())
lst = [str(input()) for _ in range(N)]


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

for i in range(len(lst)-1):
    if lst[i][-1] != lst[i+1][0]:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter
import sys
N = int(input())
lst = [str(input()) for _ in range(N)]
#print(lst)
c = Counter(lst)
for i in c:
    if lst.count(i) > 1:
        print('No')
        sys.exit()

for i in range(len(lst)-1):
    if lst[i][-1] != lst[i+1][0]:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

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

for n in range(N-1):
  w = input()
  if W[-1] == w[0] and w not in L:
    L.append(w)
    W = w
  else:
    print("No")
    exit()
    
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,*ww = open(0).read().split()

import sys
words = set()
prev = None
for w in ww:
    if w in words:
        print('No')
        sys.exit()
    words.add(w)
    
    if prev and prev[-1] != w[0]:
        print('No')
        sys.exit()
    prev = w
print('Yes')

Submission status: Accepted

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

for n in range(N):
    s=input()
    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)

Submission status: Accepted

Solution code:
n = int(input())
l = []
flag = 0
for i in range(n):
    w = input()
    l.append(w)
for k in range(1,n):
    if  l[k-1][-1] != l[k][0]:
        flag =1
        break

    for j in range(k):
        if l[k] == l[j]:
            flag = 1
            break
        
if(flag == 1):
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

ans = True
for i in range(1, n):
    if w[i][0] != w[i-1][len(w[i-1])-1]:
        ans = False
        break
    else:
        for j in range(0, i):
            if w[j] == w[i]:
                ans = False
                break

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

Submission status: Accepted

Solution code:
a = True
n = int(input())
p = input()
s = {p}
for i in range(n-1):
    c = input()
    if p[-1] != c[0] or c in s:
        a = False
    else:
        p = c
        s.add(p)
if a:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
w=[]
j=0
for i in range(n):
    k=input()
    w.append(k)
for i in range(n):
    if i!=0:
        a=w[i]
        b=w[i-1]
        if a[0]!=b[len(b)-1]:
            print("No")
            j+=1
            break

    if w.count(w[i])>1:
        print("No")
        j+=1
        break
if j==0:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
before = ''
said = set([])
f = True
for i in range(n):
    if i==0:
        before = input()
        said.add(before)
        continue
    s = input()
    if before[-1] != s[0] or s in said:
        f = False
    before = s
    said.add(s)
print('Yes' if f else 'No')

Submission status: Accepted

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

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

if not f:
    print("No")
else:
    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())
Word = [input()]
Flag = True
for T in range(0,N-1):
    New = input()
    if Word[-1][-1]==New[0] and New not in Word:
        Word.append(New)
    else:
        Flag = False
        break
if Flag: print('Yes')
else: print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
d = dict()
prev = ''
for i, s in enumerate(S):
    if i > 0 and s[0] != prev:
        print('No')
        break
    if d.get(s, 0) > 0:
        print('No')
        break
    d[s] = 1
    prev = s[-1]
else:
    print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
lw=[input() for i in range(n)]
used=set()
cond=True
last=lw[0][0]
for w in lw:
    if w in used or last !=w[0]:
        cond=False
        break
    used.add(w)
    last=w[-1]
print("Yes" if cond else "No")

Submission status: Accepted

Solution code:
import sys
N = int(input())
W = [input() for _ in range(N)]
for i in range(N - 1):
    if W[i][-1] != W[i + 1][0]:
        print('No')
        sys.exit()
    else:
        for j in range(i + 1):
            if W[j] == W[i + 1]:
                print('No')
                sys.exit()
print('Yes')

Submission status: Accepted

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

cond = True
used = set()
last = lw[0][0]
for w in lw:
    if w in used or last != w[0]:
        cond = False
        break
    used.add(w)
    last = w[-1]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
H=input()
word=[]
word.append(H)
for i in range(N-1):
  S=input()
  if S in word:
    print('No')
    exit()
  else:
    if H[-1]==S[0]:
      H=S
      word.append(H)
    else:
      print('No')
      exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    w=[input() for _ in range(int(input()))]
    sumi=set()
    p=w[0][0]
    for s in w:
        if s in sumi or p != s[0]:
            print("No")
            return
        sumi.add(s)
        p = s[-1]
    print("Yes")
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def f(words):
	seen = set([words[0]])
	p = words[0]
	for w in words[1:]:
		if w in seen or p[-1] != w[0]: return False
		p = w
		seen.add(w)
	return True

print 'Yes' if f([raw_input() for _ in range(int(raw_input()))]) else 'No'

Submission status: Accepted

Solution code:
N = int(input())
ans = 'Yes'
a = set()
pre = ''
for i in range(N):
    word = input()
    if not word in a and (pre == word[0] or pre == '') and ans == 'Yes':
        ans = 'Yes'
        a.add(word)
        pre = word[-1]
    else:
        ans = 'No'
print(ans)

Submission status: Accepted

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

ans = 'Yes'
if len(S) != len(set(S)):
    ans = 'No'
for i in range(N-1):
    if S[i][-1] != S[i+1][0]:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N = int(input())
S = []
for i in range(N):
    S.append(input().rstrip('\n'))

if len(set(S)) != N:
    print("No")
    exit()
else:
    for i in range(1, N):
        if S[i - 1][-1] != S[i][0]:
            print("No")
            exit()

print("Yes")

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
ns = lambda: stdin.readline().rstrip()
na = lambda: list(map(int, stdin.readline().split()))

# code here
N = ni()
W = []
w = input()
l = w[-1]
W.append(w)
for i in range(N-1):
    w = input()
    if w in W:
        print('No')
        break

    if not w[0] == l:
        print('No')
        break

    l = w[-1]
    W.append(w)
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
word_bank = set()
last_char = ''

for n in range(N):
  new_word = input()
  if new_word in word_bank:
    print('No')
    exit(0)
  elif n != 0 and new_word[0] != last_char:
    print('No')
    exit(0)
  else:
    word_bank.add(new_word)
    last_char = new_word[-1]

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
words = []
for _ in range(N):
    words.append(input())
print('Yes' if all(words[i].startswith(words[i-1][-1]) for i in range(1, N)) and len(set(words)) == N else 'No')

Submission status: Accepted

Solution code:
N = int(input())

w = [None] * N
for i in range(N):
    w[i] = input()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, *w = open(0).read().split()
s = set(w)
if len(s) != len(w):
    print("No")
    exit()
for i in range(1, int(n)):
    if w[i][0] != w[i - 1][-1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

before = array_word[0]
for I in array_word[1:]:
    if before[-1] == I[0] and array_word.count(I) == 1:
        before = I
        continue 
    else:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

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

Submission status: Accepted

Solution code:
n=int(input())
w=input()
tmp=w[-1:]
d={}
d[w]=1
for i in range(1,n):
    w=input()
    if w not in d:
        d[w]=1
    else:
        print("No")
        exit()
    if w[0]==tmp:
        tmp=w[-1:]
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
dic = {}
N = int(input())
pre = input()
dic[pre] = 0
flag = True
for i in range(N-1):
    s = input()
    if list(pre)[len(pre)-1]!=list(s)[0]:
        flag=False

    if s in dic:
        flag=False
    else:
        dic[s]=0

    pre = s

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
pw = None
s = set()
ans = 'Yes'
for _ in range(n):
    w = input().rstrip()
    if pw is not None:
        if w[0] != pw[-1] or w in s:
            ans = 'No'
    pw = w
    s.add(w)
print(ans)

Submission status: Accepted

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

ans = "Yes"

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

print(ans)

Submission status: Accepted

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

if len(w) != len(set(w)):
    ans = 'No'
else:
    for i in w:
        if i[0] != p:
            ans = 'No'
            break
        else:
            p = i[-1]
    else:
        ans = 'Yes'

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
la=[input()]
res = "Yes"
for i in range(1,n):
    a=input()
    if a in la or a[0]!=la[i-1][-1]:
        res="No"
        break
    la+=[a]
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    w = set()
    s = input()
    w.add(s)
    ans = 1
    for _ in range(n-1):
        c = input()
        if (s[-1] != c[0] or c in w): ans = 0
        w.add(c)
        s = c
    if ans:
        print("Yes")
    else:
        print("No")

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()




"""

4
1 2
2 4
1 3
3
2 2 4
4 5 6

6
1 2
2 3
3 4
4 5
4 6
3
3 5 6
2 17 31 5 11

"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

W=set()
s="*"
F=True
for _ in range(N):
    H=input()
    if s=="*" or (s==H[0] and H not in W):
        W.add(H)
        s=H[-1]
    else:
        F=False
if F:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    W = [input() for _ in range(N)]
    used = []
    for i in range(1, N):
        if W[i-1][-1] != W[i][0] or W[i] in used:
            print("No")
            return 
        used.append(W[i-1])
    print("Yes")




if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

l = []

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

Submission status: Accepted

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

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

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

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
l = []
pre_c = None
ans = True
for _ in range(n):
    w = input()
    # print(w)

    if w in l:
        ans = False
        break
    if not(pre_c is None or pre_c == w[0]):
        ans = False
        break

    l.append(w)
    pre_c = w[-1]

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