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())
c = False
w = input().strip().split()
for i in range(0,n):
    if i != 0:
        if w[i][0] == w[i-1][-1]:
            for j in range(i-1):
                if w[i] == w[j]:
                    c = False
                else:
                    c = True
if c:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
for i in range(n):
    w = input()
    if i > 0:
        if  w[i-1][-1] == w[i][0]:
            for j in range(i):
                if w[i] == w[j]:
                    print('No')
                else:
                    print('Yes')
        else:
            print('No')

Submission status: Runtime Error

Solution code:
n=int(input())
lw=[input() for i in range(n)]
used=set()
last=lw[0][0]
for w in lw:
    if w in used or last !=w[0]:
        cond=False
        break
    used.add(w)
    last=w[-1]
print("Yes" if cond else "No")

Submission status: Runtime Error

Solution code:
def f(words):
	seen = set([words[0]])
	p = words[0]
	for w in words[1:]:
		if w in seen or p[-1] != w[0]: return False
		p = w
		seen.add(w)
	return True

print 'Yes' if f([raw_input() for _ in range(int(raw_input())]) else 'No'

Submission status: Runtime Error

Solution code:
def f(words):
	seen = set([words[0]])
	p = words[0]
	for w in words[1:]:
		if w in seen or p[-1] != w[0]: return False
		p = w
		seen.add(w)
		return True

print 'Yes' if f([raw_input() for _ in range(int(raw_input())]) else 'No'

Submission status: Runtime Error

Solution code:
n = int(raw_input())
def f(words):
seen = set([words[0]])
p = words[0]
for w in words[1:]:
	if w in seen or p[-1] != w[0]: return False
	p = w
	seen.add(w)
	return True

print 'Yes' if f(raw_input().split()) else 'No'

Submission status: Runtime Error

Solution code:
N = int(input())
words = []
for _ in range(N):
    words.append(input())
print('Yes' if all(w[i].startswith(w[i-1][-1]) for i in range(1, N)) and len(set(words)) == N else 'No')

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(input()for i in range(N))
if len(A)==len(set(A)):
    if all(A[i][-1]==A[i+1][0]) for i in range(N-2):
        print('Yes')
    else:print('No')
else:print('No')

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(input()for i in range(N))
if len(A)==len(set(A)):
    if all(A[i][-1]==A[i+1][0]) for i in range(N-1):
        print('Yes')
    else:print('No')
else:print('No')

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(input()for i in range(N))
if len(A)==len(set(A):
    if all(A[i][-1]==A[i+1][0]) for i in range(N-1):
        print('Yes')
    else:print('No')
else:print('No')

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
ans=0
for i in range(n):
  keep=s[-1]
  s=input()
  if keep != s[0]:
    ans=1
  else:
    continue
print(["Yes","No"][ans])

Submission status: Runtime Error

Solution code:
n = int(input())

ans = 'Yes'
prev = ''
for _ in range(n):
    sta = str(input())
    if _ == 0:
        continue
    else:
        if prev[-1] == sta[0]:
            prev = sta
        else:
            ans = 'No'
            prev = sta
            
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input)
flag=True
a=0
l=[]
for i in range(n):
    b=a
    l.append(b)
    a=list(input())
    if i>0:
        if a[0]!=b[-1] or a in l:
            flag=False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
flag=True
for i in range(n):
    w.append(input())
    
for i in range(n-1):
    if w[i][-1]!=w[i+1][0]:
        #print(i,"out1")
        flag=False

for i in range(n-1):
    for j in range(i+1,n):
        if(w[i]==w[j]):
            #print(i,j,"out2")
            flag=False

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
for _ in range(N):
    W=input()
    if W in A:
        print('No')
        exit()
    else:
        W.append(A)

for i in range(N-1):
    if A[i][-1]!=A[i+1][-1]:
        print('No')
        exit()
print('Yes')

Submission status: Runtime Error

Solution code:
n = int(input())
w = [input() for i in range(n)]
if n == len(set(w)) and w[i-1][-1] == w[i][0] for i in range(1,n):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
N=int(input())
B=list()
B.append(input())
for i in range(N-1):
	tmp=input()
	if tmp in B:
		print('No')
		exit()
	if tmp[0]!=B[i-1][-1]:
		print('No')
		exit()
print('Yes')

Submission status: Runtime Error

Solution code:
N=int(input())
Ws=[]
for n in range(N):
    W=input()
    Ws.append(W)

for w in range(len(Ws)):
    if Ws.count(w)>=2:
        print('No')
        exit()

for x in range (1,N+1):
    if Ws[x][0] != Ws[x-1][-1]:
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
cnt=0
for i in range(n):
  x=input()
  if i>=1:
    if x in lst:
      print('No')
      cnt+=1
      exit()
    lst+=x
    if lst[i][0]!=lst[i-1][-1]:
      print('No')
      cnt+=1
      exit()
if cnt==0:
  print('Yes')

Submission status: Runtime Error

Solution code:
N = int(input())
W = list(input())
a = 'Yes'

s = W[0]

for i in range(N-1):
    k = input()
    if s[-1]==k[0] and k not in W:
        W.append(k)
        s = W[-1]
    else:
        a = 'No'
        for j in range(N-i):
            k = input()
        break


print(a)

Submission status: Runtime Error

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

if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
n = int(input())

w = [0]*n
used = []

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

if(w[n] not in used):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

N = inputI()
l = inputILs(N)

if len(set(l))!=N:
  No()
  exit()
else:
  for i in range(N-1):
    if l[i][-1]!=l[i+1][0]:
      No()
      exit()
Yes()

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
W = []
jud = 1

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

c = collections.Counter(W)
ct = len(c)

for i in range(N-1):
    fst = W[i]
    fnl = W[i+1]
    if fst[-1] != fnl[1]:
        jud = 0

if ct != N:
    print("No")
elif jud == 0:
    print("No")
else: print("Yes")

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
W = []
jud = 1

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

c = collections.Counter(W)
ct = len(c)

for i in range(N-1):
    fst = W[i]
    fnl = W[i+1]
    if fst[-1] == fnl[1]:
        jud = 0

if ct != N:
    print("No")
elif jud == 0:
    print("No")
else: print("Yes")

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
W = []
for _ in range(N):
    W.append(input())  # S += [input()] とも書ける

c = collections.Counter(W)
ct = len(c)

for i in range(N-1):
    fst = W[i]
    fnl = W[i+1]
    if fst[-1] == fnl[1]:
        jud = 0

if ct != N:
    print("No")
elif jud == 0:
    print("No")
else: print("Yes")

Submission status: Runtime Error

Solution code:
# ABC109B

n = int(input())
w = [int(input()) for i in range(n)]
ok = "Yes"
e = w[0][-1]
double = [w[0]]
for i in range(1, n):
    if double.count(w[i]) != 0:
        ok = "No"
        break
    double.append(w[i])
    s = w[i][0]
    if s != e:
        ok = "No"
        break
    e = w[i][-1]
print(ok)

Submission status: Runtime Error

Solution code:
n = int(input())
w = [input() for i in range(n)]
check = []
prev = ""
for i in range(n-1):
  if not prev:
    if prev[-1] != w[i][0]:
      print("No")
      return
  check.append(w[i])
  if check.count(w[i]) > 1:
    print("No")
    return
print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input())

check = []
prev = ""
for i in range(n-1):
  w = string(input())
  if not prev:
    if prev[-1] != w[0]:
      print("No")
      return
  check.append(w)
  if check.count(w) > 1:
    print("No")
    return
print("Yes")

Submission status: Runtime Error

Solution code:
n = input()
w = [input() for i in range(n)]
check = []
prev = ""
for i in range(n-1):
  check.append(w[i])

Submission status: Runtime Error

Solution code:
n = input()
w = [input() for i in range(n)]
check = []
prev = ""
for i in range(n):
  check.append(w[i])

Submission status: Runtime Error

Solution code:
n = input()
w = [input() for i in range(n)]
check = []
prev = ""
for i in range(n):
  check.append(w[i])
  if check.count(w[i]) > 1:
    print("No")
    return
print("Yes")

Submission status: Runtime Error

Solution code:
n = input()
w = [input() for i in range(n)]
check = []
prev = ""
for i in range(n):
  if not prev:
    if prev[-1] != w[i][0]:
      print("No")
      return
  check.append(w[i])
  if check.count(w[i]) > 1:
    print("No")
    return
print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input())

