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

Solution (Python):
n = int(input())
lst = [input() for _ in range(n)]
lstset = set(lst)

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

Solution (Python):
N = int(input())
W = [input() for _ in range(N)]
used = [W[0]]
current = W[0]

for w in W[1:]:
    if w[0] == current[-1] and w not in used:
        current = w
        used.append(w)
    else:
        print("No")
        break
else:
    print("Yes")

Solution (Python):

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

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

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

Solution (Python):
n = int(input())
l = [input() for i in range(n)]
f = True
if len(set(l)) != len(l):
  f = False
else:
  for i in range(n-1):
    if l[i][-1] != l[i+1][0]:
      f = False
      break

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

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	n = int(input())
	said_word=set()
	pre_word=input()
	said_word.add(pre_word)
	for _ in range(n-1):
		s = input()
		
		if s in said_word or s[0] != pre_word[-1]:
			return 'No'
		said_word.add(s)
		pre_word=s
	return 'Yes'
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
N = int(input())

d = {}
w1 = []
f = False
for i in range(N):
    w = input()

    if d.get(w) is None:
        d[w] = 1
    else:
        f = True

    w1.append(w)

for i in range(1, N):
    if w1[i-1][-1] == w1[i][0]:
        continue
    else:
        f = True

print('Yes' if f is False else 'No')

Solution (Python):
n = int(input())
s = input()
dup = [s]
ans = 'Yes'
for i in range(n-1):
    next = input()
    if s[-1]!=next[0] or next in dup:
        ans = 'No'
    else:dup.append(next)
    s = next
print(ans)

Solution (Python):
n = int(input())
s = list(input())
dup = [''.join(s)]
ans = 'Yes'
for i in range(n-1):
    next = list(input())
    if s[-1]!=next[0] or ''.join(next) in dup:
        ans = 'No'
    else:dup.append(''.join(next))
    s = next
print(ans)

Solution (Python):
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')

Solution (Python):


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

Solution (Python):
n = int(input())
w = [''] * n
for i in range(n):
    w[i] = str(input())

flag = True
for i in range(1,n):
    a = list(w[i-1])
    b = list(w[i])
    if a[-1] == b[0]:
        pass
    else:
        flag = False

chk = list(set(w))
if len(w) == len(chk):
    pass
else:
    flag = False
        
if flag:
    print('Yes')
else:
    print('No')

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

Solution (Python):
N=int(input())
W=[str(input()) for i in range(N)]
def main():
    if len(set(W))!=N:
        return 'No'
    for i in range(N):
        j=i+1
        if i<N-1 and W[i][len(W[i])-1]!=W[j][0]:
            return 'No'
            break
        if i==N-1:
            return 'Yes'
            
print(main())

Solution (Python):
from collections import Counter

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


cnt = Counter(history)
for val in cnt.values():
    if val >= 2:
        print('No')
        exit()

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

print('Yes')

Solution (Python):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):  
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


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


if has_duplicates2(w):
    print('No')
    exit()

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

Solution (Python):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):  
    seen = []
    unique_list = [x for x in seq if x not in seen and not seen.append(x)]
    return len(seq) != len(unique_list)


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


if has_duplicates2(w):
    print('No')
    exit()

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

Solution (Python):
import math
import itertools
import statistics



def check(n):
    for i in range(n-1):
        if w[n]==w[i]:
            return True
    return False

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 check(i):
        print("No")
        exit()

print("Yes")

Solution (Python):
def main():
    N = int(input())
    W = [input() for _ in range(N)]
    if len(W) != len(set(W)):
        print("No")
        exit()
    for i in range(1, N):
        if W[i-1][-1] != W[i][0]:
            print("No")
            exit()
    print("Yes")

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
used = list()
flag = True
for i in range(N):
    w = input()
    if i == 0:
        used.append(w)
        shiri = w
    else:
        if shiri[-1] != w[0]:
            flag = False
            
        else:
            if w in used:
                flag = False
            else:
                used.append(w)
                shiri = w
                
print('Yes' if flag ==True else "No")

Solution (Python):
n = int(input())
ok = True
w = [input() for _ in range(n)]
s = [w[0]]
for i in range(n-1):
    if w[i+1] in s:
        ok = False
        break
    s.append(w[i+1])
    
    if w[i][-1] != w[i+1][0]:
        ok = False 
        break
