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



Sample input:
4
hoge
english
hoge
enigma


Sample output:
No

Submission status: Runtime Error

Solution code:
N = int(input())
l = list()
al = list()
bl = list()
 
for n in range(0,N):
    a = input()
　 l.append(a)
    al.append(a[1])
    bl.append(a[-1])
 
l_unq = list(set(l))
if len(l) == len(l_unq):
    for i in range(0,N-1):
        if al[i+1] != bl[i]:
          print("No")
          break
     print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
l = list()
al = list()
bl = list()
 
for n in range(0,N):
    a = input()
　 l.append(a)
    al.append(a[:1])
    bl.append(a[-1:])
 
l_unq = list(set(l))
if len(l) == len(l_unq):
    for i in range(0,N-1):
        if al[i+1] != bl[i]:
          print("No")
          break
     print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
l = list()
al = list()
bl = list()

for n in N:
    a = input()
　 l.append(a)
    al.append(a[:1])
    bl.append(a[-1:])

l_unq = list(set(l))
if len(l) == len(l_unq):
    for i in N-1:
        if al[i+1] != bl[i]:
          print("No")
          break
     print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
n = int(input()) 
t = [int(input()) for i in range(n)] 


check_same = []
flag = False
i = 0

while i < n-1:

    b = 0

    while b < i:

        if t[i] == t[b]:
            flag = True
            break

        else:
            b += 1
     
    check_same.append(t[i])

    l = len(t[i])

    if (t[i][l-1] == t[i+1][0]):

        i += 1
    else:
        flag = True
        break

    

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

else:
    print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input()) 
t = [int(input()) for i in range(n)] 



t = ["hoge","english","hoiga","enigma"]
check_same = []
flag = False
i = 0

while i < n-1:

    b = 0

    while b < i:

        if t[i] == t[b]:
            print(t[i])
            flag = True
            break

        else:
            b += 1
     
    check_same.append(t[i])

    l = len(t[i])
    print(l)

    if (t[i][l-1] == t[i+1][0]):

        print(t[i][l-1])
        print(t[i+1][0])
    
    else:
        print("ppp")
        flag = True
        break

    i += 1

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

else:
    print("Yes")

Submission status: Runtime Error

Solution code:
from itertools import tee
N = int(input())
w0, w1 = tee((int(input()) for _ in range(N)), 2)
next(w1)
for a,b in zip(w0,w1):
  if a[-1] != b[0]:
    print('No')
    break
else:
  print('Yes')

Submission status: Runtime Error

Solution code:
c = int(input())
w = []
for i in range(c):
  w.append(input())
if len(set(w)) != len(w):
  print("No")
  return
for i in range(len(w) - 1):
  if w[i][-1] != w[i+1][0]:
    print("No")
    return
print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())

words=[input() for i in range(N)]
a0 = len(words)
b0 = len(set(words))

for i in range(N-1):
    c1=words[i]
    d1=words[i+1]
    e1=c[-1]
    f1=d[0]
    g1=0
    if e1 != f1:
        g1=g1+1
    break

if a0 != b0:
    print("No")
    sys.exit()
elif g1!=0:
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
N=input()
N=int(input())
S=[input() for i in range(N)]
ans='Yes'
if len(set(S))!=N:
    ans='No'
for i in range(N-1):
    if S[i][len(S[i])-1]!=S[i+1][0]:
        ans='No'
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
W = []
for j in range(N):
  W.append(input())
  j += 1


i = 0
while i < N:
  m = W[i-1]
  n = W[i]
  if m[-1:] == n[:1]:
    i += 1
  else:
    print('No')
    exit()
else:
  W.sort()
  for k in range(N):
      m = W[i]
      n = W[i+1]
      if m == n:
        print('No')
        exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import sys
def is_unique(seq):
    return len(seq) == len(set(seq))

N = int(input())
W = []
for i in range(N):
    w.append((input()))
if is_unique(W):
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            print("No")
            sys.exit()
    print("Yes")

else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys

n = int(input())
l = []
p = None

for i in range(n):
  s = input()
  if s in l && (p == None || p[-1:] == s[1:]):
    l.append(s)
    p = s
  else:
    print("No")
    sys.exit()
print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(N):
   A.append(input())
S = 0
for i in range(N-1):
    if A[i][-1] == A[i+1][0]:
        S += 1
B = 0
for i in range(N):
    for j in range(N):
        if A[i] == A[j]:
            B += 1
            else:
                B += 0

if S == N-1 and B == N:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys

def is_ok(l=None,words=None,num=0):
    for n in range(2,num):
        # print(l[n])
        if l[n] in words:
            # print("already used")
            return False
        head=l[n][0:1]
        rare=l[n-1][-1:]
        if head != rare:
            # print(head)
            # print(rare)
            # print("head is not rare")
            return False
        words.append(l[n])
    return True

l = input().split()
words=[l[1]]
# print(words[0])
num = int(l[0])+1
# print(num)

if is_ok(l,words,num):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys

def is_ok(l=None,words=None,num=0):
    for n in range(2,num):
        if l[n] in words:
            return False
        head=l[n][0:1]
        rare=l[n-1][-1:]
        if head != rare:
            return False
        words.append(l[n])
    return True

l = input().split()
words=[l[1]]
num = int(l[0])+1

if is_ok(l,words,num):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for num in range(1, N+1):
  if a[num][-1] != a[num+1][0]:
    print('No')
    break
  if a[num] in a:
    print('No')
    break
  print('Yes')

Submission status: Runtime Error

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

for num in range(1, N):
  if a[num][-1] != a[num+1][0]:
    print('No')
    break
  if a[num] in a:
    print('No')
    break
  print('Yes')

Submission status: Runtime Error

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

## 最初に入力回数が与えられて、そのあとデータが入力される。といったパターン
N = int(input())
a = []
for i in range(N):
    a.append(input()) # ３度の入力に対して、1, 2, 3 と入力。
#print(a) # ['1', '2', '3']

if not(is_unique(a)):
	print("No")
	exit(99)

last_char=""
counter=0
for item in a:
	if counter == 0:
		last_char = item[-1]
		counter = 1
	else:
		if(len(item)):
			print("No")
			exit(99)
		if not (item[0] == last_char):
			print("No")
			exit(99)
		else:
			last_char = item[-1]
			
print("Yes")

Submission status: Runtime Error

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

for i in range(N-1):
     S = 0
     if A[i][-1] == A[i+1][0]:
        S += 1
for i in range(N):
  for j in range(N):
    if i != j:
      if A[i] == A[j]:
        A == 1
      else:
        A == 0

if S == 1 and A == 0:
  print('Yes')
else:

Submission status: Runtime Error

Solution code:
N = input()
a = []
for i in str(N).encode():
    a.append(input())

j = 0
l = 0
N = int(N)
while j < N:
    k = j
    while k != N :
        k += 1
        if a[j] in a[k]:
            print('No')
            l = 1
            break
if l == 0:
    print('Yes')

Submission status: Runtime Error

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

## 最初に入力回数が与えられて、そのあとデータが入力される。といったパターン
N = int(input())
a = []
for i in range(N):
    a.append(input()) # ３度の入力に対して、1, 2, 3 と入力。
#print(a) # ['1', '2', '3']

if not(is_unique(a)):
	print("No")
	exit(99)

last_char=""
counter=0
for item in a:
	if counter == 0:
		last_char = item[-1]
		counter = 1
	else:
		if not (item[0] == last_char):
			print("No")
			exit(99)
		else:
			last_char = item[-1]
			
print("Yes")

Submission status: Runtime Error

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

j = 0
l = 0
while j < N:
    k = j
    while k != N :
        k += 1
        if a[j] == a[k]:
            print('No')
            l = 1
            break
if l == 0:
    print('Yes')

Submission status: Runtime Error

Solution code:
N = input()
str a = [input() for i in range(N)]

j = 0
l = 0
while j < N:
    k = j
    while k != N :
        k += 1
        if a[j] == a[k]:
            print('No')
            l = 1
            break
if l == 0:
    print('Yes')

Submission status: Runtime Error

Solution code:

n=int(input())
list=[]
word=input()
list.append(list,word)
key=word[-1]
for i in range(1,n):
    word=input()
    if key==word[0] and (word not in list):
        list.append(list,word)
        key=word[-1]
    else:
        print("No")
print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
ans = "Yes"
arr = []
for i in range(N)
    arr.append(input())
    if not i == 1:
        if arr[i] in arr and arr[i-1][-1] == arr[i][0]
            pass
        else:
            ans = "No"
            break

print(ans)

Submission status: Runtime Error

Solution code:
import sys

a = []
for line in sys.stdin:
    a.append(int(line))
N = len(a)
count = 0
flag = True
for i in range(N):
    a_i = a[i]
    a_ii = a[i+1]
    if ai[-1] != a_ii[0]:
        flag = None
        break
    for j in range(i+1, N):
        if a[i] == a[j]:
            flag = None
            break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
dataNum=input()
wordList=[]
for word in input:
    wordList.append(word.strip())

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

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

print("Yes")

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
for i in range(n):
  a.append(list(map(str,input())))
  
