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):
a=[input() for _ in range(int(input()))]
if len(a) > len(set(a)):
    print("No")
elif all([s[0]==e[-1] for (s, e) in zip(a+["?"],["?"]+a)][1:-1]):
    print("Yes")
else:
    print("No")

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, W):
    for i in range(1, N):
        if W[i-1][-1] != W[i][0]:
            return 'No'

    if len(set(W)) != N:
        return 'No'
    return 'Yes'


def main():
    N = read_int()
    W = [read_str() for _ in range(N)]
    print(slv(N, W))


if __name__ == '__main__':
    main()

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

def is_unique(arr):
    return len(arr) == len(set(arr))

if is_unique(w):
    for i in w[1:]:
        if tmp[-1] == i[0]:
            count += 1
        else:
            break
        tmp = i

if len(w) == count:
    print("Yes")
else:
    print("No")

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

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

w = input()
p = w[-1]

l = {w}

ans = 'Yes'
for _ in range(n - 1):
    w = input()

    if p != w[0] or w in l:
        ans = 'No'

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

print(ans)

Solution (Python):


def shiritori(words):
    history = set()
    pre = None
    for cur in words:
        if cur in history:
            return False
        if pre and pre[-1] != cur[0]:
            return False
        history.add(cur)
        pre = cur
    return True

def main():
    n = int(input())
    words = []
    for _ in range(n):
        words.append(input().strip())
    if shiritori(words):
        print('Yes')
    else:
        print('No')

main()

Solution (Python):
n = int(input())
flag = 0
buf = input()
last = buf[-1]
S = {buf}

for i in range(n-1):
	buf = input()
	if(buf[0] != last or buf in S):
		flag = 1
	S.add(buf)
	last = buf[-1]
	
if(flag == 0):
	print("Yes")
else:
	print("No")

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

last = ""
ans = "Yes"

for i in range(n):
    s = input()
    if (last != "" and last != s[0]) or (s in log):
        ans = "No"
        break
    log.append(s)
    last = s[len(s) - 1]


print(ans)

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

def calc():
	used = [W[0]]
	for i in range(N - 1):
		if W[i + 1] in used:
			return False
		if W[i][-1] != W[i + 1][0]:
			return False
		used.append(W[i + 1])
	return True

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

Solution (Python):
import sys
import copy

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]
sall = lambda: sys.stdin.readlines()

def main():
    n = ni()
    ws = sall()
    ws = [w.rstrip() for w in ws]

    o = ws[0]
    s = set()
    s.add(o)
    for w in ws[1:]:
        if o[-1] != w[0] or w in s:
            print('No')
            return

        s.add(copy.copy(w))
        o = copy.copy(w)

    print('Yes')

main()

Solution (Python):
n = int(input())
le = [input() for j in range(0,n)]
f = [True]
for i in range(1,n):
    if le.count(le[i])>1:
        f[0]=False
        break
    if le[i][0]!=le[i-1][-1]:
        f[0]=False
        break

if f[0]==True:
    print('Yes')

if f[0]!=True:
    print('No')

Solution (Python):
wdlist=list()
N=int(input())
for i in range(N):
	wdlist.append(input())

winflag=True

for i in range(1,N):
	if(wdlist[i-1][-1]!=wdlist[i][0]):
		winflag=False
		break
	for j in range(i):
		if(wdlist[j]==wdlist[i]):
			winflag=False
			break
if(winflag==True):
	print ("Yes")
else:
	print("No")

Solution (Python):
N = int(input())
W = []
W.append(input())
for _ in range(N-1):
    new_W = input()
    if new_W in W:
        print("No")
        break
    if new_W[0] != W[-1][-1]:
        print("No")
        break
    W.append(new_W)
else:
    print("Yes")

Solution (Python):
n = int(raw_input())
ws = []
for i in range(n):
    ws.append(raw_input())

status = True
known = []

for i, w in enumerate(ws):
    if w in known:
        status = False
        break
    if w == "":
        status = False
        break
    if i !=0 and known[-1][-1] != w[0]:
        status = False
        break
    known.append(w)

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

