AtCoder Beginner Contest 109 - Shiritori

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-----
4
hoge
english
hoge
enigma

-----Sample Output-----
No

As hoge is announced multiple times, the rules of shiritori was not observed.

Difficulty: EASY

Starter code:

Solutions:
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)


n = int(input())
li = [input() for _ in range(n)]
if len(set(li)) != n:
	print('No')
	exit()
else:
	for (i, j) in zip(li, li[1:]):
		if i[-1] != j[0]:
			print('No')
			exit()
print('Yes')


n = int(input())
arr = []
ans = 'Yes'
for _ in range(n):
	w = input()
	if w in arr:
		ans = 'No'
	if len(arr) >= 1:
		if w[0] != arr[-1][-1]:
			ans = 'No'
	arr.append(w)
print(ans)


n = int(input())
s = []
for i in range(n):
	s.append(input())
total = True
for i in range(n - 1):
	if s[i][-1] != s[i + 1][0]:
		total = False
		break
	for j in range(len(s)):
		if i != j:
			if s[i] == s[j]:
				total = False
				break
	if total == False:
		break
if total == False:
	print('No')
else:
	print('Yes')


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


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


n = int(input())
w = [input() for i in range(n)]
x = False
if n == len(set(w)):
	if all([w[i - 1][-1] == w[i][0] for i in range(1, n)]):
		x = True
print('Yes' if x else 'No')


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


n = int(input())
s = [input() for i in range(n)]
if len(s) != len(set(s)):
	print('No')
	exit()
for (c, d) in zip(s[0:], s[1:]):
	if c[-1] != d[0]:
		print('No')
		exit()
print('Yes')


n = int(input())
w = [list(input()) for _ in range(n)]
for i in range(n):
	for j in range(n - i - 1):
		if w[i] == w[-j - 1]:
			print('No')
			return
for i in range(n):
	if i < n - 1:
		if w[i][-1] != w[i + 1][0]:
			print('No')
			return
print('Yes')


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


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


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')
			exit()
	print('Yes')
else:
	print('No')


n = int(input())
w = list((input() for _ in range(n)))
ans = True
w2 = set(w)
if len(w) != len(w2):
	ans = False
for i in range(n - 1):
	if w[i][-1] != w[i + 1][0]:
		ans = False
if ans:
	print('Yes')
else:
	print('No')


N = int(input())
l = []
l.append(input())
ans = 'Yes'
for i in range(1, N):
	t = input()
	if t in l:
		ans = 'No'
		break
	elif l[i - 1][-1] == t[0]:
		l.append(t)
	else:
		ans = 'No'
		break
print(ans)


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


import sys
import math
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('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))
ans = 'Yes'
N = ini()
words = []
for _ in range(N):
	words.append(input())
if len(words) != len(set(words)):
	ans = 'No'
for i in range(N - 1):
	if words[i][len(words[i]) - 1] != words[i + 1][0]:
		ans = 'No'
print(ans)


n = int(input())
a = []
for i in range(n):
	a.append(input())
	if i > 0 and (a[i - 1][-1] != a[i][0] or a.count(a[i]) == 2):
		print('No')
		break
else:
	print('Yes')


n = int(input())
k = [input()]
a = 'Yes'
for i in [0] * (n - 1):
	x = input()
	if k[-1][-1] != x[0] or x in k:
		a = 'No'
		break
	k.append(x)
print(a)


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


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


n = int(input())
sl = [input() for _ in [0] * n]
ans = 'Yes'
for i in range(1, n):
	if sl[i - 1][-1] != sl[i][0] or sl.count(sl[i]) != 1:
		ans = 'No'
print(ans)


N = int(input())
words = set()
W = [input() for _ in range(N)]
res = False
for i in range(N):
	if W[i] in words:
		res = True
	words.add(W[i])
	if i < N - 1 and W[i][-1] != W[i + 1][0]:
		res = True
print('YNeos'[res::2])


n = int(input())
tmp1 = input()
tmp = tmp1[len(tmp1) - 1]
s = set()
s.add(tmp1)
flg = True
for i in range(n - 1):
	w = input()
	if w[0] != tmp:
		flg = False
		break
	tmp = w[len(w) - 1]
	s.add(w)
	if len(s) != i + 2:
		flg = False
		break
if flg:
	print('Yes')
else:
	print('No')


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


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


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)


N = int(input())
W = [input() for i in range(N)]
ans = 'Yes'
last = ''
for i in range(N):
	for j in range(i):
		if W[i] == W[j]:
			ans = 'No'
for w in W:
	W_new = [i for i in w]
	if w != W[0] and last != W_new[0]:
		ans = 'No'
	last = W_new[-1]
print(ans)


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


N = int(input())
l = []
S = 'Yes'
A = input()
W = A[-1]
l.append(A)
for i in range(N - 1):
	A = input()
	if A[0] != W or l.count(A) != 0:
		S = 'No'
		break
	l.append(A)
	W = A[-1]