check = []
prev = ""
for i in range(n):
  w = string(input())
  if not prev:
    if prev[-1] != w[0]:
      print("No")
      return
  check.append(w)
  if check.count(w) > 1:
    print("No")
    return
print("Yes")

Submission status: Runtime Error

Solution code:
n = input()

check = []
prev = ""
for i in range(n):
  w = input()

Submission status: Runtime Error

Solution code:
n = input()

check = []
prev = ""
for i in range(n):
  w = input()
  if not prev:
    if prev[-1] != w[0]:
      print("No")    
  check.append(w)
  if check.count(w) > 1:
    print("No")
print("Yes")

Submission status: Runtime Error

Solution code:
n = input()

check = []
prev = ""
for i in range(n):
  w = input()
  if not prev:
    if prev[-1] != w[0]:
      print("No")
      return
  check.append(w)
  if check.count(w) > 1:
    print("No")
    return
print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())

shiritori_set = set()

shiritori = input()
head = shiritori[len(shiritori) -1]

ans = "Yes"

for i in range(N-1):
  shiritori = input()
  if (shirotori[0] == head and shiritori in shiritori_set):
    head = shiritori[len(shiritori)-1]
    shiritori_set.add(shiritori)
    continue
  else:
    ans = "No"
    break

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

words = {}
w = ''
ok = True
for i in range(n):
  nw = input()
  if nw in words:
    ok = False
    break
  words.add(w)
  if w && w[-1] != nw[0]:
    ok = False
  w = nw

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