if ok:print("Yes")
else:print("No")

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

pre=W.pop(0)
ans=[]
ans.append(pre)
for word in W:
    if((word in ans)==True or pre[-1]!=word[0]):
        print('No')
        sys.exit()
    pre=word
    ans.append(word)
print('Yes')

Solution (Python):
n = int(input())

w = list(input() for i in range(n))

rule = "No"

if len(w) == len(set(w)):
  rule = "Yes"
else:
  print("No")
  exit()

c = 0
for i in range(1,n):
  if w[i-1][-1] == w[i][0]:
    c += 1
    continue
  
if c == n-1:
  rule = "Yes"
else:
  print("No")
  exit()
    
    



print(rule)

Solution (Python):

n = int(input())
W = []
for i in range(n):
  W.append(input())

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
W = [input() for _ in range(N)]

before = [W[0]]
for i in range(1,N) :
    if W[i] in before :
        print("No")
        exit()
    if W[i-1][-2] != W[i][0] :
        print("No")
        exit()
    before.append(W[i])

print("Yes")

Solution (Python):
import copy
n=int(input())
ab = []
for _ in range(n):
    s=input()
    ab.append(s)

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

cp = copy.copy(ab)

cp = list(set(cp))

if len(ab) == len(cp):
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
w_li = [input() for i in range(N)]
past_words = []
for i in range(N) :
    if i != 0 and (w_li[i] in past_words or past_words[i - 1][-1] != w_li[i][0]) :
        print("No")
        exit()
    past_words.append(w_li[i])
print("Yes")

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

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

h, b = [], []
for i in range(n):
    if i != 0:
        h.append(w[i][0])
    if i != n-1:
        b.append(w[i][-1])

for i, j in zip(h, b):
    if i != j:
        print("No")
        exit()

print("Yes")

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

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

Solution (Python):
def main():
    N = int(input())
    W = [input() for _ in range(N)]
    p = W[0][-1]
    S = set(W)

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

    del W[0]

    for w in W:
        if w[0] == p:
            p = w[-1]
        else:
            print("No")
            return

    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):
import sys
n = int(input())
w = []
for i in range(n):
    w.append(input())
for j in range(n):
    if w.count(w[j]) != 1:
        print("No")
        sys.exit()
for k in range(n-1):
    x = list(w[k])
    y = list(w[k+1])
    if x[len(x)-1] != y[0]:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
N = int(input())
W = [str(input()) for _ in range(N)]
_list = []
cnt=0
for i in range(N-1):
    if W[i][-1]!=W[i+1][0] or W[i] in _list:
        print('No')
        cnt=1
        break
    else:
        _list.append(W[i])
if cnt==0 and W[N-1] in _list:
    print('No')
    cnt=1
if cnt==0:
    print('Yes')

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    flg=1
    n=INT()
    w=[]
    for i in range(n):
        w.append(STR())
    ws=set(w)
    if len(ws)!=len(w):
        flg=0
    for i in range(n-1):
        if w[i][-1]!=w[i+1][0]:
            flg=0
    if flg==1:
        print('Yes')
    else:
        print('No')
    
if __name__ == '__main__':
    do()

Solution (Python):
n = int(input())
from collections import defaultdict
d = defaultdict(int)

s = input()
d[s] += 1
pre = s[-1]
for _ in range(n-1):
    s = input()
    if s[0] != pre or d[s] != 0:
        print('No')
        break
    d[s] += 1
    pre = s[-1]
else:
    print('Yes')

Solution (Python):
N = int(input())
words_set = set()
words_list = []
OK = True
for _ in range(N):
    s = input()
    words_list.append(s)
    words_set.add(s)


last_word = words_list[0][-1]

for i in range(1, N):
    if last_word == words_list[i][0]:
        last_word = words_list[i][-1]
    else:
        OK = False
        break

if OK and len(words_list) == len(words_set):
    print('Yes')
else:
    print('No')

Solution (Python):
n=int(input())
w_list=[input() for _ in range(n)]

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

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

Solution (Python):
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)

Solution (Python):
def has_duplicates(seq):
    return len(seq) != len(set(seq))

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



if has_duplicates(W) == True:
    flag = False


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

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

