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):
import math
import copy
import sys

inputa = input().split()



a = int(inputa[0])









inputList = []
inputNumList = []
for i in range(a):
    inputNum = input().split()
    inputNumList = list(inputNum[0])
    inputList.append(inputNumList)






flg = True
for i in range(a):
    if i == 0:
        continue
    else:
        if inputList[i][0] != inputList[i-1][-1]:
            flg = False
            break

        for j in range(i):
            if "".join(inputList[i]) == "".join(inputList[j]):
                flg = False
                break

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

Solution (Python):



import sys

def input():
    return sys.stdin.readline().rstrip()

N = int(input())
a = []
tmp, head, tail = "", "", ""

for i in range(N):
    tmp = input()
    if tmp in a:
        print("No")
        exit()
    else:
        a.append(tmp)
        if i != 0:
            tail = (a[i-1])[-1]
            head = (a[i])[0]
            if tail != head:
                print("No")
                exit()
else:
    print("Yes")

Solution (Python):
n = int(input())
w = [input() for i in range(n)]
for i in w:
    if w.count(i) > 1:
        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_lis = []
ans = "Yes"
for i in range(n):
    w = input()
    if i == 0:
        w_lis.append(w)
    elif w in w_lis:
        ans = "No"
        break
    elif w not in w_lis and w[0] != w_lis[i-1][-1]:
        ans = "No"
        break
    else:
        w_lis.append(w)
print(ans)

Solution (Python):
N = int(input())
w = list(input())
fin = w[-1]
lst = [w]
for i in range(N-1):
    w = list(input())
    head = w[0]
    if  w[0] != fin or w in lst:
      print("No")
      exit()
    else:
      fin = w[-1]
      lst.append(w)
print("Yes")

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

hantei = 0

for i in range(N):
    for j in range(i+1,N):
        if W[i] == W[j]:
            hantei = 1
            break

for j in range(N-1):
    if W[j][-1] != W[j+1][0]:
        hantei = 1
        break

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

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

Solution (Python):
n = int(input())
w = []
for i in range(n):
    w.append(input())
if len(list(set(w))) != len(w):
    print('No')
    exit()
else:
    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 = [input() for i in range(n)]
for i in w:
  if w.count(i) > 1:
    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())

used_word = []
ans = "Yes"


for i in range(N):
  word = input()
  
  if i == 0:
    used_word.append(word)
  elif i >= 1:  
    if word in used_word:
      ans = "No"
    elif word[0] != used_word[-1][-1]:
      ans = "No"
    else:
      used_word.append(word)
      continue

print(ans)

Solution (Python):
import sys
input=sys.stdin.readline

n = int(input())
a = []
for i in range(n):
    s = input().strip()
    if len(a) > 0:
        if s in a:
            print("No")
            exit()
        elif a[-1][-1] == s[0]:
            a.append(s)
        else:
            print("No")
            exit()
    else:
        a.append(s)
        
print("Yes")

Solution (Python):
n=int(input())
s=input()
a=[]
last=s[-1]
a.append(s)

for i in range(n-1):
  s=input()
  a.append(s)
  if s[0]!=last:
    print('No')
    break
  last=s[-1]
  if i==n-2 and len(a)==len(set(a)):
    print('Yes')
  elif i==n-2:
    print('No')

Solution (Python):
n = int(input())
w = []
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")
            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 = [input() for _ in range(n)]

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

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

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  

def solve(N: int, W: "List[str]"):
    already_spoken = []
    flag = True
    for i, w in enumerate(W):
        if w in already_spoken:
            flag = False
        if i > 0:
            if not W[i-1][-1] == W[i][0]:
                flag = False
        already_spoken.append(w)
    if flag == True:
        print(YES)
    else:
        print(NO)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    W = [ next(tokens) for _ in range(N) ]  
    solve(N, W)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
n = int(input())
w = [input() for i in range(n)]
se = set()
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        break
    else:
        se.add(w[i])
        se.add(w[i+1])
print('Yes') if len(se) == n else print('No')

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

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

if len(w)!=len(set(w)):
    end()

for i in range(n-1):
    if w[i][-1]!=w[i+1][0]:
        end()

print("Yes")

Solution (Python):

import sys
n = int(input())
w = input()
www = [w]
for i in range(n-1):
  w = input()
  if not www[-1][-1] == w[0]:
    print("No")
    sys.exit()
  if w in www:
    print("No")
    sys.exit()
  www.append(w)