Submission status: Runtime Error

Solution code:
n = int(input())

words = {}
w = ''
ok = True
for i in range(n):
  nw = input()
  if nw in words:
    ok = False
    break
  words.add(w)
  if w and w[-1] != nw[0]:
    ok = False
  w = nw

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

Submission status: Runtime Error

Solution code:
n = int(input())

words = {}
w = ''
ok = True
for i in range(n):
  nw = input()
  if nw in words:
    ok = False
    break
  words.add(w)
  if w && w[-1] != nw[0]:
    ok = False
  w = nw

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

Submission status: Runtime Error

Solution code:
print('Yes' if len(W) == len(set(W)) and all(i[-1] == j[0] for i, j in zip(W, W[1:])) else 'No')

Submission status: Runtime Error

Solution code:
n, *l = open(0).read().split()
print("Yes" if len(set(l)) == len(l) and all(l[i][-1] == l[i+1][0] for i in range(n)) else "No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
word = []
flag = 1
for i in range(N):
  st = input()
  if i > 0 :
    if final != st[0]:
      flag = 0
    elif st in word:
      flag = 0
    else:
      final = st[-1]
      word += [st]
if flag:
  print("Yes")
else :
  print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    n = input()
    before = ''
    words = set()

    for i in range(n):
        w = input()
        if w not in words:
            words.add(w)
        else:
            print('No')
            return

        if before == '':
            before = w
            continue

        if before[-1] != w[0]:
            print('No')
            return

    print('Yes')


main()

Submission status: Runtime Error

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

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

print('Yes')

Submission status: Runtime Error

Solution code:
def check_words(w):
    if len(w) != len(set(w)):
        return False
    for i in range(n-1):
        if w[i][-1] != w[i+1][0]:
            return False
    return True

n = int(input())
w = list(map(str, input().split()))
if check_words(w):
    ret = 'Yes'
else:
    ret = 'No'
print(ret)

Submission status: Runtime Error

Solution code:
def check_words(w):
    if len(w) != len(set(w)):
        return False
    for i in range(n-1):
        if w[i][-1] != w[i+1][0]:
            return False
    return True

n = int(input())
w = list(map(str, input().split()))
ret = 'Yes' if check_words(w) else 'No'
print(ret)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  char pe;
  string str;
  set<string> s;
  std::cin >> str;
  pe = str.back();
  s.insert(str);
  bool ok = true;
  rep(i, n-1) {
    std::cin >> str;
    if (str[0] != pe || s.count(str)) ok = false;
    pe = str.back();
    s.insert(str);
  }
  std::cout << (ok ? "Yes" : "No") << "\n";
}

Submission status: Runtime Error

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

for i in range(1, N):
    if A[i-1][-1] == A[i][0]:
        ans *= 1
    else:
        ans *= 0    
    
if all(A.count(i) == 1 for i in A):
    ans *= 1
else:
    ans *= 0

Submission status: Runtime Error

Solution code:
n = int(input())
lst = [input() for _ in range(n)]
lstset = set(lst)

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

Submission status: Runtime Error