Solution (Python):
n = int(input())
w = []
for _ in range(n):
    ww = list(input())
    w.append(ww)
    
bool = True
for i in range(n-1):
    if w.count(w[i]) == 1:
        if w[i][-1] == w[i+1][0]:
            continue
        else:
            bool = False
            break
    else:
        bool = False
        break
        
print('Yes' if bool else 'No')

Solution (Python):
import collections

N = int(input())
words = [input() for i in range(N)]
judge = 'Yes'

count = collections.Counter(words)
if (count.most_common(1)[0][1] >= 2):
    judge = 'No'

for i in range(N-1):
    end_w = words[i][-1]
    beg_w = words[i + 1][0]

    if (end_w != beg_w):
        judge = 'No'
        break

print(judge)

Solution (Python):
n=int(input())
w=[]

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

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

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

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

Solution (Python):
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import defaultdict

N = ni()
W = nsn(N)
d = defaultdict(int)

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

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

Solution (Python):
N = int(input())
used = []
old = None
fail = False
for _ in range(N):
  str = input()
  
  if old is not None:
    if str[0] != old or str in used:
      fail = True
      break
  old = str[-1]
  used.append(str)
print("No" if fail else "Yes")

Solution (Python):
def f(W):
    if len(set(W)) != len(W):
        return False
    return all(w1[-1] == w2[0] for w1, w2 in zip(W, W[1:]))

N = int(input())
W = tuple(input() for _ in range(N))
print('Yes' if f(W) else 'No')

Solution (Python):
f=-1
N=int(input())
S=[];T=[];U=[]
for i in range(N):
  a=list(input())
  S.append(a)

for i in range(1,N):
  if S[i-1][-1]!=S[i][0]:
    f=1
for i in range(N):
  T.append("".join(S[i]))
U=set(T)
if f!=1 and len(T)==len(U):
  print("Yes")
else:
  print("No")

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

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input().rstrip())
    W = []
    for i in range(N):
        W.append(input().rstrip())
        
    for i in range(1,N):
        if W[i][0] != W[i-1][-1]:
            print('No')
            return
        if W[i] in W[0:i-1]:            
            print('No')
            return            
    print('Yes')
    
if __name__ == '__main__':
    main()

Solution (Python):

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

flg=True
for i in range(N-1):
    if W[i][-1]!=W[i+1][0]:
        flg=False
if len(W)!=len(set(W)):
    flg=False
print('Yes' if flg else 'No')

Solution (Python):
N=int(input())
L=[]
count=0
for i in range (N):
	L.append(input())
if len(set(L))!=N:
	print("No")
else:
	for i in range (N-1):
		if L[i][-1]!=L[i+1][0]:
			count+=1
	if count==0:
		print("Yes")
	else:
		print("No")

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

Solution (Python):
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)

Solution (Python):
n = int(input())
w = []
for _ in range(n):
    w.append(input())

ans = True
if len(set(w)) != len(w):
    print("No")
else:
    tmp = w[0][-1]
    for x in w[1:]:
        if tmp != x[0]:
            ans = False
            break
        else:
            tmp = x[-1]
    if ans:
        print("Yes")
    else:
        print("No")

Solution (Python):
N = int(input())

prev = None
flag = True
words = []
for i in range(N):
    w = input()
    if i != 0:
        if prev[-1] != w[0] or w in words:
            flag = False

    prev = w
    words.append(w)

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

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

if len(set(W))<N:
    print('No')
    exit()
    
for i in range(1,N):
    if W[i-1][-1]!=W[i][0]:
        print('No')
        exit()

print('Yes')

Solution (Python):
n = int(input())
W = list()
ans = "Yes"
for i in range(n):
    w = input()
    W.append(w)
for j in range(1,n):
    if W[j][0] != W[j-1][-1] or (W[j] in W[:j]):
        ans = "No"
print(ans)

Solution (Python):
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")

Solution (Python):
num_s, *D,  = [s.split() for s in open(0)]
flag = 0
D  = [d[0] for d in D]
pw = D[0]
if len(D) != len(set(D)):
    flag += 1
else:
    for i in range(1, len(D)):
        w = D[i]
        if pw[-1] != w[0]:
            flag += 1
            break 
        pw = w 
        
if flag:
    print("No")
else:
    print("Yes")