print(S)


n = int(input())
s = input()
ws = set()
ws.add(s)
last = s[-1]
for _ in range(n - 1):
	s = input()
	if s in ws or s[0] != last:
		print('No')
		break
	else:
		ws.add(s)
		last = s[-1]
else:
	print('Yes')


l = [input() for _ in range(int(input()))]
for (i, w) in enumerate(l):
	if i:
		if l[i][0] == l[i - 1][-1] and w not in l[:i]:
			continue
		exit(print('No'))
print('Yes')


n = int(input())
w = input()
s = set([w])
l = w[-1]
for i in range(n - 1):
	w = input()
	if w not in s:
		s.add(w)
		if w[0] != l:
			print('No')
			break
		else:
			l = w[-1]
	else:
		print('No')
		break
else:
	print('Yes')


print('No' if (lambda w: sum([w.count(s) - 1 for s in w]) or sum([w[i][0] != w[i - 1][-1] for i in range(1, len(w))]))([input() for i in range(int(input()))]) else 'Yes')


L = [input() for x in ' ' * int(input())]
print('YNeos'[any((i[-1] != j[0] * L.count(i) for (i, j) in zip(L, L[1:])))::2])


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


n = int(input())
L = [input()]
for i in range(n - 1):
	l = input()
	if l not in L and str(L[i])[-1] == l[0]:
		L.append(l)
	else:
		break
print('Yes' if len(L) == n else 'No')


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


n = int(input())
w = [input() for i in range(n)]
m = w[0][-1]
for i in range(1, n):
	if w.count(w[i]) == 1 and m == w[i][0]:
		m = w[i][-1]
	else:
		print('No')
		return
print('Yes')


N = int(input())
siritolist = []
for i in range(N):
	W = input()
	siritolist.append(W)
for i in range(1, len(siritolist)):
	back_word = list(siritolist[i - 1])
	word = list(siritolist[i])
	if back_word[-1] == word[0] and i > 1:
		for j in range(i - 1):
			if siritolist[i] == siritolist[j]:
				print('No')
				return
	elif back_word[-1] != word[0]:
		print('No')
		return
print('Yes')


n = int(input())
f = True
l = [str(input())]
for i in range(1, n):
	a = str(input())
	if a in l or l[i - 1][-1] != a[0]:
		f = False
		break
	else:
		l += [a]
print('Yes' if f == True else 'No')


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


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


n = int(input())
w = [input() for _ in range(n)]
words = set()
ok = True
for i in range(n):
	if w[i] in words:
		ok = False
		break
	elif i != 0 and w[i - 1][-1] != w[i][0]:
		ok = False
		break
	words.add(w[i])
print('Yes' if ok else 'No')


import sys
n = int(input())
l = []
for x in range(n):
	l.append(str(input()))
	if x > 0:
		if not l[x - 1][-1] == l[x][0] or l[x] in l[:x]:
			print('No')
			sys.exit()
print('Yes')


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


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


import collections
n = int(input())
words = [input() for _ in range(n)]
ok = True
for i in range(n - 1):
	if words[i][-1] != words[i + 1][0]:
		ok = False
count = collections.Counter(words)
for i in count.values():
	if i != 1:
		ok = False
print('Yes' if ok else 'No')


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


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


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')
		exit()
print('No')


c = int(input())
l = []
b = ''
f = False
for i in range(c):
	a = input()
	if l.count(a) > 0 or (b != '' and a[0] != b[-1]):
		f = True
	b = a
	l.append(a)
if f:
	print('No')
else:
	print('Yes')


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


n = int(input())
a = [input() for _ in range(n)]
cnt = 0
aset = set()
aset.add(a[0])
for i in range(1, n):
	if a[i][0] == a[i - 1][-1] and a[i] not in aset:
		aset.add(a[i])
		cnt += 1
print('Yes' if cnt == n - 1 else 'No')


N = int(input())
Ws = [input() for _ in range(N)]
for i in range(1, N):
	if Ws[i][0] != Ws[i - 1][-1] or Ws[i] in Ws[:i]:
		print('No')
		break
else:
	print('Yes')


n = int(input())
w = []
ans = 'Yes'
for i in range(n):
	w.append(input())
if len(set(w)) < len(w):
	ans = 'No'
for i in range(1, n):
	if w[i][0] != w[i - 1][-1]:
		ans = 'No'
print(ans)


n = int(input())
w = [input() for _ in range(n)]
prev = w[0][0]
for x in w:
	if not (w.count(x) == 1 and x[0] == prev):
		print('No')
		exit(0)
	prev = x[-1]
print('Yes')


n = int(input())
b = input()
s = [b]
for i in range(n - 1):
	a = input()
	if a[0] != b[::-1][0] or a in s:
		print('No')
		exit()
	s += [a]
	b = a
else:
	print('Yes')