Solution (Python):
a = int(input())
b = []
ppp = 0
for i in range(a):
	b.append(input())
	y = list(b[-1])
	s = y[0]
	e = y[-1]
	if i == 0:
		n = e
	else:
		for j in range(len(b)-1):
			if b[-1] == b[j]:
				ppp = 1
			if j == len(b)-2:
				yy = list(b[j])
				ss = yy[0]
				ee = yy[-1]
				if ee != s:
					ppp = 1
	if ppp == 1:
		break
if ppp == 1:
	print("No")
else:
	print("Yes")

Solution (Python):
import sys

N = int(input())

arr = []

arr.append(input())

for i in range(1,N):
    s = input()
    if s in arr:
        print("No")
        sys.exit()
    else:
        if arr[i-1][-1:] != s[0]:
            print("No")
            sys.exit()

        arr.append(s)

print("Yes")

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

Solution (Python):


n = int(input())
ws = [input() for _ in range(n)]
flg = True

if len(ws) == len(set(ws)):
    for i in range(1, n):
        if ws[i][0] != ws[i-1][-1]:
            flg = False
else:
    flg = False


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

Solution (Python):


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

words = set()

res = True
char = ''

for word in w:
    if word in words:
        res = False
        break
    if char != '' and word[:1] != char:
        res = False
        break
    words.add(word)
    char = word[-1:]


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

Solution (Python):
N=int(input())
word_list=[]
flag=0
for i in range(N):
    a=input()
    if a in word_list:
        flag=1
    word_list.append(a)
for i in range(N-1):
    if word_list[i][-1]!=word_list[i+1][0]:
        flag=1
        break
if flag==0:
    print("Yes")
else:
    print("No")

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


count = 0





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

W.sort()
for i in range(N - 1):
    if W[i] == W[i + 1]:
        count += 1
        break

if count != 0:
    print("No")

else:
    print("Yes")

Solution (Python):
N = int(input())
W_list = [input() for _ in range(N)]
appeared_words = set()

previous_word = W_list[0]
appeared_words.add(previous_word)
for word in W_list[1:]:
    if previous_word[-1] != word[0]:
        print("No")
        exit(0)
    elif word in appeared_words:
        print("No")
        exit(0)
    else:
        previous_word = word
        appeared_words.add(word)
else:
    print("Yes")

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

isOK = True
for i in range(N):
  word = input()
  if word in words:
    print("No")
    isOK = False
    break
  if len(words) > 0:
    if words[-1][-1] != word[0]:
      print("No")
      isOK = False
      break
  words += [word]


if isOK:
  print("Yes")

Solution (Python):
def main():
    n = int(input())
    xs = [input() for _ in range(n)]

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

def judge(xs):
    s = set()

    for x, y in zip(xs, xs[1:]):
        s.add(x)
        if y in s:
            return False
        if x[-1] != y[0]:
            return False

    return True

main()

Solution (Python):



    
def main(n, m):
    for i in range(n - 1):
        if m[i][-1] != m[i+1][0]:
            
            print('No')
            return
        
    if len(set(m)) != len(m):
        
        print('No')
        return

    print('Yes')
    
        
if __name__ == '__main__':
    try:
        n  = int(input().strip())
        moji = []
        for i in range(n):
            moji.append(str(input().strip()))
        main(n, moji)
    except EOFError:
        pass

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

Solution (Python):
if __name__=='__main__':
    N = int(input())
    WORDs = [input() for i in range(N)]
    for i in range(N-1):
        if not WORDs[i][-1] == WORDs[i+1][0]:
            print("No")
            break;
    else:
        if len(WORDs) == len(set(WORDs)):
            print("Yes")
        else:
            print("No")

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

Solution (Python):

N = int(input())
Wi = []

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


Wi_set = set(Wi)
if len(Wi) != len(Wi_set):
    print('No')
    exit()


tail = ""
for W in Wi:
    if tail != "":
        if tail != W[0]:
            print('No')
            exit()
    tail = W[-1]

