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())
W=[]

S=set()
for i in range(N):
    w=input()
    W.append(w)

last=W[0][-1]
S.add(W[0])

for i in range(1,N):
    if W[i][0]==last and not W[i] in S:
        pass
    else:
        print("No")
        exit()
    S.add(W[i])
    last=W[i][-1] 
print("Yes")

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

words.append(input())

for _ in range(N-1):
    w = input()
    if w not in words and words[-1][-1] == w[0]:
        words.append(w)
    else:
        flag = False
        break

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

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

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

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
W = []
for k in range(N):
    w = stdin.readline().rstrip()
    if k >= 1:
        if w[0] != W[k - 1][len(W[k - 1]) - 1] or len([x for x in W if x == w]) > 0:
            print('No')
            break
    W.append(w)
if len(W) == N:
    print('Yes')

Solution (Python):
n = int(input())
a = []
re = "Yes"
for i in range(n):
        a.append(input())
        if a.count(a[i]) >= 2:
                re = "No"
        if i != 0:
                if a[i][0] != a[i-1][-1]:
                        re ="No"

print(re)

Solution (Python):
N = int(input())
W = []
for i in range (0,N):
    W.append(input())
ans = "Yes"
d = dict()
count = 0
for j in W:
    if j in d.keys():
        ans = "No"
    else:
        d[j] = 1
    if count != 0:
        if j[0] != W[count - 1][-1]:
            ans = "No"
    count += 1
print(ans)

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

D = set()
ls = W[0][-1]
D.add(W[0])
for i in range(1, n):
    if ls == W[i][0] and not W[i] in D:
        D.add(W[i])
        ls = W[i][-1]
    else:
        print("No")
        exit()
print("Yes")

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

Solution (Python):
N = int(input())
said = [input()]
prev = said[0][-1]
for _ in range(N - 1):
  s = input()
  if s in said or prev != s[0]:
    print('No')
    break
  prev = s[-1]
  said.append(s)
else:
  print('Yes')

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  

def solve(N: int, W: "List[str]"):
    if len(W) != len(set(W)):
        print(NO)
        return

    for i in range(1,N):
        if W[i-1][-1] != W[i][0]:
            print(NO)
            return

    print(YES)

    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 i in range(N)]
s_W = list(set(W))

if len(W) != len(s_W):
    print('No')
    exit()

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

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

Solution (Python):
a = input()

def main():
    ed = []
    for i in range(int(a)):
        neww = input()
        if i != 0:
            if ed[i-1][-1] != neww[0] or neww in ed:
                return 'No'
        ed.append(neww)

    return 'Yes'
                

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

Solution (Python):
a = input()

def main():
    ed = []
    for i in range(int(a)):
        neww = input()
        if i != 0:
            if ed[i-1][-1] != neww[0] or neww in ed:
                return 'No'
        ed.append(neww)

    return 'Yes'
                

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

Solution (Python):
a = input()

def main():
    ed = []
    for i in range(int(a)):
        neww = input()
        if i != 0:
            if ed[i-1][-1] != neww[0] or neww in ed:
                return 'No'
        ed.append(neww)

    return 'Yes'
                

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

Solution (Python):
a = input()

def main():
    ed = []
    for i in range(int(a)):
        neww = input()
        if i != 0:
            if ed[i-1][-1] != neww[0] or neww in ed:
                return 'No'
        ed.append(neww)

    return 'Yes'
                

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

Solution (Python):
a = input()

def main():
    ed = []
    for i in range(int(a)):
        neww = input()
        if i != 0:
            if ed[i-1][-1] != neww[0] or neww in ed:
                return 'No'
        ed.append(neww)

    return 'Yes'
                

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

Solution (Python):
a = input()

def main():
    ed = []
    for i in range(int(a)):
        neww = input()
        if i != 0:
            if ed[i-1][-1] != neww[0] or neww in ed:
                return 'No'
        ed.append(neww)

    return 'Yes'
                

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

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


ans = 'Yes'
head = words[0][0]
memory = []
for w in words:
    if w[0] != head: 
        ans = 'No'
        break
    if w in memory:
        ans = 'No'
        break
    head = w[-1]
    memory.append(w)

print(ans)

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

l = [W[0]]

for i in range(1, N):
    if W[i - 1][-1] == W[i][0] and W[i] not in l:
        l.append(W[i])
    else:
        print("No")
        exit()