N = int(input())
W = [input() for i in '0' * N]
print('YNeos'[any((a[0] != b[-1] for (a, b) in zip(W[1:], W))) or len(set(W)) != N::2])


n = int(input())
w = list((input() for i in range(n)))
a = [w[0]]
for j in range(1, n):
	if w[j] not in a and w[j][0] == a[j - 1][-1]:
		a.append(w[j])
		continue
	else:
		print('No')
		break
else:
	print('Yes')


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


import sys
input = sys.stdin.readline

def main():
	N = int(input())
	W = [input().strip() for _ in range(N)]
	s = set()
	prev = ''
	for w in W:
		if w in s:
			print('No')
			return
		if prev == '':
			prev = w[-1]
		elif prev == w[0]:
			prev = w[-1]
		else:
			print('No')
			return
		s.add(w)
	print('Yes')

def __starting_point():
	main()
__starting_point()


n = int(input())
W = [input() for i in range(n)]
word = W[0]
words = [word]
for i in range(1, n):
	if W[i] in words or word[-1] != W[i][0]:
		print('No')
		break
	word = W[i]
	words.append(word)
else:
	print('Yes')


import sys
n = int(input())
w = [input() for i in range(n)]
if all((w[j][len(w[j]) - 1] == w[j + 1][0] for j in range(n - 1))) and len(set(w)) == n:
	print('Yes')
	sys.exit()
print('No')


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


n = int(input())
w = []
w.append(input())
for i in range(1, n):
	W = input()
	if W in w or W[0] != w[i - 1][len(w[i - 1]) - 1]:
		print('No')
		exit(0)
	w.append(W)
print('Yes')


N = int(input())
lst = []
for i in range(N):
	W = input()
	lst.append(W)
for n in range(1, N):
	if lst[n][0] != lst[n - 1][-1] or lst.count(lst[n]) >= 2:
		print('No')
		break
else:
	print('Yes')


N = int(input())
m = dict()
prev = input()
m[prev] = True
flg = True
for _ in range(N - 1):
	s = input()
	flg = flg and s not in m
	flg = flg and prev[len(prev) - 1] == s[0]
	m[s] = True
	prev = s
print('Yes' if flg else 'No')


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


n = int(input())
w = [input()]
for i in range(n - 1):
	tmp = input()
	if w[i][-1] == tmp[0]:
		flg = tmp in w
		if flg == False:
			w.append(tmp)
		else:
			print('No')
			return
	else:
		print('No')
		return
print('Yes')


N = int(input())
W = [input() for i in range(N)]
if all((W[i][0] == W[i - 1][-1] and W[i] not in W[:i] for i in range(1, N))):
	print('Yes')
else:
	print('No')


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


import sys
input = sys.stdin.readline

def main():
	words = []
	n = int(input())
	words = [input().rstrip() for _ in range(n)]
	if len(set(words)) != n:
		print('No')
		return
	endstring = ''
	for word in words:
		if len(endstring) == 0:
			endstring = word[-1]
		elif endstring == word[0]:
			endstring = word[-1]
		else:
			print('No')
			return
	print('Yes')

def __starting_point():
	main()
__starting_point()


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


N = int(input())
W = []
ans = 'Yes'
for i in range(N):
	text = input()
	if i > 0 and text[0] != W[-1][-1] or text in W:
		ans = 'No'
	W.append(text)
print(ans)


n = int(input())
words = [input() for _ in range(n)]
print('Yes' if all([y[0] == x[-1] for (x, y) in zip(words, words[1:])]) and len(set(words)) == n else 'No')


N = int(input())
l = [str(input())]
for i in range(N - 1):
	w = str(input())
	if w in l:
		print('No')
		return
	elif l[-1][-1] != w[0]:
		print('No')
		return
	else:
		l.append(w)
print('Yes')


N = int(input())
A = list((input() for i in range(N)))
if len(A) == len(set(A)):
	if all((A[i][-1] == A[i + 1][0] for i in range(N - 1))):
		print('Yes')
	else:
		print('No')
else:
	print('No')


W = [w.strip() for w in open(0).readlines()[1:]]
judge = [W.count(w) == 1 and w[-1] == W[i + 1][0] for (i, w) in enumerate(W[:-1])]
print('No' if False in judge else 'Yes')


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


N = int(input())
W = []
for i in range(N):
	W.append(str(input()))
flag = True
for i in range(1, N):
	if W[i - 1][-1] != W[i][0]:
		print('No')
		return
	for j in range(i - 1):
		if W[j] == W[i]:
			print('No')
			return
print('Yes')


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


n = int(input())
lst = [input() for i in range(n)]
if all([lst[i][-1] == lst[i + 1][0] for i in range(n - 1)]) and len(set(lst)) == n:
	print('Yes')
else:
	print('No')


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


L = [input() for x in ' ' * int(input())]
b = 0
p = L[0]
for i in L[1:]:
	b |= p[-1] != i[0]
	p = i