print("Yes")

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

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

print('Yes')

Solution (Python):
import collections

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


def same_word_check(s):
    c = collections.Counter(s)
    l = sorted(list(c.values()), reverse=True)
    if l[0] >= 2:
        print('No')
        exit()


def shiritori_rule(s):
    for i in range(len(s)-1):
        if s[i][-1] != s[i+1][0]:
            print('No')
            exit()

same_word_check(s)
shiritori_rule(s)
print('Yes')

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

Solution (Python):
def resolve():
    n = int(input())
    W = list(input() for _ in range(n))
    f = False
    if n==len(set(W)):
        if all(W[i][0] == W[i-1][-1] for i in range(1,len(W))):
            f = True
    print('Yes') if f else print('No')
resolve()

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

Solution (Python):
n = int(input())
yje = [input()]
for i in range(1,n):
    now = input()
    if now in yje:
        print('No')
        break
    if yje[-1][-1] != now[0]:
        print('No')
        break
    yje.append(now)
else:
    print('Yes')

Solution (Python):
n = int(input())
w = [input() for _ in range(n)]
ng = []
last = ""
for i in range(n):
    if i != 0:
        if w[i] not in ng:
            word = w[i]
            if word[0] == last:
                last = word[len(word)-1]
                ng.append(word)
            else:
                print("No")
                exit()
        else:
            print("No")
            exit()
    else:
        word = w[i]
        last = word[len(word) - 1]
        ng.append(word)
print("Yes")

Solution (Python):
N=int(input())
word_list=[]

ans="Yes"
for i in range(N):
  word=input()
  if word in word_list:
    ans="No"
    break
  else:
    word_list.append(word)
    if i>=1:
      if word_list[i-1][len(word_list[i-1])-1]!=word[0]:
        ans="No"
        break
      else:
        continue

print(ans)

Solution (Python):
N = int(input())
W = list(input() for i in range(N))
f = True

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

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter

def main():
	n = int(input().strip())
	v = [0] * n
	for i in range(n):
		v[i] = input().strip()
	if len(set(v)) != n:
		print('No')
		return
	for i in range(n-1):
		if v[i][-1] != v[i+1][0]:
			print('No')
			return
	print('Yes')

if __name__ == '__main__':
	main()

Solution (Python):
n = int(input())
yje = [input()]
for i in range(1,n):
  now = input()
  if now in yje:
    print('No')
    break
  if yje[-1][-1] != now[0]:
    print('No')
    break
  yje.append(now)
else:
  print('Yes')

Solution (Python):
stocker = []

N = int(input())
pastwd = input()
stocker.append(pastwd)

for i in range(1,N):
  curwd = input()
  if (pastwd[-1] != curwd[0]) or curwd in stocker:
    print("No")
    exit()
  stocker.append(curwd)
  pastwd = curwd

print("Yes")

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

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

pw =[]
no  = False
for i in range(n):
    if i == 0:
        wi = input()
        pw.append(wi)
    else:
        w = input()
        if wi[-1]!=w[0] or (w in pw):
            no = True
        pw.append(w)
        wi = w

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

Solution (Python):
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    W = inputs
    appeared = set()
    prev = ''
    for w in W:
        if w in appeared:
            return "No"
        appeared.add(w)
        if not (prev == '' or w[0] == prev):
            return "No"
        prev = w[-1]
    return "Yes"


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

Solution (Python):
def check(w1,w2):
  return w1[-1] == w2[0]

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

if len(set(w)) < n:
  print('No')
  exit()
for i in range(n-1):
  if not check(w[i],w[i+1]):
    print('No')
    exit()
print('Yes')

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

Solution (Python):
n = int(input())
word = []
for i in range(n):
  word.append(input())
  
  
s_word = set(word)
ans = 'No' 
siri = word[0][-1]
s_size = len(s_word)
w_size = len(word)
del word[0]

if s_size == w_size:
  for i in word:
    if siri == i[0]:
      ans = 'Yes'
      siri = i[-1]
    else:
      ans = 'No'
      break
      
print(ans)

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

li = [input() for _ in range(n)]

s = list(set(li))

if n != len(s):
    print("No")
    exit()
    
for i in range(n):
    t = li[i][-1]
    try:
        u = li[i+1][0]
        if t != u:
            print("No")
            break
    except:
        pass