print("Yes")

Solution (Python):
n = int(input())
a = list([str(input())])

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

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

Solution (Python):
W = [w.strip() for w in open(0).readlines()[1:]]

judge = [(W.count(w) == 1) and (w[-1] == W[i+1][0]) for i, w in enumerate(W[:-1])]

print('No' if (False in judge) else 'Yes')

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

Solution (Python):
a = int(input())
b = []
for i in range(a):
  c = input()
  if i == 0:
    b.append(c)
  elif 1 <= i < a-1:
    if c[0] != b[-1][-1] or c in b:
      b.append(c)
      print("No")
      break
    else:
      b.append(c)
  elif i == a-1:
    if c[0] != b[-1][-1] or c in b:
      print("No")
    else:
      print("Yes")

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

word = input()
prev_char = word[-1]
word_set = set()
word_set.add(word)
flag = True
for i in range(N-1):
    word = input()
    if word in word_set or word[0] != prev_char:
        flag = False
        
    word_set.add(word)
    prev_char = word[-1]
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):

"""
B - Shiritori
https://atcoder.jp/contests/abc109/tasks/abc109_b

"""
import sys


def solve(words):
    seen = set()
    prev = words[0][0]
    for w in words:
        if w in seen or w[0] != prev[-1]:
            return 'No'
        prev = w
        seen.add(w)
    return 'Yes'


def main(args):
    N = int(input())
    words = [input() for _ in range(N)]
    ans = solve(words)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
import sys
n=int(input())
ws = set()
for _ in range(n):
    w = input()
    if w in ws:
        print('No')
        sys.exit()
    if ws and b != w[0]:
        print('No')
        sys.exit()
    ws.add(w)
    b = w[-1]
print('Yes')

Solution (Python):
n=int(input())
s_list=[]
shiritori_list=[]
for i in range(n):
  s=input()
  s_list.append(s)
  schar = list(s)
  schar_list=[]
  schar_list.append(schar[0])
  schar_list.append(schar[len(schar)-1])
  shiritori_list.append(schar_list)

unique_list=set(s_list)

if len(s_list) != len(unique_list):
  print('No')
else:
  judge='Yes'
  for j in range(n-1):
    if shiritori_list[j][1] != shiritori_list[j+1][0]:
      judge='No'
      break
  print(judge)

Solution (Python):
N = int(input())
A = []
cnt = []

for i in range(N):
    a = input()
    A.append(a)
for i in range(N):
    cnt.append(A.count(A[i]))
for i in range(N-1):
    if A[i][-1] == A[i+1][0]:
        cnt.append(1)
if cnt.count(1) == (N  + (N-1)):
    print('Yes')
else:
    print('No')

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

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

Solution (Python):
import sys

n = int(input())
words = []
word = ""
for i in range(n):
    word = input()
    
    if word in words:
        print("No")
        sys.exit(0)
    else:
        words.append(word)

for index, word in enumerate(words):
    if index == 0:
        continue
    if words[index - 1][-1] == list(word)[0]:
        continue
    else:
        print("No")
        sys.exit(0)
print("Yes")

Solution (Python):
N = int(input())
correct = True
past = [input()]
for n in range(N-1):
    w = input()
    if w[0] != past[-1][-1] or w in past:
        correct = False
        break
    past.append(w)

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

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

s = []
cnt = 0

for i in range(N) : 
    s.append(input())
    
for i in range(N) : 
    for j in range(N) : 
        if i != j : 
            if s[i] == s[j] : 
                cnt += 1
                
for i in range(0, N-1, 1) : 
    if s[i][-1] != s[i+1][0] : 
        cnt += 1
        
if cnt == 0 : 
    print("Yes")
else : 
    print("No")

Solution (Python):
N=int(input())
W=[0]*N
for i in range(N):
  W[i]=input()
for i in range(N-1):
  A=W[i]
  B=W[i+1]
  if A[-1]!=B[0]:
    print('No')
    exit()
  elif W.count(B)>=2:
    print('No')
    exit()
print('Yes')

Solution (Python):
N=int(input())
set=set()
bool=True
list = (list(input()for i in range(N)))
    
    
    
    
set.add(list[0])
for i in range(1,N):
    if list[i] in set or list[i-1][-1] != list[i][0]:
        bool=False
        break
    set.add(list[i])
print('Yes' if bool else 'No')