for j in range(1,n):
  if a[j][0]!=a[j-1][-1]:
    print("No")
    break
  elif j==n-1:
    print("Yes")
    break
  for l in range(j-1):
    if a[l]==a[j]:
      print("No")
      sys.exit()
    elif j==n-1 and l==j-2:
      print("Yes")
      sys.exit()

Submission status: Runtime Error

Solution code:
n = input()
flag = True
s = []
w1 = input()
e = w1[-1]
for i in range(n-1):
  wi = input()
  if e != wi[-1]:
    flag = False
  
  e = wi[-1]
  
if flag:
  print("Yes")
  
else:
  print("No")

Submission status: Runtime Error

Solution code:
n = int(input())

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

Submission status: Runtime Error

Solution code:
def count_word(words, word):
    count = 0

    for w in words:
        if w == word:
            count += 1

    return count

n = int(input())

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

bind_letter = ""
for word in words:
    matches = count_word(words, word)
    if matches >= 2:
        print("No")
        exit()

    if bind_letter != "":
        if word[0] != bind_letter:
            print("No")
            exit()
    bind_letter = word[len(word) - 1]
    
p

Submission status: Runtime Error

Solution code:
import collecions

N = int(input())
W = [input() for i in range(N)]
c = collecions.Counter(W)

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

Submission status: Runtime Error

Solution code:
x = input().split('\n')
n = int(x[0])
w = [x[i] for i in range(1, n+1)]

def chk_shiri(w):
    for i in range(n - 1):
        if w[i][-1] == w[i + 1][0]:
            continue
        else:
            return False
    return True
    
if len(w) != len(set(w)):
    print('No')
elif chk_shiri(w):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

N = int(input())
words = []
for i in range(N):
    words.append(input())
hantei = 0
for i in range(N-1):
    a = [x for x in words[i]]
    b = [x for x in words[i+1]]
    if a[len(a)-1] == b[1]:
        pass
    else:
        hantei += 1
        break
if hantei == 0 and is_unique(words) == True:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:

n = int(input())
w = []

for i in range(n):
    s = input()
    if s in w:
        flag = 0
        break
    else:
        w.append(s)

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

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

Submission status: Runtime Error

Solution code:

n=input()
word=input()
key=word[-1]
for i in range(1,n):
    word=input()
    if key==word[0]:
        key=word[-1]
    else:
        print("No")
print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input())

ans = 'Yes'

w = []

for i in range(n):
	a = input()
	if a in w:
		ans = 'No'
	else:
		w.append(a)

if n == 2:
	if w[0][-1] != w[1][0]:
		ans = 'No'
elif n == 3:
	if w[0][-1] != w[1][0]:
		ans = 'No'
	if w[1][-1] != w[2][0]:
		ans = 'No'
else:
	for i in range(1,n-2):
		print(i)
		if b[-1] == w[i][0]:
			b = w[i]
		else:
			ans = 'No'
print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vpii = vector<pii>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

int main() {
	int n;
	cin >> n;
	vs w;
	rep(i, 0, n) {
		string s;
		cin >> s;
		w.push_back(s);
	}
	string s0(w[0]);
	repv(i, w) {
		repv(j, w) {
			if (w[i] == w[j] && i != j) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	rep(i, 1, n) {
		string s1 = w[i];
		if (s0[s0.size() - 1] != s1[0]) {
			cout << "No" << endl;
			return 0;
		}
		s0 = s1;
	}
	cout << "Yes" << endl;
}

Submission status: Runtime Error

Solution code:
n=int(input())
w=[input() for i in range(n)]
flag=True
for s in w:
    if w.count(s) > 1:
        flag = False
for i in range(1,n)
    if w[i][0] != w[i-1][len(w[i-1])-1]:
        flag = False
print("Yes" if flag else "No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
    n = int(input())
     
    last = None
    seen = set()
    for _ in range(n):
      w = input()
      if w in seen or (last and last[-1] != w[0]):
        print("No")
        break
      seen.add(w)
    else:
      print("Yes")

Submission status: Runtime Error

Solution code:
n=int(input())
w=[input() for i in range(n)]
flag=True
for s in w:
    if w.count(s) > 1:
        flag = False
for i in range(1,n)
    if list(w[i])[0] != reversed(list(w[i-1]))[0]:
        flag = False
print("Yes" if flag else "No")

Submission status: Runtime Error

Solution code:
4
hoge
english
hoge
enigma

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys


N = int(input())
prev = None
ok = Truen
for n in range(N):
    w = input()
    if prev is None:
        prev = w
    else:
        if prev[-1] != w[0]:
            ok = False
    prev = w
if ok:
    print('Yes')
else:
    print('No')