Solution (Python):
n = int(input())
w = []
correct = 0

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

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

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

print("Yes")

Solution (Python):
N=int(input())
w=[]
for _ in range(N):
  w_i=str(input())
  w.append(w_i)
for i in range(N):
  for j in range(i+1,N):
    if w[i]==w[j]:
      print("No")
      exit()
for i in range(N-1):
  p=w[i]
  q=w[i+1]
  if p[-1]!=q[0]:
    print("No")
    exit()
print("Yes")

Solution (Python):
n = int(input())
wl = list(input() for _ in range(n))

en = wl[0][-1]
flag = 0
word = [wl[0]]
for i in range(1, n):
    st = wl[i][0]
    if st == en and word.count(wl[i]) == 0:
        en = wl[i][-1]
        word.append(wl[i])
    else:
        flag = 1
        break

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

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

t = w[0]

for i in w:
    if w.count(i) >= 2:
        print("No")
        exit()

for j in range(1,len(w)):
    if w[j-1][-1] != w[j][0]:
        print("No")
        exit()
        

print("Yes")

Solution (Python):
N = int(input())
past = []
last = ""
Success = True
for i in range(N):
    W = input()
    
    
    
    if last == "":
        past.append(W)
        last = W
    elif W in past or W[0] != last[-1:]:
        Success = False
    else:
        past.append(W)
        last = W

if Success == True:
    print("Yes")
else:
    print("No")

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

Solution (Python):
N = int(input())
W = []
flag = 0
for i in range(N):
    tmp = input()
    if tmp in W:
        flag = 1
    W.append(tmp)

if flag:
    print("No")
    exit()
    
ans = "Yes"

for i in range(N):
    tmp = W[i]
    if i != 0:
        if tmp[0] != l:
            ans = "No"
            break
    l = tmp[-1]

print(ans)

Solution (Python):
N = int(input())

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

if len(words) == N:
    print('Yes')

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

g = set()
l = w[0][-1]
g.add(w[0])
for i in range(1, n):
    if w[i] in g or w[i][0] != l:
        print("No")
        break
    l = w[i][-1]
    g.add(w[i])
else:
    print("Yes")

Solution (Python):
n = int(input())
words = [0] * n
ans = 'Yes'
for i in range(n):
    words[i] = input()
    if i == 0:
        continue

    if words[i-1][-1] != words[i][0] or words[i] in words[:i]:
        ans = 'No'
print(ans)

Solution (Python):
n = int(input())
w_0 = input()
words = {w_0}
now = w_0[-1]
ans = "Yes"
for _ in range(n-1):
    w = input()
    if now == w[0] and not (w in words):
        now = w[-1]
        words.add(w)
    else:
        ans = "No"
        break

print(ans)

Solution (Python):
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
    elif w.count(w[i]) != 1:
        ans = "No"
        break
print(ans)

Solution (Python):
import sys

def main():
    N=int(input())
    W=[input() for i in range(0,N)]
    flag=0
    for i in range(0,N-1):
        if W[i][len(W[i])-1]!=W[i+1][0]:
            flag=1
            break
    memo=[]
    memo_append=memo.append
    for i in range(0,N):
        if W[i] in memo:
            flag=1
            break
        else:
            memo_append(W[i])
    if flag==0:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Solution (Python):
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial

sys.setrecursionlimit(10**7)
N = int(input())
W = [input() for _ in range(N)]

s = set()
s.add(W[0])
l = W[0][-1]

for w in W[1:]:
    if w in s:
        print('No')
        exit()

    if w[0] != l:
        print('No')
        exit()

    l = w[-1]
    s.add(w)

print('Yes')

Solution (Python):




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


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
a = [input() for i in range(N)]
ans = 'Yes'
for i in range(N-1): 
    if a[i][-1] != a[i+1][0]: 
        ans = 'No'
    if a.count(a[i]) > 1: 
        ans = 'No'
if a.count(a[N-1]) > 1:
        ans = 'No'
print(ans)

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

Solution (Python):
N = int(input())
s = input()
words = [s]
for _ in range(N-1):
    t = input()
    if not t in words:
        words.append(t)
    else:
        print("No")
        exit()
    if s[-1] != t[0]:
        print("No")
        exit()
    s = t
print("Yes")

Solution (Python):
import collections
n=int(input())
w=[]
for i in range(n):
    w.append(str(input()))