Solution (Python):
n = int(input())
w = [input() for i in range(n)]
ans = True
for j in range(n-1):
    if w[j][-1] != w[j+1][0]:
        ans = False
for k in range(n):
    for l in range(n):
        if l != k:
            if w[l] == w[k]:
                ans = False
        else:
            continue
if ans == True:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
words = []
flg = 0
for i in range(n):
    tmp_word = input()
    if tmp_word not in words:
        words.append(tmp_word)
    else:
        flg =1
        
if flg ==1:
    print("No")
else:
    for i in range(n-1):
        if words[i][-1] == words[i+1][0] and i < n-2:
            pass
        elif words[i][-1] == words[i+1][0] and i == n-2:
            print("Yes")
        else:
            print("No")
            break

Solution (Python):
n=int(input())
w=list(list(input()) for i in range(n))
f=True
c=0
for i in range(n):
    for j in range(n):
        if w[i]==w[j]:
            c+=1
    if (i!=n-1 and w[i+1][0]!=w[i][-1]) or c>n:
        f=False
if f:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
dic = [input()]
check = 0
for n in range(N-1):
    s = input()
    if s in dic:
        print('No')
        check = 1
        break
    else:
        if dic[-1][-1] == s[0]:
            dic.append(s)
        else:
            print('No')
            check = 1
            break
if check == 0:
    print('Yes')

Solution (Python):
n = int(input())
x = list(input() for i in range(n))
bw = 0
e = 'Yes'
for j in x:
    if bw == 0:
        bw = j
        if n != len(set(x)):
            e = 'No'
            break
    else:
        if bw[-1] != j[0]:
            e = 'No'
            break
        bw = j
print(e)

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

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

if __name__=='__main__':
    main()

Solution (Python):
n=int(input())
w=[input() for _ in range(n)]
l=w[0][-1]
said=set()
said.add(w[0])
f=True
for i in range(1,n):
    if w[i][0] == l:
        l=w[i][-1]
    else:
        f=False
        break
    if w[i] in said:
        f=False
        break
    said.add(w[i])
print('Yes' if f else 'No')

Solution (Python):

n = int(input())
first = input()
words = {first}
flag = False
for i in range(n-1):
    second = input()
    if first[-1] == second[0] and second not in words:
        words.add(second)
        first = second
    else:
        print("No")
        flag = True
        break
        
if not flag:
    print("Yes")

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

list=[]
for i in range(n):
  list.append(input())
  
import collections
c=collections.Counter(list)
t=0
for i in range(n-1):

  if list[i][len(list[i])-1]==list[i+1][0]:
    
    t += 1
  else:
    pass

if t == n-1 and len(c) == n:
  print("Yes")
else:
  print("No")

Solution (Python):


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

Solution (Python):
W = []
judge = True
a = ""
N = int(input())
for i in range(N):
    s = input()
    if i == 0:
        a = s[len(s)-1]
    else:
        if a != s[0] or s in W:
            judge = False
            break
        else:
            a = s[len(s)-1]
    W.append(s)
if judge:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
lst = []
ans = "Yes"

for i in range(N):
  tmp = input()
  lst.append(tmp)

for k in range(N):
  if lst.count(lst[k]) != 1:
    ans = "No"

if ans == "No":
  ans = "No"
else:
  for j in range(N-1):
    left = lst[j]
    right = lst[j+1]
    if left[-1:] == right[:1]:
      continue
    else:
      ans = "No"
      break
print(ans)

Solution (Python):
n=int(input())
a=input()
st=set()
st.add(a)
ans='Yes'
for i in range(n-1):
    s=input()
    st.add(s)
    if a[-1]!=s[0]:
        ans='No'
    a=s
if len(st)<n:
    ans='No'
print(ans)

Solution (Python):

from sys import stdin
import sys

N = int(stdin.readline().rstrip())
Ws = [ stdin.readline().rstrip() for _ in range(N) ]

def main():
    for i in range(1,len(Ws)):
        if Ws.count(Ws[i]) > 1 or Ws[i-1][-1:] != Ws[i][0:1] :
            print("No")
            sys.exit()
    print("Yes")
if __name__ == '__main__':
    main()

Solution (Python):
import sys

N = int(input())
W = [input() for _ 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())
W=[]
for i in range(N):
    w=input()
    W.append(w)
words=W.copy()
words=set(words)