print('YNeos'[len(set(L)) < len(L) or b::2])


n = int(input())
l = [input() for _ in range(n)]
b = l[0][-1]
for w in l[1:]:
	if l.count(w) > 1 or not w[0] == b:
		print('No')
		exit()
	b = w[-1]
print('Yes')


N = int(input())
W = [input() for i in range(N)]
for (a, b) in zip(W, W[1:]):
	if a[-1] != b[0]:
		print('No')
		exit()
sl = len(set(W))
print('Yes' if N == sl else 'No')


import sys
n = int(input())
w = []
for i in range(n):
	w.append(input())
if len(w) != len(set(w)):
	print('No')
	return
for i in range(n - 1):
	p = list(w[i])
	q = list(w[i + 1])
	if p[-1] != q[0]:
		print('No')
		return
print('Yes')


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


from collections import Counter
n = int(input())
l = [input() for i in range(n)]
if Counter(l).most_common()[0][1] != 1:
	ans = 'No'
else:
	l_head = [l[i + 1][0] for i in range(n - 1)]
	l_tail = [l[i][-1] for i in range(n - 1)]
	if l_head == l_tail:
		ans = 'Yes'
	else:
		ans = 'No'
print(ans)


n = int(input())
a = [input()]
for i in range(n - 1):
	aa = input()
	if aa in a or aa[0] != a[-1][-1]:
		print('No')
		break
	if i == n - 2:
		print('Yes')
	a.append(aa)


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


n = int(input())
w = [''] * n
a = set()
for i in range(n):
	w[i] = input()
cnt = 0
for x in w:
	if x in a:
		print('No')
		return
	else:
		if cnt > 0:
			if bef != x[0]:
				print('No')
				return
		bef = x[-1]
	cnt += 1
	a.add(x)
print('Yes')


import sys
s = []
for i in range(int(input())):
	W = input()
	if W in s:
		print('No')
		return
	if len(s) != 0 and s[-1][-1] != W[0]:
		print('No')
		return
	s.append(W)
print('Yes')


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


n = int(input())
w = [input() for i in range(n)]
swi = 'Yes'
for i in range(n - 1):
	if w.count(w[i]) > 1 or w[i][-1] != w[i + 1][0]:
		swi = 'No'
print(swi)


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


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


def main():
	n = int(input())
	data = [input() for _ in range(n)]
	ok = True
	if len(set(data)) != n:
		ok = False
	for i in range(n - 1):
		if data[i][-1] != data[i + 1][0]:
			ok = False
	print('Yes' if ok else 'No')
main()


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


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


N = int(input())
W = [input() for _ in range(N)]
b = len(set(W)) == len(W) and all(map(lambda s, t: s == t, (s[-1] for s in W[:-1]), (s[0] for s in W[1:])))
print('YNeos'[not b::2])


(n, *w) = open(0)
n = int(n)
print('No' if len(set(w)) < n else ' YNeos'[all((w[i][-2] == w[i + 1][0] for i in range(n - 1)))::2])


n = int(input())
w = [input() for i in range(n)]
bool = True
for i in range(1, n):
	if w[i][0] != w[i - 1][len(w[i - 1]) - 1]:
		bool = False
	for j in range(0, i):
		if w[i] == w[j]:
			bool = False
if bool:
	print('Yes')
else:
	print('No')


n = int(input())
w = []
for _ in range(n):
	w.append(input())
if len(set(w)) == n and all([w[i][-1] == w[i + 1][0] for i in range(n - 1)]):
	print('Yes')
else:
	print('No')


n = int(input())
a = []
c = 0
for _ in range(n):
	w = input()
	a.append(w)
for i in range(1, n):
	if a[i - 1][-1] != a[i][0]:
		print('No')
		return
if n != len(set(a)):
	print('No')
	return
print('Yes')


n = int(input())
l = [input()]
c = 0
for i in range(n - 1):
	s = input()
	if all([s not in l, s[0] == l[-1][-1]]):
		l.append(s)
	else:
		c += 1
print('Yes' if c == 0 else 'No')


n = int(input())
s = set()
ok = True
t = input()
p = t[-1]
s.add(t)
for i in range(n - 1):
	t = input()
	if t in s:
		ok = False
	s.add(t)
	if t[0] != p:
		ok = False
	p = t[-1]
print('Yes' if ok else 'No')


N = int(input())
W = [input()]
ans = 'Yes'
for _ in range(N - 1):
	w = input()
	if w[0] == W[-1][-1] and w not in W:
		W.append(w)
	else:
		ans = 'No'
print(ans)


n = int(input())
ar = []
for i in range(n):
	ar.append(input())
for i in range(n - 1):
	if ar[i][-1] != ar[i + 1][0]:
		print('No')
		return
	if ar.count(ar[i]) > 1:
		print('No')
		return
print('Yes')