print('Yes')

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

t = str(input())
t_old = t[-1]
cc = 0
word = [t]

for i in range(N-1):
  t = str(input())
  t_new = t[0]
  if t_new == t_old:
    if t in word:
      cc += 1
      break
    else:
      t_old = t[-1]
      word.append(t)
  else:
    cc +=1
    break

if cc == 0:
  print("Yes")
else:
  print("No")

Solution (Python):
N = int(input())
words = []
flag = 0

for i in range(N):
  word = input()
  if i != 0:
    if word in words:
      flag = 1
    if word[0] != words[i-1][-1]:
      flag = 1
      
  words.append(word)

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

Solution (Python):
n = int(raw_input())
a = []
for i in range(n):
  a.append(raw_input())
b = set(a)
c = len(b)
d = len(a)
ans = []
if c == d:
  for i in range(n-1):
    x = a[i]
    y = a[i+1]
    z = x[-1]
    w = y[0]
    if z == w:
      ans.append(1)
    else:
      ans.append(0)
  if ans.count(1)==n-1:
    print "Yes"
  else:
    print "No"
else:
  print "No"

Solution (Python):
n = int(input())
ls = [input()]
c = 'Yes'

for i in range(1,n) :
   a = input()
   if a in ls :
      c = 'No'
   elif ls[i-1][len(ls[i-1])-1] != a[0] :
      c = 'No'
   ls.append(a)

print(c)

Solution (Python):
import math
import sys




il = []
for line in sys.stdin:
    il.append(line.strip())

N = int(il[0])
il = il [1:]

def main():
    if N != len(set(il)):
        print("No")
        return
    temp_w = None
    for w in il:
        if temp_w != None:
            if temp_w[-1] != w[0]:
                print("No")
                return
        temp_w = w
    print("Yes")
main()

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

say = []

flag = True

pre = ""

for s in w:
    if pre != "" and pre != s[0]:
        flag = False

    if s in say:
        flag = False
    
    say.append(s)
    pre = s[-1]

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

Solution (Python):
n = int(input())
w_dic =	{}
for i in range(n):
    w = input()
    if w_dic.get(w, False):
        print('No')
        break
    if i != 0:
        if last_word != w[0]:
            print('No')
            break
    last_word = w[-1]
    w_dic[w] = True
    if i == n-1:
        print('Yes')

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

li = []
for i in range(N):
	li.append(input())

last_str = li[0][0]

if len(li) != len(list(set(li))):
	print("No")
else:
	for i in li:
		if i[0] != last_str:
			print("No")
			break
		else:
			last_str = i[-1]
	else:
		print("Yes")

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

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

if len(set(W)) != N:
    print("No")
else:
    bw = W[0]
    for w in W[1:]:
        if w[0] != bw[-1]:
            print("No")
            break
        bw = w
    else:
        print("Yes")

Solution (Python):
N = int(input())
w = []
duplication = 0
series = 1
for i in range(N):
    w.append(str(input()))
for i in range(1,N):
    if w[i-1][-1] != w[i][0]:
        series = 0
        break
for i in range(N-1):
    for j in range(i+1,N):
        if w[i] == w[j]:
            duplication = 1
            break
if duplication == 0 and series == 1:
    print("Yes")
else:
    print("No")

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

seen = []
before = ''
flag = True

for i in strli:
    if before != '':
        if before[-1] != i[0]:
            flag = False
    if i in seen:
        flag = False
    if not flag:
        break
    before = i
    seen.append(i)

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

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

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

flg=0

if len(W)!=len(set(W)):
    flg+=1

for i in range(len(W)-1):
    if W[i][-1]!=W[i+1][0]:
        flg+=1
        break

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

Solution (Python):
if __name__ == '__main__' :
    N = int(input())
    ws = []
    for i in range(0,N):
        ws.append(input())

    if len(ws) != len(set(ws)):
        print('No')
        exit()
        
    before = ws[0][0]
    for w in ws:
        if before != w[0]:
            print('No')
            exit()
        else:
            before = w[len(w)-1]
                  
    print('Yes')

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

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

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