w_count=collections.Counter(w)
if max(w_count.values())>=2:
    print("No")
    exit()

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

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

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

Solution (Python):
N = int(input())
w = [input() for _ in range(N)]

fl = True
for i in range(1,N):
    if w.count(w[i])>1:
        fl = False
    if w[i-1][-1]==w[i][0]:
        continue
    else:
        fl = False
print('Yes') if fl else print('No')

Solution (Python):


def resolve():
    N=int(input())
    S=[input() for i in range(N)]
    if len(S)!=len(set(S)):
        print('No')
        return
    p=S[0]
    for i in S[1:]:
        if p[-1]!=i[0]:
            print("No")
            return
        p=i
    print('Yes')


if __name__ == "__main__":
    resolve()

Solution (Python):
N = int(input())
flg = False
w = input()
l = [w]
for i in range(1, N):
  w = input()
  if w not in l and w[0] == l[-1][-1]:
    l.append(w)
    flg = True
  else:
    flg = False
    break
if flg:
  print('Yes')
else:
  print('No')

Solution (Python):
N = int(input())

shiritori = []
shiritori.append(input())
for _ in range(N-1):
    w = input()
    if w in shiritori or shiritori[-1][-1] != w[0]:
        print("No")
        exit()
    shiritori.append(w)
print("Yes")

Solution (Python):
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')
		exit(0)
	else:
		pass
if len(set(w)) == len(w):
	print('Yes')
else:
	print('No')

Solution (Python):
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)

Solution (Python):
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")

Solution (Python):
import sys
input=sys.stdin.readline
n = int(input())
lis = []
lis.append(input()[:-1])
ans = 0
for i in range(n-1):
    word = input()[:-1]
    if word in lis:
        ans += 1
    if word[0] != lis[-1][-1]:
        ans += 2
    lis.append(word)
if ans == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
n = int(input())
lis = []
lis.append(input())
ans = 0
for i in range(n-1):
    word = input()
    if word in lis:
        ans += 1
    if word[0] != lis[-1][-1]:
        ans += 2
    lis.append(word)    
if ans == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
words = [input() for i in range(n)]
already = []
for i in range(n):
  word = words[i]
  if i==0:
    already.append(word)
    bottom = word[-1]
  else:
    top = word[0]
    if top != bottom or word in already:
      print("No")
      exit()
    bottom = word[-1]
    already.append(word)
print("Yes")

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

flag=1

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

Solution (Python):
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")

Solution (Python):
n = int(input())
w = list(input() for _ in range(n))
flg = False

for i in range(n-1):
    if(w[i][len(w[i])-1] == w[i+1][0]):
        cnt = 0
        for j in range(n):   
            if(w[j] == w[i]):
                cnt += 1
        if(cnt >= 2):
            flg = False
            break
        else:
            flg = True
    else:
        flg = False
        break
        
print("Yes" if flg else "No")

Solution (Python):
n = int(input())
ss = [input() for i in range(n)]

last = ""
a = set() 
check = True
for i in range(n):
  s = ss[i]
  if i == 0:
    last = s[len(s) - 1]
    a.add(s)
    continue

  if s in a:
    check = False
    break
  if last != s[0]:
    check = False
    break

  last = s[len(s) - 1]
  a.add(s)

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

Solution (Python):
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')

Solution (Python):
n=int(input())
W=[input() for _ in range(n)]
end=W[0][-1]
Flag=1
exp=[W[0]]
for w in W[1:]:
    start=w[0]
    if end!=start or w in exp:
        Flag=0
        break
    end=w[-1]
    exp.append(w)
print('Yes' if Flag==1 else 'No')

Solution (Python):
n = int(input())

st= set()
back=""
flg=True
for i in range(n):
    s=input()

    if i>0 and back!=s[0]:
        flg=False
    
    back=s[-1]
    st.add(s)

if flg and len(st)==n:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
words = []
for inp in range(N):
	words.append(input())

frst = words[0]
wrds = set(words)
if len(wrds) != len(words):
	print("No")
else:	
	for i in range(1,len(words)):
		flag = 1
		if words[i-1][-1] != words[i][0]:
			print("No")
			flag = 0
			break
	if flag == 1:
		print("Yes")

Solution (Python):


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