(N, *W) = open(0)
ans = 'Yes'
i = 0
while i + 1 < int(N):
	if W[i][-2] != W[i + 1][0]:
		ans = 'No'
	i += 1
print([ans, 'No'][int(N) > len(set(W))])


n = int(input())
list_w = [input() for s in range(0, n)]
for i in range(0, n):
	if i == 0 or (list_w[i - 1][-1] == list_w[i][0] and list_w[i] not in list_w[:i]):
		continue
	else:
		print('No')
		return
print('Yes')


n = int(input())
a = [input()]
for i in range(n - 1):
	tmp = input()
	if not tmp in a and tmp[0] == a[-1][-1]:
		a.append(tmp)
	else:
		break
if len(a) == n:
	print('Yes')
else:
	print('No')


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


n = int(input())
s = []
res = 'Yes'
for i in range(n):
	s.append(input())
	for j in range(i):
		if s[i] == s[j]:
			res = 'No'
	if i != 0:
		if s[i][0] != s[i - 1][len(s[i - 1]) - 1]:
			res = 'No'
print(res)


N = int(input())
used_word_set = set()
last_char = '@'
for i in range(N):
	w = input()
	if i != 0 and (w in used_word_set or last_char != w[0]):
		print('No')
		return
	last_char = w[-1]
	used_word_set.add(w)
print('Yes')


import sys
(n, *s) = sys.stdin.read().split()
seen = set()
tmp = s[0][0]
for x in s:
	if x[0] != tmp or x in seen:
		print('No')
		return
	else:
		seen.add(x)
		tmp = x[-1]
print('Yes')


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


n = int(input())
w = []
for _ in range(n):
	w.append(input())
a = ''
for i in range(n):
	for j in range(i):
		if w[i] == w[j]:
			print('No')
			return
for j in w:
	b = [i for i in j]
	if j != w[0] and a != b[0]:
		print('No')
		return
	a = b[-1]
print('Yes')


N = int(input())
W = [0] * N
W[0] = str(input())
for i in range(1, N):
	s = str(input())
	if s[0] == W[i - 1][-1] and s not in W:
		W[i] = s
	else:
		print('No')
		exit()
print('Yes')


l = open(0).readlines()[1:]
print('YNeos'[any((a[-2] != b[0] * l.count(a) for (a, b) in zip(l, l[1:])))::2])


N = int(input())
W_list = []
check = True
for i in range(N):
	W = input()
	if i == 0:
		W_list.append(W)
		continue
	if W in W_list:
		check = False
		break
	if W_list[i - 1][-1] != W[0]:
		check = False
		break
	W_list.append(W)
print('Yes' if check else 'No')


n = int(input())
w_l = [input() for _ in range(n)]
memo = set()
b_w = w_l[0][0]
ans = 'Yes'
for w in w_l:
	if b_w == w[0]:
		if w not in memo:
			memo.add(w)
			b_w = w[-1]
			continue
	ans = 'No'
	break
print(ans)


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


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


N = int(input())
s = set()
t = input()
s.add(t)
ans = True
for i in range(N - 1):
	q = input()
	if t[-1] != q[0] or q in s:
		ans = False
	s.add(q)
	t = q
print('Yes') if ans else print('No')


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


def main():
	n = int(input())
	words = [input() for _ in range(n)]
	before = words[0][0]
	for w in words:
		if words.count(w) >= 2 or before[-1] != w[0]:
			print('No')
			return
		before = w
	print('Yes')

def __starting_point():
	main()
__starting_point()


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


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


n = int(input())
mywords = []
for i in range(n):
	mywords.append(input())
judge = 0
for i in range(n - 1):
	if not mywords[i][len(mywords[i]) - 1] == mywords[i + 1][0]:
		judge = 1
for i in range(n):
	if mywords.count(mywords[i]) > 1:
		judge = 1
if judge == 1:
	print('No')
else:
	print('Yes')


n = int(input())
S = input()
last = S[-1]
D = set()
D.add(S)
for i in range(n - 1):
	S = input()
	D.add(S)
	if S[0] == last:
		last = S[-1]
	else:
		print('No')
		return
if len(D) == n:
	print('Yes')
else:
	print('No')


n = int(input())
words = []
for _ in range(n):
	words.append(input())
sets = set(words)
if len(sets) != len(words):
	ans = 'No'
else:
	for i in range(1, n, 1):
		if words[i - 1][-1] != words[i][0]:
			ans = 'No'
			break
		else:
			ans = 'Yes'
print(ans)


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


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


n = int(input())
ans = 'Yes'
s = input()
alist = [s]
for i in range(n - 1):
	new = input()
	if new in alist:
		ans = 'No'
	if new[0] != alist[-1][-1]:
		ans = 'No'
	alist.append(new)
print(ans)


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


N = int(input())
li = []
flag = True
for i in range(N):
	word = input()
	if i != 0:
		if pre_word[len(pre_word) - 1] != word[0] or word in li:
			flag = False
			break
	li.append(word)
	pre_word = word