print("Yes")

Solution (Python):
n = int(input())
w = {}
ans = "Yes"
for i in range(0,n):
    W = input()
    w[W] = w.get(W,0) + 1
    if i >= 1:
        if e != W[0]:
            ans = "No"
    if w[W] >= 2:
        ans = "No"
    e = W[-1]
print(ans)

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

for n in range(N-1):
  w = W[-1]
  W = input()
  if w != W[0] or W in Wlist:
    a = 0
    break
  else:
    Wlist.append(W)
    w = W[-1]
    a = 1

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

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

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

arr = [];
flag=0;
for i in range(n):
	arr.append(input())

for i in range(n):
	if i>0:

		j = i-1;

		if ( arr[i][0] == arr[i-1][-1] ):
			
			while( j >=0 ):

				if arr[i]==arr[j]:
					flag=1;
					break;
				j-=1;
			if flag==1:
				break;
		else:
			flag=1;
			break;


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

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

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

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

print("Yes")

Solution (Python):
N = int(input())
A = []
for i in range(N):
    A.append(input())
set_A = set(A)
if len(set_A) < N:
    print("No")
else:
    prev = A[0][-1]
    for i in range(1, N):
        if A[i][0] != prev:
            print("No")
            break
        else:
            prev = A[i][-1]
    else:
        print("Yes")

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

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][len(l[i])-1] != l[i+1][0]:
        print("No")
        break
else:
    print("Yes")

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

check = []
check.append(w[0])
for i in range(1, n, 1):
    if(w[i-1][-1] == w[i][0]):
        if((w[i] in check) == False):
            check.append(w[i])
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()

print("Yes")

Solution (Python):

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

ans = "Yes"

for i, Wi in enumerate(W):
    
    if W.count(Wi) > 1:
        ans = "No"
        break
    
    if i == 0:
        hdr = Wi[-1]
        continue
    
    if Wi[0] != hdr:
        ans = "No"
        break
    hdr = Wi[-1]

print(ans)

Solution (Python):

N = int(input())

ans = 1
w_set = set()
previous_word = ''
for i in range(N):
    w = str(input())
    if i != 0:
        if previous_word[-1] == w[0]:
            pass
        else:
            ans = 0
            break
    if w in w_set:
        ans = 0
        break
    previous_word = w
    w_set.add(w)

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

Solution (Python):
n = int(input())
first_word = input()
word_list = [first_word]
last_char = first_word[-1:]
flag = 0
for i in range(n-1):
    word = input()
    word_list.append(word)
    first_char = word[0]
    if first_char == last_char:
        last_char = word[-1:]
    else:
        flag = 1
        break;
if(flag):
    print("No")
else:
    if(n == len(list(set(word_list)))):
        print("Yes")
    else:
        print("No")

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

Solution (Python):
N=input()
A=[]
for i in range(N):
	x=raw_input()
	if x in A:
		print "No"
		quit()
	if i==0:
		A.append(x)
		last=x[-1]
	else:
		if last!=x[0]:
			print "No"
			quit()
		else:
			A.append(x)
			last=x[-1]
else:
	print "Yes"

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

w=[]
ans=0

for i in range(n):
    a=input()
    w.append(a)
    if i>0:
        if w[i][0]==w[i-1][-1]:
            ans+=1

li=list(set(w))
l=len(li)

if l==n and ans==n-1:
    print("Yes")
else:
    print("No")

Solution (Python):
import math
import sys

n = int(input())

words = list()

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


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

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

print("Yes")

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

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

c=[]
f=1
for i in range(len(s)):
    if i < len(s)-1:
        if s[i][-1:] != s[i+1][0]:
            print("No")
            f=0
            break
    if s[i] not in c:
        c.append(s[i])
    else:
        print("No")
        f=0
        break

if f:
    print("Yes")

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

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