else:
    print("Yes")

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

Solution (Python):
N = int(input())
W = []

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

for i in range(1,N):

    for j in W[:i]:
        if j == W[i]:
            print('No')
            exit()


    if W[i-1][-1] != W[i][0]:
        print('No')
        exit()

print('Yes')

Solution (Python):
ans = "Yes"
l = []
N = int(input())
for _ in range(N):
  w = input()
  l.append(w)
for i in range(N-1):
  if l[i+1][0] != l[i][-1]:
    ans = "No"
  for j in range(i):
    if l[j] == l[i+1]:
      ans = "No"
print(ans)

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

lst = [input() for i in range(N)]

lst2 = []
lst2.append(lst[0])
ans = "Yes"
for i in range(1, N):
	if (lst[i] in lst2 or lst[i-1][-1] != lst[i][0]):
		ans = "No"
		break
	else:
		lst2.append(lst[i])

print(ans)

Solution (Python):


def main():

    N = int(input())
    past=[]
    past.append(input())

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

    print('Yes')


        
    
if __name__== "__main__":
    main()

Solution (Python):
import collections

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

c = collections.Counter(ls)

count = 0
if c.most_common()[0][1] >= 2:
    print("No")
else:
    for i in range(len(ls)-1):
        if ls[i][-1] == ls[i+1][0]:
            count += 1
    if count == len(ls)-1:
        print("Yes")
    else:
        print("No")