if flag:
	print('Yes')
else:
	print('No')


N = int(input())
W = list((input() for i in range(N)))
W_len = len(W)
import sys
for i in range(0, W_len):
	n = i + 1
	while n <= W_len - 1:
		if W[i] == W[n]:
			print('No')
			return
		else:
			n += 1
x = 0
while x <= W_len - 2:
	if not W[x][-1] == W[x + 1][0]:
		print('No')
		return
	else:
		x += 1
print('Yes')


n = int(input())
hatsugen = []
w = input()
hatsugen.append(w)
oshiri = w[-1]
Flag = True
for _ in range(n - 1):
	w = input()
	if w[0] != oshiri:
		Flag = False
		break
	if w in hatsugen:
		Flag = False
		break
	oshiri = w[-1]
	hatsugen.append(w)
if Flag:
	print('Yes')
else:
	print('No')


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


n = int(input())
l = [input() for i in range(n)]
f = True
for x in range(n - 1):
	if l[x][-1] != l[x + 1][0]:
		f = False
o = set(l)
if len(l) != len(o):
	f = False
if f:
	print('Yes')
else:
	print('No')


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)


n = int(input())
a = [input()]
for _ in [0] * (n - 1):
	b = input()
	if a[-1][-1] != b[0] or b in a:
		print('No')
		break
	a += [b]
else:
	print('Yes')


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


N = int(input())
words = []
for i in range(N):
	W = input()
	if i == 0:
		top = W[-1]
		words.append(W)
	elif top != W[0] or W in words:
		print('No')
		return
	else:
		top = W[-1]
		words.append(W)
print('Yes')


n = int(input())
w = input()
lst = [w]
for i in range(1, n):
	w = input()
	if w in lst or w[0] != lst[-1][-1]:
		print('No')
		quit()
	lst.append(w)
print('Yes')


n = int(input())
d = set()
m = ''
for i in range(n):
	s = input()
	if i > 0 and (s in d or s[0] != m[-1]):
		print('No')
		exit()
	m = s
	d.add(s)
print('Yes')


n = int(input())
ans = 0
a = ''
l = []
for i in range(n):
	w = input()
	if a == w[0]:
		ans += 1
	a = w[-1]
	l.append(w)
x = 'No'
if ans == n - 1 and len(set(l)) == n:
	x = 'Yes'
print(x)


n = int(input())
W = [input() for i in range(n)]
if len(set(W)) != n:
	print('No')
	exit()
if all((x[-1] == y[0] for (x, y) in zip(W, W[1:]))):
	print('Yes')
else:
	print('No')


N = int(input())
W = [input() for n in range(N)]
a = 'Yes'
for n in range(N - 1):
	if W[n][-1] != W[n + 1][0] or W.count(W[n]) != 1:
		a = 'No'
print(a)


N = int(input())
W = [input()]
flg = 'Yes'
for i in range(1, N):
	W.append(input())
	if not (W[i - 1][-1] == W[i][0] and W.count(W[i]) == 1):
		flg = 'No'
		break
print(flg)


N = int(input())
W = []
for i in range(N):
	W.append(input())
cnt = set()
last = W[0][-1]
for (i, w) in enumerate(W):
	if i == 0:
		cnt.add(w)
		continue
	if w[0] != last:
		print('No')
		return
	last = w[-1]
	cnt.add(w)
	if i + 1 != len(cnt):
		print('No')
		return
print('Yes')


(N, *S) = open(0).read().split()
F = True if len(S) == len(set(S)) else False
for i in range(int(N) - 1):
	if S[i][-1] != S[i + 1][0]:
		F = False
print('Yes' if F else 'No')


N = int(input())
used = set()
for i in range(N):
	s = input()
	if i != 0 and s[0] != p[-1] or s in used:
		print('No')
		exit()
	used.add(s)
	p = s
print('Yes')


import collections
N = int(input())
W = []
f = input()
W.append(f)
ans = 'Yes'
for _ in range(N - 1):
	w = input()
	if f[-1] != w[0]:
		ans = 'No'
	W.append(w)
	f = w
cnt = collections.Counter(W)
for v in cnt.values():
	if v >= 2:
		ans = 'No'
print(ans)


N = int(input())
alter_str = input()
str_list = [alter_str]
for _ in range(N - 1):
	input_str = input()
	if input_str in str_list:
		print('No')
		break
	if input_str[0] != alter_str[-1]:
		print('No')
		break
	else:
		str_list.append(input_str)
		alter_str = input_str
else:
	print('Yes')


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


n = int(input())
l = []
w = [0] * n
for i in range(n):
	w[i] = input()
	if w[i] in l:
		print('No')
		return
	l.append(w[i])
	if i >= 1 and w[i - 1][-1] == w[i][0] or i == 0:
		continue
	else:
		print('No')
		return
print('Yes')


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


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


