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


def solve(words):
    word = words[0]
    uniq_words = {word: True}

    ans = "Yes"
    for key in range(1, len(words)):
        next_word = words[key]
        if next_word in uniq_words:
            ans = "No"
            break
        uniq_words[next_word] = True
        if word[-1] != next_word[0]:
            ans = "No"
            break
        word = next_word

    return ans

def main():
    n = int(input())
    words = []
    for i in range(n):
        words.append(input())

    ans = solve(words)
    print(ans)

main()

Solution (Python):
def main():
    N = int(input())
    words = [input() for _ in range(N)]
    past = [words[0]]
    for i in range(1, N):
        prev, now = words[i-1], words[i]
        if (now in past or prev[-1] != now[0]):
            print("No")
            return
        else:
            past.append(now)
    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
w = [input() for i in range(n)]
for i in range(len(w)):
	for j in range(i + 1, len(w)):
		if w[i] == w[j]:
			print('No')
			exit()

for i in range(len(w) - 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(1,N):
  w = input()
  if W[i-1][-1] != w[0] or w in W:
    print('No')
    break
  else:
    W.append(w)
if len(W)==N:
  print('Yes')

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

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

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

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

lastch = ''
answer = 'Yes'
words = []

for i in range(n):
    word = input()
    words.append(word)
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(words) != len(set(words)):
    answer = 'No'

print(answer)

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

lastch = ''
answer = 'Yes'
words = []
for i in range(n):
    word = list(input())
    words.append(''.join(word))
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(set(words)) != len(words):
    answer = 'No'

print(answer)

Solution (Python):


"""
Created on Mon Feb 11 05:38:56 2019

@author: shinjisu
"""



import math


def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def dmp(x):
    global debug
    if debug:
        print(x)


debug = True


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


def prob096():  
    X = getIntList()
    K = getInt()
    dmp((X, K))
    total = sum(X) - max(X) + max(X)*2**K
    return total


def prob097():  
    X = getInt()
    dmp(X)
    if X == 1:
        return 1
    for n in range(X, 0, -1):
        dmp(n)
        for b in range(2, int(math.sqrt(X))+1):
            a = n
            exp = True
            while a > 1:
                if a % b != 0:
                    exp = False
                    break
                a //= b
            if exp:
                break
        if exp:
            break
    return n


def prob098():  
    N = getInt()
    S = input()
    dmp((N, S))
    maxChCount = 0
    for i in range(1, N):
        before = S[:i]
        after = S[i:]
        dmp((before, after))
        chCount = 0
        for j in range(26):
            ch = chr(ord('a')+j)
            if ch in before and ch in after:
                chCount += 1
        maxChCount = max(maxChCount, chCount)
    return maxChCount


def prob099():  
    a, b = getIntList()
    height = 0
    for i in range(b-a+1):
        height += i
    height -= b
    return height


def prob103():  
    S = input()
    T = input()
    for i in range(len(S)):
        S = S[1:] + S[0]
        dmp(S)
        if S == T:
            return 'Yes'
    else:
        return 'No'


def prob110():  
    N, M, X, Y = getIntList()
    cX = getIntList()
    cY = getIntList()
    dmp((N, M, X, Y))
    dmp(cX)
    dmp(cY)
    NW = 'No War'
    WA = 'War'
    if Y <= X:
        return WA
    cX.sort()
    cY.sort()
    dmp(cX)
    dmp(cY)
    if cX[-1] < cY[0] and \
            X < cY[0] and \
            cX[-1] < Y:
        return NW
    else:
        return WA


def prob109():  
    N = getInt()
    W = []
    for i in range(N):
        W.append(input())
    dmp(W)
    ALPHABET = [chr(i+ord('a')) for i in range(26)]
    NO = 'No'
    dmp(ALPHABET)
    used = set([W[0]])
    for i in range(1, N):
        dmp(used)
        if W[i] in used:
            return NO
        used.add(W[i])
        if W[i-1][-1] != W[i][0]:
            return NO
    return 'Yes'


def prob100():  
    return 0


debug = False  
print(prob109())

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

if not len(W) == len(set(W)):
	print('No')
	exit()

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

Solution (Python):
N=int(input())
announced = []
announced.append(input())
judge = True
for i in range(N-1):
    word = input()
    if (announced[i])[len(announced[i])-1] == word[0] and word not in announced:announced.append(word)
    else:
        judge = False
        print("No")
        break
if (judge): print("Yes")

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

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

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

print("Yes")

Solution (Python):


import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline












N = int(input().rstrip())
str_s = [str(input().rstrip()) for _ in range(N)]

prev_s = [str_s[0]]
for i in range(1, N):
	if prev_s[i-1][-1] != str_s[i][0] or str_s[i] in prev_s:
		print("No")
		exit()
	else:
		prev_s.append(str_s[i])
print("Yes")

Solution (Python):


N = int(input())

words = {}
last_w = ""

for _ in range(N):
    w = input()
    if w in words:
        print("No")
        exit()
    else:
        if len(last_w) == 0 or last_w == w[0]:
            words[w] = True
            last_w = w[-1]
        else:
            print("No")
            exit()

print("Yes")

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

Solution (Python):
N = int(input())
prev = ''
dic = set()
for i in range(N):
    word = input()
    if word in dic:
        print("No")
        exit()
    else:
        dic.add(word)
        if i == 0:
            prev = word[-1]
            continue
        if prev != word[0]:
            print("No")
            exit()
        prev = word[-1]
print("Yes")

Solution (Python):
import sys
N = int(input())
string = []

false = 0
for i in range(N):
    string += input().split()
    if i ==0:
        ans = list(string[0])
    elif string[i] in string[:-1]:
        false += 1
    else:
        get = list(string[i])
        if get[0] == ans[-1]:
            ans = get
        else:
            false+=1
if false > 0:
    print("No")
else:
    print("Yes")

Solution (Python):
def main() -> None:
    N = int(input())
    say = [input() for _ in range(N)]
    if len(say) != len(list(set(say))):
        print("No")
        exit()
    else:
        for i in range(N-1):
            if say[i][-1] != say[i+1][0]:
                print("No")
                exit()
            else:
                continue
    print("Yes")


if __name__ == '__main__':
    main()

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

li_words = list()
for i in range(int_n):
    li_words.append(input())

ends = "".join([e[-1] for e in li_words[:-1]])
starts = "".join([s[0] for s in li_words[1:]])

if starts == ends and len(set(li_words)) == int_n:
    print("Yes")
else:
    print("No")

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

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

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

torf = True

if not is_unique(warray):
    torf = False

for i in range(len(warray) - 1):
    if warray[i][-1] != warray[i+1][0]:
        torf = False

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

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

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

li_uniq = list(set(w))
if len(li_uniq) != len(w):
    print('No')
    exit()

print('Yes')

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

words = dict()
for i in w:
	words[i] = words.get(i,0)+1

for i in words:
	if words[i]>1:
		print("No")
		exit(0)

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

print("Yes")

Solution (Python):
from sys import stdin
N=int(stdin.readline().rstrip())
a=[]
for i in range(N):
    a.append(input())
    
if len(set(a)) < N:
    print("No")
else:
    

  end=a[0][0]
  cnt=0
  for i in a:
      if end==i[0]:
          end=i[-1]
          cnt+=1
      else:
          print("No")
          break
  if cnt==N:
      print("Yes")

Solution (Python):
N = int(input())
W = [input() for _ in range(N)]
exist = []
for i, w in enumerate(W):
    if w in exist:
        print("No")
        exit()
    if i != 0 and W[i - 1][-1] != w[0]:
        print("No")
        exit()
    exist.append(w)
print("Yes")

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

if not len(w)==len(set(w)):
    print('No')
    import sys
    sys.exit()

for i in range(len(w)-1):
    if not w[i][-1]==w[i+1][0]:
        print('No')
        import sys
        sys.exit()
print('Yes')

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

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

Solution (Python):

n = int(input()) 
w = [str(input()) for i in range(n)]
output = 'Yes'

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

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

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

l = []

flg = True

for i in range(N):
    s = input()

    if (s in l):
        flg = False
        break

    num = len(l)

    if (num != 0 and l[num - 1][-1] != s[0]):
        flg = False
        break

    l.append(s)

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

Solution (Python):
N = int(input())
w = []
for i in range(N):
    w.append(input())
last_char = w[0][0]
Rule = True
for word in w:
    if last_char == word[0]:
        last_char = word[-1]
        continue
    else:
        Rule = False
        break
if Rule and len(w) == len(set(w)):
    print("Yes")
else:
    print("No")

Solution (Python):
def is_unique(seq):
    return len(seq) == len(set(seq))


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

first = w[0][-1]
result = "Yes"
if not is_unique(w):
    result = "No"
else:
    for i in range(1,len(w)):
        if not w[i][0] == first:
            result = "No"
            break
        first = w[i][-1]

print(result)

Solution (Python):
n=int(input())
hoge=[]
no=0

a=input()
hoge.append(a)
saigo=a[-1]

for i in range(n-1):
  a=input()
  hoge.append(a)
  if(hoge.count(a)>1):
    no=1
    break
  if(saigo==a[0]):
    saigo=a[-1]
  else:
    no=1
    break
  
if(no==0):
  print("Yes")
else:
  print("No")

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

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

Solution (Python):
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  W = [str(input().strip()) for _ in range(N)]
  
  if len(W) != len(set(W)):
    ans = 'No'
  else:
    ans = 'Yes'
    for i in range(N-1):
      a, b = W[i], W[i+1]
      if a[-1] != b[0]:
        ans = 'No'
        break
  
  print(ans)


if __name__ == '__main__':
  main()

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

Solution (Python):
n = int(input())
first = input()
record = list()
record.append(first)

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

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

  
print(ans)

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

Solution (Python):

"""
高橋くんは今日も1人でしりとりの練習をしています。

しりとりとは以下のルールで遊ばれるゲームです。

・はじめ、好きな単語を発言する
・以降、次の条件を満たす単語を発言することを繰り返す
　・その単語はまだ発言していない単語である
　・その単語の先頭の文字は直前に発言した単語の末尾の文字と一致する

高橋くんは、10秒間にできるだけ多くの単語を発言する練習をしています。
高橋くんが発言した単語の個数Nとi番目に発言した単語Wiが与えられるので、
どの発言もしりとりのルールを守っていたかを判定してください。
"""
def check(words):
    answer = "Yes"

    
    for i in range(0, len(words)):
        for j in range(i+1, len(words)):
            if(words[i] == words[j]):
                answer = "No"

    
    for i in range(0, len(words)-1):
        if(words[i][-1] != words[i+1][0]):
            answer = "No"

    return answer


def main(words):
    answer = check(words)
    print(answer)


if __name__ == "__main__":
    num = int(input())  
    str = [input() for i in range(0, num)]  
    main(str)

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

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

Solution (Python):
class Solver(object):
    def __init__(self):
        self.n = int(input())

    def solve(self):
        prev = input()
        self.words = set([prev])
        valid = True
        for _ in range(self.n-1):
            word = input()
            if valid:
                if word in self.words:
                    valid = False
                if word[0] != prev[-1]:
                    valid = False
                self.words.add(word)
                prev = word
        if valid:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    s = Solver()
    s.solve()

Solution (Python):
N = int(input())
word = []
flag = True
word.append(input())
for _ in range(N - 1):
    w = input()
    if w in word:
        flag = False
    elif word[-1][-1] != w[0]:
        flag = False
    else:
        word.append(w)

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

Solution (Python):
n = int(input())
w1 = input()
words = set([w1])
for _ in range(n-1):
    w2 = input()
    if (w2 in words) or (w2[0]!=w1[-1]):
        print("No")
        break
    else:
        words.add(w2)
        w1 = w2
else:
    print("Yes")

Solution (Python):
n = int(input())
w1 = input()
words = set([w1])
for _ in range(n-1):
    w2 = input()
    if w2 in words:
        print("No")
        break
    elif w2[0]!=w1[-1]:
        print("No")
        break
    else:
        words.add(w2)
        w1 = w2
else:
    print("Yes")

Solution (Python):
n = int(input())
w1 = input()
words = list([w1])
for _ in range(n-1):
    w2 = input()
    if w2 in words:
        print("No")
        break
    else:
        words.append(w2)
        if w2[0]!=w1[-1]:
            print("No")
            break
        else:
            w1 = w2
else:
    print("Yes")

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

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


for i,w in enumerate(ww[:-1]):
    if ww[i][-1] != ww[i+1][0] or ww.count(w)>1:
        print('No')
        
        break
else:
    print('Yes')

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

appeared = []
prev = input()
for i in range(N-1):
    appeared += [prev]
    S = input()
    if prev[-1] != S[0] or S in appeared:
        print('No')
        exit()
    prev = S
print('Yes')

Solution (Python):
n = int(input())
w = [ input() for i in range(n) ]
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        print("No")
        exit()
    elif w[i] in w[i+1:]:
        print("No")
        exit()

print("Yes")

Solution (Python):
import sys
n = int(input())
w_arr = []

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

if len(list(set(w_arr))) == len(w_arr):
    for i in range(n-1):
        if w_arr[i][-1] == w_arr[i+1][0]:
            continue
        else: 
            print("No")
            sys.exit()

else:
    print("No")
    sys.exit()

print("Yes")

Solution (Python):


















import collections
def inpl(): return list(map(int, input().split()))


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

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

Solution (Python):
siri = ''
N = int(input())
a = [input() for i in range(N)]
for i, temp in enumerate(a):
    if i == 0:
        if len(set(a)) != N:
            print('No')
            break
        siri = temp[-1]
        continue
    if siri != temp[0]:
        print('No')
        break
    siri = temp[-1]
else:
    print('Yes')

Solution (Python):
N= int(input())
W = list(input() for i in range(N))
ans = True
if len(set(W)) == len(W):
    l = W[0][-1]
    ans = True
    for i in range(len(W)-1):
        if W[i+1][0] == l:
            l = W[i+1][-1]
        else:
            ans = False
            break
    if ans == True:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

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

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

for i in range(1, len(lst)):
    if lst[i][0] != lst[i-1][-1]:
        print('No')
        break
    if lst[i] in lst[:i]:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
def main():
    N = input()
    data = []
    pW = raw_input()
    data.append(pW)
    for i in range(N-1):
        W = raw_input()
        if pW[-1] != W[0]:
            return 'No'
        if W in data:
            return 'No'
        data.append(W)
        pW = W
    return 'Yes'

print main()

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

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

Solution (Python):
import sys

n = int(input())
w_list = [input() for _ in range(n)]
for i in range(1, len(w_list)):
    if w_list[i - 1][-1] == w_list[i][0]:
        if not w_list[i] in w_list[0:i]:
            pass
        else:
            print("No")
            sys.exit(0)
    else:
        print("No")
        sys.exit(0)

print("Yes")

Solution (Python):
N=int(input())
w=[input() for i in range(N)]
rule = 'Yes'
same = False
for x in range(1, N):
    rule='Yes'
    same = False
    if w[x-1][len(w[x-1])-1] != w[x][0]:
       rule = 'No'
       break
    for y in range(x):
        if w[y]==w[x]:
            rule='No'
            same = True
            break
    if same:
        break
print(rule)

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

w=list()
temp=['a']
error=0

for i in range(n):
    s=input()
    if i!=0 and s[0]!=temp:
       error=1
    w.append(s)
    temp=s[-1]

wset=set(w)

if len(w)==len(wset) and error==0:
    print('Yes')
else:
    print('No')

Solution (Python):
N= int(input())
Wn = list(input() for i in range(N))
ans = True
if len(set(Wn)) == len(Wn):
    lastst = Wn[0][-1]
    ans = True
    for i in range(len(Wn)-1):
        if Wn[i+1][0] == lastst:
            lastst = Wn[i+1][-1]
        else:
            ans = False
            break
    if ans == True:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

a = []
flag = 0
for i in range(n):
    b = input()
    if i == 0 or b[0] == en:
        if b in a:
            flag = 1
        else:
            a.append(b)
    else:
        flag = 1

    en = b[len(b)-1]

print(['Yes','No'][flag])

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

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

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

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

Solution (Python):
N = input()
a = []
f = True
for i in range(N):
  a.append(raw_input())
    
for x in range(N-1):
  if a[x][-1:] != a[x+1][:1]:
    f = False
    
if len(a) != len(set(a)):
  f = False

if f:
  print "Yes"
else:
  print "No"

Solution (Python):



n = int(input())

word = []
word.append(input())

ans = 'Yes'

for _ in range(n-1):
    shiritori = input()
    if shiritori in word:
        ans = 'No'
        break
    elif shiritori[0] != word[-1][-1]:
        ans = 'No'
        break
    else:
        word.append(shiritori)
        
print(ans)

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

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

Solution (Python):
N=int(input())
s=[input() for i in range(N)]
count=0
if(len(s)!=len(set(s))):
  count=1
else:
  for i in range(N-1):
    len_s=len(s[i])
    if(s[i][len_s-1]!=s[i+1][0]):
      count=1
      break
    else:continue
if(count==0):
	print('Yes')
else:print('No')

Solution (Python):
l = []

N = int(input())

t = input()
last = t[-1]
l.append(t)

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

Solution (Python):
judge = 'Yes'
N = int(input())
W = [None] * N

W[0] = input()

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

Solution (Python):



from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator

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

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

Solution (Python):
N = int(input())
list = []
for i in range(N):
    list.append(str(input()))
flag = 0
for i in range(N):
    c = 0
    for j in range(N):
        if list[i] == list[j]:
            c += 1
    if c >= 2:
        print("No")
        break

if c < 2:
    for i in range(N-1):
        if list[i][len(list[i])-1] == list[i+1][0]:
            flag += 1
    if flag == N - 1:
        print("Yes")
    else:
        print("No")

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

Solution (Python):


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

    f = True
    d = {}
    pv = ''
    for i in range(N):
        v = W[i]
        if v in d:
            f = False
            break
        if 0 < i and pv[-1] != v[0]:
            f = False
            break
        d[v] = pv = v

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


if __name__ == '__main__':
    main()

Solution (Python):
""" AtCoder """

import sys
input = sys.stdin.readline

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

a = [W[0]]
check = 1

for i in range(N-1):
    if W[i+1] in a or W[i][-2] != W[i+1][0]:
        check = 0
        break
    a.append(W[i+1])

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

Solution (Python):
""" AtCoder """

import sys
input = sys.stdin.readline

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

a = []
check = 1

for i in range(N-1):
    if W[i+1] in a or W[i][-2] != W[i+1][0]:
        check = 0
        break
    a.append(W[i])

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

Solution (Python):
def main():
    N = int(input())
    wn = [input()]
    ans = True
    for i in range(1, N):
        w = input()
        if ans is False:
            continue
        if wn.count(w) > 0:
            ans = False
        if wn[i - 1][-1] != w[0]:
            ans = False
        wn.append(w)

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


main()

Solution (Python):
N =int(input())
l =[input()]
s =l[0][-1]
a = True
for i in range(N-1):
    m =input()
    if not m in l and m[0]==s:
        l.append(m)
        s = m[-1]
    else:
        a=False
        break
if a:
    print("Yes")
else:
    print("No")

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

Solution (Python):
def main():
    n = int(input())
    words = []
    for i in range(n):
        word = input()
        if words.count(word) > 0:
            print("No")
            return

        if len(words) != 0:
            if words[-1][-1] != word[0]:
                print("No")
                return
        words.append(word)
    print("Yes")


if __name__ == '__main__':
    main()

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

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

ans = 'Yes'
if len(W) != 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):


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

main()

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

w.insert(0, w[0][0])
w.append(w[-1][-1])

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

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

end = w[0][-1]
flag = 0

memo={}
memo[w[0]] = "_"

for i in range(1,n):
  if w[i] in memo:
    flag=1
    break
  memo[w[i]] = "_"
  start = w[i][0]
  if end != start:
    flag = 1
    break
  else:
    end = w[i][-1]
    
if flag == 1:
  print("No")
else:
  print("Yes")

Solution (Python):

import sys
n = int(input());
words = []

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

if (len(words) > len(set(words))):
    print('No')
    sys.exit(0)

before_word = words.pop(0)
while( len(words) > 0 ):
    after_word = words.pop(0)
    if (before_word[-1] != after_word[0]):
        print('No')
        sys.exit(0)
    before_word = after_word
print('Yes')