for k in range(N-1):
    if W[k][-1]!=W[k+1][0]:
        print('No')
        break
    elif len(W)!=len(words):
        print('No')
        break
    else:
        continue
else:
    print('Yes')

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

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

Solution (Python):
N=int(input())
W=[input() for _ in range(N)]
flag=0
if N==len(set(W)):
  for i in range(N-1):
    if W[i][-1]!=W[i+1][0]:
      flag=1
      break
else:
  flag=1

print("YNeos"[flag==1::2])

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance





def main():
    n = intin()
    wlist = [input() for _ in range(n)]

    history = []
    prev = None
    for w in wlist:

        if w in history:
            print('No')
            return
        history.append(w)

        if prev is None:
            prev = w
            continue
        if w[0] != prev[-1]:
            print('No')
            return
        prev = w

    print('Yes')


if __name__ == '__main__':
    main()

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

W = [input() for n in range(N)]

flag = "Yes"

for n in range(1, N):
    if W[n][0] != W[n - 1][-1] or (W[n] in W[:n]):
        flag = "No"

print(flag)

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

flg = True
for i in range(N-1):
    Wi = input()
    if Wi in ws:
        flg = False
    elif ws[-1][-1] != Wi[0]:
        flg = False
    ws.append(Wi)

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

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

b = []
for i in range(N):
    a = str(input())
    if a in b:
        print ('No')
        sys.exit()
        b += [a]
    elif i != 0:
        if str(b[i-1])[-1] == a[0]:
            pass
        else:
            print ('No')
            sys.exit()
        b += [a]
    else:
        b += [a]
print ('Yes')

Solution (Python):
n = int(input())
s = [0]*n
for j in range(0,n):
    s[j] = input()
for j in range(0,n-1):
    if s[j][len(s[j])-1] != s[j+1][0]:
        print('No')
        break
    elif s.count(s[j]) >= 2:
        print('No')
        break
    elif j == n-2:
        print('Yes')

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

Solution (Python):
d = dict()

n = int(input())
w0 = input().strip()
d[w0] = True
c = w0[-1]

ok = True
for _ in range(n-1):
    w = input().strip()
    if w in d or w[0] != c:
        ok = False
        break

    d[w] = True
    c = w[-1]

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

Solution (Python):
N = int(input())
y = input()
W = [y]
cnt = False
for i in range(1,N):
  x = input()
  if x in W:
    cnt = True
  elif x[0]!=y[-1]:
    cnt = True
  W.append(x)
  y = x
print("Yes" if cnt==False else "No")

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
li = []
start = True
for i in range(N):
    w = input()
    if w in li:
        print('No')
        exit()

    li.append(w)
    if start:
        start = False
    else:
        if bef[-1] != w[0]:
            print('No')
            exit()
    bef = w

print('Yes')

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

if len(W) != len(set(W)):
    print('No')
else:
    for i in range(N - 1):
        b = W[i]
        f = W[i + 1]
        if b[-1] != f[0]:
            print('No')
            break
        else:
            if i == N - 2:
                print('Yes')

Solution (Python):
N=int(input())
W = [input() for i in range(N)]
words = set([W[0]])
for i in range(1, N):
    if W[i][0] != W[i-1][-1] or W[i] in words:
        print("No")
        exit()
    words.add(W[i])
print("Yes")

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

Solution (Python):

n = int(input())
visited = set()
ans = "Yes"
bef = ""
for i in range(n):
    c = str(input())
    if c in visited:
        ans = "No"
        break
    else:
        if i != 0:
            if c[0] != bef[-1]:
                ans = "No"
                break
    bef = c
    visited.add(c)
print(ans)

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

Solution (Python):
n=int(input())
List=list(input() for i in range(n))
for i in range(n-1):
      if List[i][-1]!=List[i+1][0]:
            x=1
            break
      else:
            x=0



print('Yes' if x==0 and len(list(set(List)))==len(List) else 'No')

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

wordset = set()
last= W[0][0]

for i in W:
    if last != i[0]:
        print("No")
        exit()
    else:
        wordset.add(i)
        last = i[-1]

print("Yes" if len(wordset) == N else "No")

Solution (Python):
import sys
n = int(input())
words = []
for i in range(n):
    w = input()
    if w in words:
        print('No')
        sys.exit()
    w_list = list(w)
    if i == 0:
        last = w_list[-1]
    elif i != 0 and i != n-1:
        start = w_list[0]
        if start != last:
            print('No')
            sys.exit()
        last  = w_list[-1]
    else:
        start = w_list[0]
        if start != last:
            print('No')
            sys.exit()
    words.append(w)