N = int(input())
L = []
for _ in range(N):
	W = str(input())
	if W in L:
		print('No')
		return
	L.append(W)
for i in range(N - 1):
	if L[i][len(L[i]) - 1] != L[i + 1][0]:
		print('No')
		return
print('Yes')


n = int(input())
l = []
e = 'abcdefghijklmnopqrstuvwxyz'
ans = 'Yes'
for i in range(n):
	w = input()
	if w[0] not in e or w in l:
		ans = 'No'
	l.append(w)
	e = w[-1]
print(ans)


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


n = int(input())
w = str(input())
a = []
a.append(w)
for i in range(1, n):
	x = w[len(w) - 1]
	w = str(input())
	if x != w[0] or w in a:
		print('No')
		return
	a.append(w)
print('Yes')


N = int(input())
b = input()
d = {b}
f = 1
for _ in [0] * ~-N:
	s = input()
	if b[-1] != s[0] or s in d:
		f = 0
		break
	b = s
	d |= {s}
print('Yes' if f else 'No')


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


n = int(input())
word = [input()]
for _ in range(n - 1):
	w = input()
	if w not in word and w[0] == word[-1][-1]:
		word.append(w)
	else:
		print('No')
		exit()
print('Yes')


N = int(input())
W = []
for i in range(N):
	W.append(input())
False_cnt = 0
for i in range(N):
	if W.count(W[i]) >= 2:
		False_cnt += 1
for i in range(N - 1):
	x = W[i]
	y = W[i + 1]
	if not x[-1] == y[0]:
		False_cnt += 1
if False_cnt == 0:
	print('Yes')
else:
	print('No')


N = int(input())
ls = [input() for i in range(N)]
flag = 'Yes'
for i in range(1, N):
	if ls[i][0] != ls[i - 1][-1]:
		flag = 'No'
		break
x = len(set(ls))
if x < N:
	flag = 'No'
print(flag)


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


N = int(input())
w = [input() for _ in range(N)]
valid = len(set(w)) == len(w) and all((a[-1] == b[0] for (a, b) in zip(w, w[1:])))
print('Yes' if valid else 'No')


N = int(input())
W = [input()]
a = 'Yes'
for i in range(1, N):
	k = input()
	W.append(k)
	if W[-2][-1] != k[0] or len(set(W)) != i + 1:
		a = 'No'
		break
print(a)


n = int(input())
W = [input() for _ in range(n)]
if len(W) > len(set(W)):
	print('No')
	return
tmp = W[0][-1]
for w in W[1:]:
	if w[0] != tmp:
		print('No')
		return
	tmp = w[-1]
print('Yes')


n = int(input())
w = set()
wk = None
for _ in range(n):
	wi = input()
	if wi in w or (wk and wk[-1] != wi[0]):
		print('No')
		break
	w.add(wi)
	wk = wi
else:
	print('Yes')


n = int(input())
bk = input()
word = [bk]
for _ in range(1, n):
	s = input()
	if s[0] != bk[-1] or s in word:
		print('No')
		exit()
	else:
		word.append(s)
		bk = s
print('Yes')


def check_shiritori(n: int, w: list) -> bool:
	if len(set(w)) < n:
		return False
	for i in range(n - 1):
		if w[i][-1] != w[i + 1][0]:
			return False
	return True

def main():
	n = int(input())
	w = []
	for i in range(n):
		w.append(input())
	if check_shiritori(n, w):
		print('Yes')
	else:
		print('No')

def __starting_point():
	main()
__starting_point()


N = int(input())
W = list((input() for i in range(N)))
for i in range(N - 1):
	if W.count(W[i]) == 2:
		print('No')
		break
	if W[i][-1] != W[i + 1][0]:
		print('No')
		break
else:
	print('Yes')


a = int(input())
l = []
for i in range(a):
	l.append(input())
head = l[0][0]
c = 0
if len(l) != len(set(l)):
	print('No')
	exit
else:
	for i in l:
		if i[0] != head:
			print('No')
			break
		else:
			head = i[-1]
			c += 1
if c == a:
	print('Yes')


N = int(input())
li = [input() for i in range(N)]
temp = li[0][-1]
for j in range(N - 1):
	if temp == li[j + 1][0]:
		temp = li[j + 1][-1]
	else:
		print('No')
		return
li.sort()
for k in range(N - 1):
	if li[k] == li[k + 1]:
		print('No')
		return
print('Yes')


N = int(input())
W = [input() for _ in range(N)]
print('Yes' if len(W) == len(set(W)) and all((i[-1] == j[0] for (i, j) in zip(W, W[1:]))) else 'No')


(n, *l) = open(0).read().split()
print('Yes' if len(set(l)) == len(l) and all((l[i][-1] == l[i + 1][0] for i in range(int(n) - 1))) else 'No')


N = int(input())
W = [input() for _ in range(N)]
if len(set(W)) != len(W):
	print('No')
	return