Solution (Python):
def main():
    """
    はじめ、好きな単語を発言する
    以降、次の条件を満たす単語を発言することを繰り返す
        その単語はまだ発言していない単語である
        その単語の先頭の文字は直前に発言した単語の末尾の文字と一致する
    """
    N = int(input())
    W = [input() for _ in range(N)]

    ans = AC(N, W)
    print(ans)


def AC(N, W):
    for i, w in enumerate(W[1:]):
        if W.count(w) >= 2:
            return "No"

        if W[i][-1] != w[0]:
            return "No"

    return "Yes"


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [input() for i in range(n)]
for i in range(n):
    num  = a.count(a[i])
    if num > 1:
        print('No')
        exit()
for i in range(n-1):
    if a[i][-1] == a[i+1][0]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Solution (Python):
n = int(input())
words = [input() for _ in range(n)]
prev = words[0]
memory = []
ans = 'Yes'
for i,w in enumerate(words):
  if i == 0:
    memory.append(w)
    continue
  if prev[-1] != w[0]:
    ans = 'No'
    break
  prev = w
  if w in memory:
    ans = 'No'
    break
  memory.append(w)
print(ans)

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

say = []
word = input()
say.append(word)
ans = 'Yes'

for i in range(n-1):
    word = input()
    if word in say:
        ans = 'No'

    elif word[0] != say[-1][-1]:
        ans = 'No'

    else:
        say.append(word)

print(ans)

Solution (Python):
n = int(input())
w = [input() for i in range(n)]
w_set = set()
w_set.add(w[0])

ans = 'Yes'
for i in range(1, n):
    if w[i-1][-1] != w[i][0] or w[i] in w_set:
        ans = 'No'
        break
    w_set.add(w[i])

print(ans)

Solution (Python):
n = int(input())
pw = input()
wset = set()
wset.add(pw)
for _ in range(n - 1):
    w = input()
    if pw[-1] != w[0] or w in wset:
        print('No')
        exit()
    else:
        pw = w
        wset.add(w)
print('Yes')

Solution (Python):
n=int(input())
s=[]
for i in range(n):
    st=input()
    if st in s:
        print('No')
        exit()
    s.append(st)

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

Solution (Python):
def solve(N, list):
    d = set()
    for i, l in enumerate(list):
        if l in d:
            return "No"
        if i > 0 and l[0] != list[i - 1][-1]:
            return "No"
        d.add(l)
    return "Yes"


if __name__ == "__main__":
    l = input()
    N = int(l)
    list = [input() for _ in range(0, N)]
    print(solve(N, list))

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

dic = {}
ans = 'Yes'
last = ''
for _ in range(N):
    s = input()
    if last == s[0] or last == '':
        last = s[-1]
        pass
    else:
        ans = 'No'
        break
    if dic.get(s, 0) == 0:
        dic[s] = 1
    else:
        ans = 'No'
        break
print(ans)

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

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

w=[]

for i in range(n):
    s=input()
    w.append(s)
    
w2 = list(set(w))

f=1

if len(w)>len(w2):
   f=-1

pre = list(w[0])

for i in range(1, n):
   now = list(w[i])
   
   if not pre[len(pre)-1]==now[0]:
       f=-1
   pre = []
   pre = now
       
if f>0:
    print("Yes")
else:
    print("No")

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

Solution (Python):





words=[]
N=int(input())
ok=1
for i in range(N):
    s=input()
    if s in words:
        ok = 0

        break
    
    if i != 0 and words[-1][-1] != s[0]:
        ok=0

        break

    words.append(s)

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

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

judge = True
w = input()

word_list = [w]
count = 0

while judge and count < N-1:
    w = input()
    if w[0] == word_list[count][-1] and not(w in word_list):
        count += 1
        word_list.append(w)
    else:
        judge = False
        break

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

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

for i in range(N):
  w = input()
  words.append(w)
  
signal=1

for j in range(1,N):
  for k in range(j):
    if words[k]==words[j]:
      signal=0
  if words[j-1][-1]!=words[j][0]:
    signal=0
    
if signal==1:
  print('Yes')
else:
  print('No')

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