print('Yes')

Solution (Python):
n=int(input())
w=[input() for s in range(n)]
k=[w[0]]
D=0
for i in range(1,n):
 if w[i] in k or w[i-1][-1]!=w[i][0]:
  D+=1
 else:
  k.append(w[i])

if D>0:
 print("No")
else:
 print("Yes")

Solution (Python):
import sys
n = int(input())
s = set([])
last = str(input())
s.add(last)
for i in range(n-1):
    tmp = str(input())
    
    if not (last[len(last)-1] == tmp[0]):
        print('No')
        sys.exit()
    
    s.add(tmp)
    last = tmp

print('Yes') if len(s) == n else print('No')

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

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

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

tmp = 'a'
ans = 'Yes'
for i in range(N):
    word = list(W[i])
    if (i > 0) and  (word[0] != tmp):
        ans = 'No' 
    
    tmp = word[len(word)-1]

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

print(ans)

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

Solution (Python):

import sys

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

dic = [W[0]]
for word in W[1:]:
    if word in dic or word[0] != dic[-1][-1]:
        print('No')
        sys.exit()
    dic.append(word)

print('Yes')

Solution (Python):
N=int(input())
Check=[]
Key=True

for i in range(N):
    W=input()
    Check.append(W)
    W=list(W)
    if 0<i and W[0]!=tmp:
        Key=False
        break
    tmp=W[len(W)-1]
    
for i in Check:
    if 1<Check.count(i):
        Key=False
        break

if Key==True:
    print('Yes')
else:
    print('No')

Solution (Python):
def is_OK(W, N):
    w = {W[0]}
    for i in range(0, N-1):
        if (W[i][-1] != W[i+1][0]) or (W[i+1] in w):
            return 'No'
        else:
            w.add(W[i+1])
    return 'Yes'

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

print(is_OK(W, N))

Solution (Python):
N = int(input())
W = []
ans = True
for i in range(N):
    tmp = input()
    if tmp in W and i != 0:
        ans = False
    W.append(tmp)

if ans:
    last_word = W[0][-1]
    for i in range(1, N):
        if last_word != W[i][0]:
            ans = False
        last_word = W[i][-1]

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

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

Solution (Python):
n=int(input())
w=[]
for i in range(n):
    w.append(str(input()))
a=True
for i in range(n):
    if i ==0:
        a = a
    else:
        a = a and w[i][0]==w[i-1][-1] and w[i] not in w[:i]
if a:
    print("Yes")
else:
    print("No")

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

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

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

s = input()
ss = {s}

ans = True

for i in range(1, n):
  t = input()
  if t not in ss and s[-1] == t[0]:
    s = t
    ss.add(s)
  else:
    ans = False
    break
  
  
if ans:
  print("Yes")
else:
  print("No")

Solution (Python):
n = int(input())
lst = []
lst.append(input())
c = 0

for i in range(n-1):
    word = input()
    
    if word in lst:
        c=1

    if lst[-1][-1] == word[0]:
        lst.append(word)
    else:
        c=1   
  
if c==1:
    print('No')
else:
    print('Yes')

Solution (Python):
import sys
_ = input()
prev = [input().strip()]
for line in sys.stdin:
  word = line.strip()
  if prev[-1][-1] == word[0] and word not in prev:
    prev.append(word)
  else:
    print('No')
    exit()
print('Yes')

Solution (Python):

import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

YES = "Yes"  
NO = "No"  

def solve(N: int, W: "List[str]"):
    s = set([W[0]])
    for i in range(1, len(W)):
        if (W[i] in s) or (W[i-1][-1] != W[i][0]):
            return NO
        s.add(W[i])
    return YES


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) ]  
    result = solve(N, W)
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = []
judge = 0

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

B = set(A)

if len(B) != N:
    judge = 1

for i in range(N-1):
    C = list(A[i])
    D = list(A[i+1])
    if C[-1] != D[0]:
        judge = 1

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

Solution (Python):
a=int(input())
c="0"
d=2
e=[]
for i in range(a):
    b=input()
    if b[0]!=c[-1]:
        d-=1
    e.append(b)
    c=b
print(["No","Yes"][(len(set(e))==a) and d==1])