prev = W[0][0]
for w in W:
	if w[0] != prev:
		print('No')
		return
	prev = w[-1]
print('Yes')


n = int(input())
dic = [input() for _ in range(n)]
ans = 'Yes'
for i in range(1, n):
	if dic[i] in dic[:i] or dic[i][0] != dic[i - 1][-1]:
		ans = 'No'
		break
print(ans)


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


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


N = int(input())
W = [input() for n in range(N)]
for i in range(N - 1):
	if W[i][-1] != W[i + 1][0] or W[i + 1] in W[0:i:1]:
		print('No')
		break
else:
	print('Yes')


n = int(input())
w = input()
s = {w}
for i in range(n - 1):
	ww = input()
	if w[-1] != ww[0] or ww in s:
		print('No')
		exit()
	w = ww
	s.add(w)
print('Yes')


n = int(input())
li = [input() for i in range(n)]
for i in range(n - 1):
	for j in range(i + 1, n):
		if li[i] == li[j]:
			print('No')
			return
for i in range(n - 1):
	if li[i][-1] != li[i + 1][0]:
		print('No')
		return
print('Yes')


n = int(input())
seen = set()
tmp = ''
for _ in range(n):
	x = input()
	if not tmp:
		seen.add(x)
		tmp = x[-1]
		continue
	elif x[0] != tmp or x in seen:
		print('No')
		return
	else:
		seen.add(x)
		tmp = x[-1]
print('Yes')


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


N = int(input())
c = 0
m = []
s = input()
m.append(s)
for i in range(N - 1):
	l = input()
	if l not in m and m[i][-1] == l[0]:
		c += 1
	m.append(l)
if c == N - 1:
	print('Yes')
else:
	print('No')


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


n = int(input())
w = [input() for i in range(n)]
a = all([w[i][-1] == w[i + 1][0] for i in range(n - 1)])
b = len(w) == len(set(w))
print('Yes' if a and b else 'No')


N = int(input())
W = [input() for _ in range(N)]
used = []
first = W[0]
used.append(first)
for index in range(1, len(W)):
	if W[index][0] == W[index - 1][-1] and W[index] not in used:
		used.append(W[index])
	else:
		print('No')
		return
print('Yes')


l = [input() for _ in range(int(input()))]
for (i, w) in enumerate(l):
	if i:
		if l[i][0] != l[i - 1][-1] or w in l[:i]:
			exit(print('No'))
print('Yes')


import math
import itertools
import sys
n = int(input())
last = input()
log = []
log.append(last)
q = []
ans = 'Yes'
for i in range(n - 1):
	tmp = input()
	q.append(tmp)
for i in q:
	if i[0] != last[-1] or i in log:
		ans = 'No'
		break
	else:
		last = i
		log.append(i)
print(ans)


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


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


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


import os
import sys
from collections import defaultdict, Counter, deque
from itertools import product, permutations, combinations, accumulate
from operator import itemgetter
from bisect import bisect_left, bisect
from heapq import heappop, heappush, heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
	n = int(input())
	vectoer = []
	flag = True
	for i in range(n):
		s = input()
		vectoer.append(s)
	if len(vectoer) != len(set(vectoer)):
		flag = False
	for i in range(n - 1):
		if vectoer[i][-1] != vectoer[i + 1][0]:
			flag = False
			break
	if flag:
		print('Yes')
	else:
		print('No')

def __starting_point():
	main()
__starting_point()


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


def readinput():
	n = int(input())
	w = []
	for _ in range(n):
		w.append(input())
	return (n, w)

def main(n, w):
	words = {}
	word = w[0]
	words[w[0]] = 1
	for i in range(1, n):
		if w[i][0] != word[-1]:
			return 'No'
		elif w[i] not in words:
			words[w[i]] = 1
		else:
			return 'No'
		word = w[i]
	return 'Yes'

def __starting_point():
	(n, w) = readinput()
	ans = main(n, w)
	print(ans)
__starting_point()


n = int(input())
a = input()
s = {a}
r = 'Yes'
for i in range(1, n):
	b = input()
	if a[-1] != b[0] or b in s:
		r = 'No'
		break
	a = b
	s.add(b)
print(r)


N = int(input())
W = [input() for _ in range(N)]
d = dict()
last = W[0][0]
good = True
for w in W:
	if d.get(w) != None:
		good = False
		break
	elif w[0] != last:
		good = False
		break
	else:
		d[w] = 1
		last = w[-1]
if good:
	print('Yes')
else:
	print('No')


from typing import List

def answer(n: int, w: List[str]) -> str:
	if len(set(w)) != len(w):
		return 'No'
	for i in range(1, len(w)):
		if not w[i].startswith(w[i - 1][-1]):
			return 'No'
	return 'Yes'

def main():
	n = int(input())
	w = [input() for _ in range(n)]
	print(answer(n, w))

def __starting_point():
	main()
__starting_point()