Solution code:
n = int(input())
lst = [iuput() for _ in range(n-1)]
lstset = set(lst)
if len(lst) != len(lstset):
    print("No")
else:
    cnt = 0
    for i in range(n-1):
        if lst[i][-1] == lst[i][0]:
            cnt += 1
        else:
            break
    if cnt == len(lst):
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int n;
string w;
set<string>ss;
int main(){
	cin>>n;
	char c;
	for(int i=0;i<n;i++){
		cin>>w;
		if(ss.count(w)==0){
			if(i!=0&&c!=w[0]){
				cout<<"No";
				return 0;
			}
			c=w[w.size()-1];
			ss.insert(w);
		}
		else{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Submission status: Runtime Error

Solution code:
3
abc
arc
agc

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N=input()
W=[]
for i in range(N):
  W[i]=input()
  if len(W)!=i+1:
    print('No')
    break
  if W[i][1]!=W[i-1][-1]:
    print('No')
    break
else:
  print('Yes')

Submission status: Runtime Error

Solution code:
def main():
  n = int(input())
  result = True
  used= {}
  for order in range(0,n):
    word = str(intput())
    print(used.key)
    if word in used or sorted(used.keys())[len(used) -1][-1] == word[0]:
      print('NO')
      result = False
      break
  if result:
    print('Yes')
 
 
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
def main():
  n = int(input())
  result = True
  used= {}
  for order in range(0,n):
    word = str(intput())
    print(used.key)
    if word in used or used.key[-1][-1] == word[0]:
      print('NO')
      result = False
      break
  if result:
    print('Yes')
 
 
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
def main():
  lists = [str(input())]
  used = {}
  result = True
  for word in lists:
    if word in used:
      print('NO')
      break
    elif:
      if used.keys()[- 1][-1] == word[0]:
        print('NO')
        break
      used.setdefault(word, 0)
  if result:
	print('Yes')
 
 
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
def main():
  siri_list = list(input())
  used = {}
  result = true
  for word in siri_list:
    if word in used:
      print('NO')
      break
    elif:
      if used.keys()[- 1][-1] == word[0]:
        print('NO')
        break
      used.setdefault(word, 0)
      
  print('Yes')
 
 
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
def main():
  siri_list = map(int, input().split())
  used = {}
  result = true
  for word in siri_list:
    if word in used:
      print('NO')
      break
    elif:
      if used.keys()[- 1][-1] == word[0]:
        print('NO')
        break
      used.setdefault(word, 0)
      
  print('Yes')
 
 
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
N= int(input())
words=[]
words.append(input())
ans="Yes"
for i in range(1,N):
    next=input()
    for word in words:
        if (next==word or  words[i-1][-1]==next[0]):
            ans = "No"
            break
        else:
            words.append(next)
print(ans)

Submission status: Runtime Error

Solution code:
words = []
for inp in range(N):
	words.append(input())

frst = words[0]
for i in range(1,len(words)):
	if words[i-1][-1] != words[i][0]:
		print("No")
		break
	else:
		flag = 0
		if words[i] in words[:i-1]:
			print("No")
			break
		else:
			flag = 1
if flag == 1:
	print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
words = input().split("\n")

frst = words[0]
last = words[-1]
if frst[0] !=  last[-1]:
	print("No")
else:
	
	for i in range(1,len(words)):
		flag = 0
		if words[i] in words[:i-1]:
			print("No")
			break
		else:
			flag = 1
	if flag == 1:
		print("Yes")

Submission status: Runtime Error

Solution code:
n=int(input())
w=[int(x) for x in input().split()]
ans='Yes'
for i in range(1,n):
  if w[i-1][-1]!=w[i][0]:
    ans='No'
    break
  for j in range(i):
    if w[i]==w[j]:
      ans='No'
      break
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
w=[input() for i range(n)]
d={}
for i in range(n):
  if w[i] not in d:
    d[w[i]]=1
  else:
    print('No')
    exit()
for i in range(n-1):
  if w[i][len(w[i])-1]!=w[i+1][0]:
    print('No')
    exit()
print('Yes')

Submission status: Runtime Error

Solution code:
n = int(input())

l = [input() for _ in range(4)]

count = len(set(l))
flag = True
for i in range(len(l) -1 ):
    if l[i][len(l[i]) -1] != l[i+1][0]:
        flag = False
        break

if flag and count == n:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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


ans = "Yes"

for i in shiritori:
    if shiritori.count(i) != 1:
        ans = "No"
        break
    
for k in range(N-1):
    first = shiritori[k]
    second = shiritori[k+1]
    if first[-1] != second[0]:
        ans = "No"
        break


    
print(ans)

Submission status: Runtime Error

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

shiritori.append(w)

ans = "Yes"

for i in shiritori:
    if shiritori.count(i) != 1:
        ans = "No"
        break
    
for k in range(N-1):
    first = shiritori[k]
    second = shiritori[k+1]
    if first[-1] != second[0]:
        ans = "No"
        break


    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
shiritori = [str(input())]

shiritori.append(w)

ans = "Yes"

for i in shiritori:
    if shiritori.count(i) != 1:
        ans = "No"
        break
    
for k in range(N-1):
    first = shiritori[k]
    second = shiritori[k+1]
    if first[-1] != second[0]:
        ans = "No"
        break


    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
w = input()
shiritori = []

shiritori.append(w)

ans = "Yes"

for i in shiritori:
    if shiritori.count(i) != 1:
        ans = "No"
        break
    
for k in range(N-1):
    first = shiritori[k]
    second = shiritori[k+1]
    if first[-1] != second[0]:
        ans = "No"
        break


    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
li = []
w = input()
li.append(w)
k = 0
ans = "Yes"
for i in range(N) :
    word = input()
    for j in range(len(li)) :
        if li[j] == word :
            k = 1
            break
    last_word = li[-1]
    if last_word[-1] != word[0] :
        k = 1
    if k == 1 :
        ans = "No"
        break
    li.append(word)
print(ans)

Submission status: Runtime Error

Solution code:
def isDupe(_arg_list):
    return True if len(_arg_list) != len(set(_arg_list)) else False
def isWordMatch(_arg_list):
    _i=0
    import pdb;pdb.set_trace()
    try:
        while True:
            if _arg_list[_i][-1:] != _arg_list[_i+1][0:1]: return True
            _i+=1
    except IndexError:
        return False
i=int(input())
word_list=[]
while i>0:
    word_list.append(input())
    i-=1
print("No") if (isDupe(word_list) or isWordMatch(word_list)) else print("Yes")

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import fractions
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=abs(x-a[0])
cnt=abs(a[1]-a[0])
for j in range(n-1):
    cnt=min(abs(a[j+1]-a[j]),cnt)
for i in range(n):
    ans=min(abs(x-a[i]),ans)
print(min(ans,cnt))

Submission status: Runtime Error

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-10 12:28:14(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, *w = sys.stdin.read().split()
    n = int(n)
    for i in range(1, n):
        if w[i][0] == w[i-1][-1] and not w[i] in w[:i]:
            continue
        else:
            sys.exit('No')
    
    print('Yes')


if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
words = [input() for i in range(1,n)]

for i in n:
    words[i] = list(words[i].split())

for j in n:
    if words[j][-1] == words[j + 1][0]:
        pass
    else:
        print('No')
        break

if len(list(set(words))) != len(words):
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
N = int(input())
words = [input() for i in range(N)]
ans = "Yes"
tmp = list(dict.fromkeys(words))
if words == tmp:
    for j in range(1,N):
        if words[j][0] != word[j-1][-1]:
            ans = "No"
            break
    print(ans)
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())

W = []
for i in range(N):
    if i == 0:
        x = input()
        W.append(x)
    else:
        x = input()
        if x in W:
            print("No")
            exit()
        elif W[i-1][len(W[i-1]) - 1] != x[0]:
            print("No")
        else:
            W.append(x)

print("Yes")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

check = True
for i in range(N-1):
    if W[i][-1] == W[i+1][0]:
        continue
    else:
        check = False
        break
for i in range(N):
    if W[i] in w_dic:
        check = False
    else:
        w_dict[W[i]] = 1
if check:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
from colecctions import defaultdict

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

dic = defaultdict(int)

for i in range(N):
  if i == 0:
    tmp = W[i][-1]
    dic[W[i]] = 1
  else:
    if tmp != W[i][0] or dic[W[i]]:
      print("No")
      break
    else:
      tmp = W[i][-1]
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
def valid(words):
  used = set()
  last = ""

  for w in words:
    if w in used:
      return False
    if last != "" and last[-1] != w[0]:
      return False
    last = w
    used.append(w)
  return True

n = int(input())
words = [input() for _ in range(n)]
print("Yes" if valid(words) else "No")