Solution (Python):
words = lambda t : list(map(t, input().split()))
n = int(input())
a = set()
c = "
ans = True
for _ in range(n):
    s = input()
    if (c != "
        ans = False
        break
    a.add(s)
    c = s[-1]
if ans:
    print("Yes")
else:
    print("No")

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

result = 'Yes'
used = []
last_char = ''
for word in words:
    if not used:
        used.append(word)
        last_char = word[-1]
        continue
    if word[0] != last_char or word in used:
        result = 'No'
        break
    used.append(word)
    last_char = word[-1]

print(result)

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

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

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

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

Solution (Python):
n = int(input())
err = False
word_list = []
for i in range(n):
    s = input()
    if i == 0:
        last_letter = s[-1]
        word_list.append(s)
        continue
    if s in word_list:
        err = True
    else:
        if last_letter != s[0]:
            err = True
        else:
            last_letter = s[-1]
            word_list.append(s)
if err:
    print("No")
else:
    print("Yes")

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

Solution (Python):

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

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

if len(set(w)) != len(w):
    ok = False

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

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

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

Solution (Python):
N = int(input())
S = [0] * N 
check = 0
for i in range(N):
    S[i] = input()


A = list(set(S))
if len(A) == len(S):
    pass
else:
    check = 1

for i in range(1, N):
    if S[i][0] == S[i-1][-1]:
        pass
    else:
        check = 1

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

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

ans = 1
s = w[0][-1]
for x in w[1:]:
    if x[0] == s:
        s = x[-1]
    else:
        ans = 0
        break

import collections
c = collections.Counter(w)
if c.most_common()[0][1] > 1:
    ans = 0

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

Solution (Python):
n=int(input())
a = set()
pi = ""
no = 0
for i in range(n):
    x = input()
    a.add(x)
    if i > 0 and pi[-1] != x[0]:
        no = 1
    pi = x
if n != len(a):
    no = 1
print(('Yes','No')[no])

Solution (Python):
def main28():
    num = int(input())
    st = []
    for i in range(num):
        st.append(input())
    for i in range(1,num,1):
        if st[i-1][-1] != st[i][0]:
            print("No")
            return
        for j in range(i):
            if st[j] == st[i]:
                print("No")
                return
    print("Yes")

if __name__ == "__main__":
    main28()

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

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

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

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


ans2=set(ans)


if len(ans2)!=n:
    print("No")
    exit()

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

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

if len(a) != len(set(a)):
    print("No")
else:
    for i in range(N-1):
        aa = a[i]
        bb = a[i+1]
        if aa[-1] != bb[0]:
            print("No")
            break
    else:
        print("Yes")

Solution (Python):
n=int(input())
a=input()
b=a[len(a)-1]
word1=[a]
word2=[b]
c=0

for i in range(n-1):
    aa=input()
    bb=aa[0]
    if aa not in word1 and word2[i]==bb:
        word1.append(aa)
        top=aa[len(aa)-1]
        word2.append(top)
    else:
        c=1
        break
        
print("Yes" if c==0 else "No")

Solution (Python):
N = int(input())
W1 = input()
past = set()
past.add(W1)
last = W1[-1]
ans = 'Yes'
for _ in range(N - 1):
    W = input()
    if W in past or not W.startswith(last):
        ans = 'No'
    else:
        past.add(W)
        last = W[-1]
print(ans)

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

ans = True
li = [input() for _ in range(n)]

said =[li[0]]
for i in range(1, n):
    if li[i] in said or li[i-1][-1] != li[i][0]:
        print("No")
        break
    else:
        said.append(li[i])
else:
    print("Yes")

Solution (Python):
n = int(input())
word = input()
words = [word]
for _ in range(n-1):
  word = input()
  if word in words or not word.startswith(words[-1][-1]):
    print('No')
    exit()
  words.append(word)
print('Yes')

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

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

print('Yes')

Solution (Python):
n=int(input())
w=[input() for i in range(n)]
a=0
for i in range(1,n):  
  if w[i-1][-1] == w[i][0]:
    if w[i] not in w[:i]:
      a=a
    else:
      a+=1
  else:
    a+=1
if a==0:print("Yes")
else:print("No")

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

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

vocab = {W[0]}
for i in range(1, N):
    if W[i] in vocab:
        print("No")
        exit()
    vocab.add(W[i])

    if W[i-1][-1] != W[i][0]:
        print("No")
        exit()
print("Yes")

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

pre = W[0][0]
ok = True
for w in W:
    if w[0] != pre[-1] or w in checked:
        ok = False
        break
    pre = w
    checked.append(w)

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

Solution (Python):
import sys

N = int(input())
WLst = [0] * N

for i in range(N):
    WLst[i] = input()

if WLst.count(WLst[0]) != 1:
    print('No')
    sys.exit()

for i in range(1, N):
    if WLst[i - 1][-1] != WLst[i][0]:
        print('No')
        sys.exit()
    if WLst.count(WLst[i]) != 1:
        print('No')
        sys.exit()

print('Yes')

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b = LI()
    if (a * b) % 2:
        print("Yes")
    else:
        print("No")
    return


def B():
    n = II()
    w = SR(n)
    d = []
    for i in w:
        d.append("".join(i))
    if len(set(d)) != n:
        print("No")
        return
    for i in range(n - 1):
        if w[i][-1] != w[i + 1][0]:
            print("No")
            return
    print("Yes")
    return


def C():
    return


def D():
    return


if __name__ == '__main__':
    B()

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

c = 0
for j in range(N-1):
    if W.count(W[j+1]) == 1:
        if W[j+1][0] == W[j][-1]:
            c += 1

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

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

past = []
flag = 0
for i in range(n):
    if i == 0:
        past.append(w[i])
    else:
        if w[i] in past:
            flag = 1
            break
        else:
            if w[i-1][-1] == w[i][0]:
                past.append(w[i])
            else:
                flag = 1
                break
if flag == 1:
    print("No")
else:
    print("Yes")

Solution (Python):
N = int(input())
before = ''
words = []
ans = 'Yes'
for idx in range(N):
  word = input()
  if idx == 0:
    before = word[0]
  if word in words or word[0] != before[-1]:
    ans = 'No'
    break
  words.append(word)
  before = word
print(ans)

Solution (Python):
N = int(input())
wordlist = [input()]
ans = 'Yes'
for i in range(1, N):
	newW = input()
	if wordlist[-1][-1] != newW[0] or newW in wordlist:
		ans = 'No'
		break
	wordlist.append(newW)
print(ans)

Solution (Python):
N = int(input())
s = input()
memo = {s:1}
flag = True
for i in range(N-1):
  t = input()
  if s[-1] != t[0]:
    flag = False
  if t not in memo:
    memo[t] = 1
  else:
    flag = False
  s = t
print('Yes' if flag else 'No')

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

res='Yes'

su=set(s)
if len(su)<n:
	res='No'


    
for i in range(n-1):
	f=s[i][len(s[i])-1]
	
	b=s[i+1][0]
	
	if f!=b:
		
		res='No'
		break

print(res)

Solution (Python):
n = int(input())
w = []
st = set()
for i in range(n):
    s = input()
    st.add(s)
    w.append(s[0] + s[-1])
if len(st) != n:
    print('No')
    exit()
for i,j in zip(w, w[1:]):
    if i[-1] != j[0]:
        print('No')
        exit()
print('Yes')

Solution (Python):
n = int(input())
ws = []
flag = 0
for i in range(n):
  w = input()
  if ws != []:
    if w in ws:
      print("No")
      flag = 1
      break
    elif ws[-1][-1] != w[0]:
      print("No")
      flag = 1
      break
    else:
      ws.append(w)
  else:
    ws.append(w)

if flag == 0:
  print("Yes")

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

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

    if W[i][-1]!=W[i+1][0]:
        print('No')
        exit()

print('Yes')

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

Solution (Python):
n = int(input())
lst = []
for i in range(n):
  x = input()
  if i==0:
    lst.append(x)
    continue
  else:
    if (x not in lst)&(str(lst[i-1])[-1:] == x[0]):
      lst.append(x)
      continue
    else:
      print("No")
      quit()
print("Yes")

Solution (Python):
a = int(input())
b = []
for i in range(a):
    c = input()
    if len(b) == 0:
        b.append(c)
    else:
        d = b[i-1]
        if c not in b and d[-1] == c[0]:
            b.append(c)
        else:
            print("No")
            exit()
print("Yes")

Solution (Python):
from collections import Counter
n = int(input())
ws = [input() for i in range(n)]
if len(Counter(ws)) < len(ws):
    print("No")
    exit(0)

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

Solution (Python):


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


used = []

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

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

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

    c = ""
    for w in W:
        if W.count(w) > 1:
            return False

    for w in W:
        cc = w[len(w) - 1]
        if c == "" or c == w[0]:
            c = cc
        else:
            return False
    
    return True

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

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

Solution (Python):
N = int(input())
Ws = []
for x in range(100):
  Ws.append(str(input()))
  if x+1 == N:
    break

words = [Ws[0]]
tmp = list(Ws[0])[-1]
Ws.remove(Ws[0])

for y in Ws:
  if y in words:
    print('No')
    break
  elif tmp == list(y)[0]:
    words.append(y)
    tmp = list(y)[-1]
  else:
    print('No')
    break

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    W = [str(input()) for _ in range(N)]

    mem = set([W[0]])

    answer = 'Yes'
    for i in range(1, N):
        if len(mem & set([W[i]])) == 0 and W[i-1][-1::] == W[i][0:1:]:
            mem.add(W[i])
        else:
            
            
            
            
            
            
            
            answer = 'No'
            break
    print(answer)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    W = [str(input()) for _ in range(N)]

    mem = set([W[0]])

    answer = 'Yes'
    for i in range(1, N):
        if len(mem & set([W[i]])) == 0 and W[i-1][-1::] == W[i][0:1:]:
            mem.add(W[i])
        else:
            
            
            
            
            
            
            
            answer = 'No'
            break
    print(answer)

Solution (Python):
n=int(input())
w=[input() for i in range(n)]
a=0
for i in range(1,n):  
  if w[i-1][-1] == w[i][0]:
    if w[i] not in w[:i]:
      a=a
    else:
      a+=1
  else:
    a+=1
if a==0:print("Yes")
else:print("No")

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

Solution (Python):



import sys

input = sys.stdin.readline

def main():
    N = int(input())
    W = [input().strip() for _ in range(N)]
    m = {}
    for i in range(N-1):
        if W[i][-1] != W[i+1][0] or W[i+1] in m:
            print("No")
            return
        m[W[i]] = True
    print("Yes")

main()

Solution (Python):
a = int(input())
b = list(input() for i in range(a))
c = set(b)
d = 0

if len(c)!=a:
  print("No")
else:
  for i in range(a-1):
    if b[i][-1]!=b[i+1][0]:
      d = 1
  else:
    if d==0:
      print("Yes")
    else:
      print("No")

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

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

Solution (Python):



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

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

Solution (Python):
N = int(input())
word_set = set()
valid = True
words = ["" for i in range(N)]
for i in range(N):
    words[i] = input()

word_set.add(words[0])
for i in range(1, N):
    if words[i-1][-1] != words[i][0] or words[i] in word_set:
        valid = False
        break
    word_set.add(words[i])
    
if valid:
    print("Yes")
else:
    print("No")