Solution (Python):
n =  int(raw_input())
dic = {}
flag = 0
lis = []
for i in xrange(n):
    s = raw_input()
    lis.append(s)
    if s in dic:
        flag = 1
    else:
        dic[s] = 1
for i in range(1, n):
    
    
    
    
    if lis[i][0:1] != lis[i-1][len(lis[i-1])-1:]:
        flag = 1
        break
if flag == 1:
    print "No"
else:
    print "Yes"

Solution (Python):
g=0
x=0
w=[input() for i in range(int(input()))]
if len(set(w))==len(w):
   n=w[0][::-1][0]
   for i in range(1,len(w)):
      if w[i][0]==n:
         n=w[i][::-1][0]
      else:break
      x=i
if x==len(w)-1:g=1

print(["No","Yes"][g])

Solution (Python):



def main():
    n = int(input())
    word = list()
    pre_word = input()
    word.append(pre_word)

    for i in range(n - 1):
        w = input()

        if w not in word:
            word.append(w)

            if pre_word[-1] != w[0]:
                print('No')
                exit()
        else:
            print('No')
            exit()

        pre_word = w

    print('Yes')


if __name__ == '__main__':
    main()

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

out = False
word1 = input()
words = [word1]
for i in range(n-1):
    next_w = input()
    if next_w in words:
        out = True
        break
    if next_w[0:1] != words[-1][-1]:
        out = True
        break
    words.append(next_w)
if out:
    print("No")
else:
    print("Yes")

Solution (Python):
N = int(input())
word = input()
W = [input() for i in range(N-1)]
used = set()
used.add(word)

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

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

dic = [input()]

flag = "Yes"

for i in range(0,N-1):
    k = input()
    if (k in dic) or (dic[-1][-1] is not k[0]):
        flag = "No"
        break
    else:
        dic.append(k)

print(flag)

Solution (Python):
import sys

N = int(input())

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

WW = set(W)

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

Solution (Python):
N = int(input())
words = []
prev = "hogehoge"


def check():
    for i in range(N):
        w = input()
        if (i != 0 and prev[-1] != w[0]) or (w in words):
            return "No"
        prev = w
        words.append(w)
    return "Yes"


print(check())

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

Solution (Python):
def run(n, w):
    for i in range(n-1):
        if w[i] in w[i+1:]:
            return 'No'
        if w[i][len(w[i])-1] != w[i+1][0]:
            return 'No'
    return 'Yes'


def main():
    n = int(input())
    w = []
    for i in range(n):
        w.append(input())
    print(run(n, w))


if __name__ == '__main__':
    main()

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

words = []

shiritori = True

first = input()
end = first[len(first)-1]
words.append(first)


for i in range(1,N):
    w = input()
    beg = w[0]
    if beg != end:
        shiritori = False
    if w in words:
        shiritori = False
    end = w[len(w)-1]
    words.append(w)

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

Solution (Python):
def main():
    N = int(input())
    W = []
    for i in range(N):
        W.append(input())
    
    alr = [W[0], ]
    for i in range(1, N):
        if W[i] in alr:
            return "No"
        elif W[i][0] != W[i-1][-1]:
            return "No"
        else:
            alr.append(W[i])
    return "Yes"

if __name__ == "__main__":
    print(main())

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

if len(l) != len(set(l)):
    print('No')
    exit()

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

print('Yes')

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

word=['a']*N
word[0]=input()




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

wordunique=list(set(word))

if len(wordunique)!=N:
  print('No')
  exit()

print('Yes')

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

Solution (Python):
n=int(input())
w=[input() for _ in range(n)]
setw = set(w)
if(len(setw)!=len(w)):
    print("No")
    exit()

endw=w[0][-1]
for ww in w[1:]:
    if(endw!=ww[0]):
        print("No")
        exit()
    endw=ww[-1]

print("Yes")

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

l = []
c = False
o = ""
for a in w:
    if a in l:
        print("No")
        exit()
    if c == False or o == a[0]:
        l.append(a)
        o = a[-1]
        c = True
    else:
        print("No")
        exit()

print("Yes")