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())
p = ''
d = []
for _ in range(n):
  w = input()
  if p and p[-1] == w[0]
    print('No')
    exit()
  if w in d:
    print('No')
    exit()
  p = w[-1]
  d[w] = 1
print('Yes')

Submission status: Runtime Error

Solution code:
import sys
N,*W = map(str,open().read().split())
N = int(N)
for i in range(N-1):
    if list(W[i])[-1] != list(W[i+1])[0]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import sys
N,*W = map(str,open().read().split())
N = int(N)
for i in range(N-1):
    if list(N[i])[-1] != list(N[i+1])[0]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input())
words = []
before= input()
words.append(first)
flag = True
for _ in range(n-1):
  s = input()
  if before[-1] != s[0]:
    flag == False
  before = s
l = len(set(words))
if l != n:
  flag = False
if flag:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n=int(input())
a=[input() for i in range(n)]
s=0
for i in raneg(n-1):
    if a[i][-1]!=a[i+1][0]:
        s+=1
a.sort()
for i in raneg(n-1):
    if a[i]==a[i+1]:
        s+=1
if s==0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
A = [[input()] for _ in range(N)]
for i in range(N):
  if b==A[i][0]:
    b= A[i][-1]
  else:
    print("No")
    exit()
A.sort()
for i in range(N-1):
  if A[i]==A[i+1]:
    print("No")
    exit()
print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input())
soFar = []
last = None
flag = True
for i in range(n + 1):
    x = input()
    if i == 0:
        soFar.append(x)
        last = x
    else:
        if x not in soFar and last[len(last) - 1] == x[0]:
            soFar.append(x)
            last = x
        else:
            flag = False
            break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
siritori=collections.defaultdict(int)
prev=""
for i in range(N):
  word = input()
  if word in siritori:
    print("No")
  elif prev[-1]==word[0]:
    print("No")
  siritori[word]+=1
  prev=word
print("Yes")

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
siritori=collections.defaultdict(int)
prev=""
for i in range(N):
  word = imput()
  if word in siritori:
    print("No")
  elif prev[-1]==word[0]:
    print("No")
  siritori[word]+=1
  prev=word
print("Yes")

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
siritori=collections.defaultdict(int)
prev=""
for i in range(N):
  word = imput()
  if word in siritori:
    print("No")
  elif prev[-1]==word[0]:
    print("No")
    siritori[word]+=1
print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input())
w = []
for i in range(n):
    item = str(input())
    if i == 0:
        w.append(item)
    elif i!=0:
        if w[i-1][-1]==item[0]:
            w.append(item)
        else:
            print("No")
            end()
l = set(w)
if len(l)==len(w):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui N; cin >> N;
  vector<string> w(N);
  for(auto& s : w) cin >> s;
  std::unordered_set<string> s(w.begin(), w.end());
  if(s.size() != w.size())
  {
    cout << "No" << CRLF;
    return;
  }  

  ui res{1};
  for(ui i = 1; i < N; ++i)
  {
    if(w[i][0] != w[i - 1].back())
    {
      res = 0;
      break;
    }
  }

  cout << (res ? "Yes" : "No") << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
yetlist = []
for i in range(n):
    word = input()
    if word in yetlist:
        print("No")
        sys.exit()
    if word[0] != yetlist[-1][-1]:
        print("No")
        sys.exit()
    yetlist.append(word)
print("Yes")

Submission status: Runtime Error

Solution code:
n=int(input())
l=[str(input()) for i in range(n)]
ans = 0
for i in range(n):
    if list(l[i])[-1] == list(l[i+1])[0] and l.count(l[i]) == 1:
        ans += 1
    else:
        ans += 0
print('Yes' if ans==n else'N0')

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
word = input()
li = [word]
end = word[-1]
ans = 'Yes'
for i in range(n):
    word = input()
    if word[0] != end or word in li:
        ans = 'No'
        break
    end = word[-1]
    li.append(word)
print(ans)

Submission status: Runtime Error

Solution code:
#B - Shiritori(ABC109)
N=int(input())
W=[]
for i in range(N):
    W.append(input())

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

Submission status: Runtime Error

Solution code:
N = int(input())
L = [input() for _ in range(N)]

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

Submission status: Runtime Error

Solution code:
N = int(input())
w = []
ans = "Yes"
for i in range(N):
  s = str(input())
  if(i>0):
    if(s[0]==w[-1][-1]):
      None
    else:
      ans = "No"
      break
  w.append(s)
j = set(N)
l = len(list(j))
if(len(N)==l):
  None
else:
  ans="No"
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
x=[]
for i in range(n):
  w = input()
  if i !=0 and (w in x or x[i-1][-1] != w[0]):
    print ("No")
    exit()
  x.append(w)
print("Yes")

Submission status: Runtime Error

Solution code:
n=int(input())
a=input()
b=a[len(a)-1]
word1=[a]
word2=[b]
c=0

for i in range(n-1):
    aa=input()
    bb=aa[0]
    if aa not in word1 and word2[i]==bb:
        word1.append(aa)
        top=aa[len(aa)-1]
        word2.append(top)
    else:
        c=1
        
print("Yes" if c==0 else "No")

Submission status: Runtime Error

Solution code:
n = int(input())
s1 = []
for i in range(n):
  s1.appned(input())
ans = True
p = s1[0]
for i in range(1,n):
    j = s1[i]
    if p[-1] != j[0]:
        ans = False
    p = s1[i]
for i in range(n):
    if s1.count(s1[i]) > 1:
        ans = False

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
abc = map(int, input().split())
ab = sorted(abc, reverse=True)[:3]
hoge = str(ab[0]) + str(ab[1])
print(int(hoge) + ab[2])

Submission status: Runtime Error

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

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

print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
words = []
l = []
for i in range(N):
    a = input()
    if i == 0:
        l.append(a)
        b = list(a)
        words.append(b[len(b)-1])
    elif i > 0:
        b = list(a)
        if i == N-1:
            words.append(b[0])
        else:
            words.append(b[0])
            words.append(b[len(b)-1])
        l.append(a)

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

for h in range(0,len(words),2):
    if words[h] != words[h+1]:
        print("No")
        exit(1)
print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
words = []
l = []
for i in range(N):
    a = input()
    if i == 0:
        l.append(a)
        b = list(a)
        words.append(b[len(b)-1])
    elif i > 0:
        b = list(a)
        if i == N-1:
            words.append(b[0])
        else:
            words.append(b[0])
            words.append(b[len(b)-1])
        l.append(a)

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

for h in range(0,len(words),2):
    if words[h] == words[h+1]:
        words[h] = True
        words[h+1] = True
    else:
        print("No")
        exit(1)
    
if all(l):
    print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
words = []
l = []
for i in range(N):
    a = input()
    if i == 0:
        l.append(a)
        b = list(a)
        words.append(b[len(b)-1])
    elif i > 0:
        b = list(a)
        if i == N-1:
            words.append(b[0])
        else:
            words.append(b[0])
            words.append(b[len(b)-1])
        l.append(a)

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

for h in range(0,len(words),2):
    print(h)
    if words[h] == words[h+1]:
        words[h] = True
        words[h+1] = True
    else:
        print("No")
        exit(1)
    
if all(l):
    print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
words = []
l = []
for i in range(N):
    a = input()
    if i == 0:
        l.append(a)
        b = list(a)
        words.append(b[len(b)-1])
    elif a not in l and i > 0:
        b = list(a)
        print(b)
        if i == N-1:
            words.append(b[0])
        else:
            words.append(b[0])
            words.append(b[len(b)-1])
        l.append(a)
    elif a in l and i > 0:
        print("No")
        exit(1)

for h in range(0,len(l)-2,2):
    if l[h] == l[h+1]:
        flag = True
if all(l):
#if len(set(words))*2 - len(words) == 0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
words = []
l = []
for i in range(N):
  a = input()
  if i == 0:
    l.append(a)
    b = list(a)
    words.append(b[len(b)-1])
  elif a not in l and i>0:
    b = list(a)
    if i == N-1:
      words.append(b[0])
    else:
      words.append(b[0])
      words.append(b[len(b)-1])
    l.append(a)
  elif a in l and i>0:
    print("No")
    exit(1)

    
for h in range(0,len(l),2):
  if words[h] == words[h+1]:
    words[h] = True
    words[h+1] = True
  else:
    print("No")
    exit(1)
    
if all(l):
  print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
words = []
l = []
for i in range(N):
  a = input()
  if i == 0:
    l.append(a)
    b = list(a)
    words.append(b[len(b)-1])
  elif a not in l and i>0:
    b = list(a)
    if i == N-1:
      words.append(b[0])
    else:
      words.append(b[0])
      words.append(b[len(b)-1])
    l.append(a)
  elif a in l and i>0:
    print("No")
    exit(1)

    
for h in range(0,len(l)-2,2):
  if l[h] == l[h+1]:
    flag = True
if all(l):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
words = []
for i in range(N):
  word = list(input())
  if i == 0:
    words.append(word[len(word)])
  elif i == N-1:
    words.append(word[0])
  else:
    words.append(word[0])
    words.append(word[len(word)])
  
if len(set(words))*2 - len(words) == 0:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

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

from collections import Counter

dic = Counter(W)
flg = 0
for i in range(N):
    if dic[W[i]]!=1:
        flg=1
        

for j in range(N-1):
    if W[j][-1]!=W[j+1][1]:
        flg = 1

if flg!=1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

from collections import Counter

dic = Counter(W)
flg = 0
for i in range(N):
    if dic[W[i]]!=1:
        flg=1
        break

for j in range(N-1):
    if W[j][-1]!=W[j+1][1]:
        flg = 1
        break

if flg!=1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
w = []
for i in range(n):
  word = input()
  if word in w:
    print('No')
    sys.exit()
cur = w[0][-1]
for x in w[1:]:
  if cur != x[0]:
    print('No')
    sys.exit()
  cur = x[-1]
print('Yes')

Submission status: Runtime Error

Solution code:
N=int(i)
W=[int(input()) for i in range(N)]
for i in range(N-1):
  if W[i:].find(W[i])==True:
    print("No")
  elif W[i][-1]!=W[i+1][0]:
    print("No")
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
ls = []
w = []
for i in range(N):
  ls.append(str(input())
for j in range(1,N):
  if ls[j-1][(len(ls[j])-1):] and ls[j][(len(ls[j])-1):]
    if ls[j-1] in w:
      print("No")
    else:
      w.append(ls[j-1])
  else:
    print("No")
    break

Submission status: Runtime Error

Solution code:
L=[]
for i in range(N):
  L.append(input())
if not len(L)==len(set(L)):
  print("NO")
n=0
while n<=N:
  if n==N-1:
    print("Yes")
    break
  elif L[n][-1]==L[n+1][0]:
    n=n+1
  else:
    print("NO")
    break

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
for i in range(n):
  aa=input()
  if aa in a or aa[0] != a[-1][0]:
    print("No")
    break
  if i == n-1:
    print("Yes")
  a.append(aa)

Submission status: Runtime Error

Solution code:
N = int(input())

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

#重複チェック
if len(set(l)) != n:
    print("No")
    exit()

#しりとりチェック
for i in range(n-1):
    if l[i][-1] != l[i+1][0]:
        print("No")
        exit()

print("Yes")

Submission status: Runtime Error

Solution code:
x1, y1, x2, y2 = map(int, input().split())
print(x2+(y1-y2),y2+(x2-x1),x1+(y1-y2),y1+(x2-x1))

Submission status: Runtime Error

Solution code:
n = int(input())

used = []
ans = "Yes"

for i in range(n):
    if i == 0:
        t = str(input())
    else:
        t = str(input())
        print(t + "!")
        for j in used:
            if t == j:
                ans = "No"

        if len(t) == 1:
            if past[]
            
        else:
            if past[-1] != t[0]:
               ans == "No"
    used.append(t)
    past = t

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

used = []
ans = "Yes"

for i in range(n):
    if i == 0:
        t = str(input())
    else:
        t = str(input())
        for j in used:
            if t == j:
                ans = "No"
        if past[-1] != t[1]:
            ans == "No"
    used.append(t)
    past = t

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

used = ["empty"]
ans = "Yes"

for i in range(n):
    if i == 0:
        t = str(input())
        
        past = t
    else:
        t = str(input())
        for j in used:
            if j == t:
                ans = "No"
    
    if past[-1] != t[1]:
        ans = "No"
    used.append(t)
    past = t

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

used = []
ans = "Yes"

for i in range(n):
    if i == 0:
        t = str(input())
        
        past = t
    else:
        t = str(input())
        for j in used:
            if j == t:
                ans = "No"
    
    if past[-1] != t[1]:
        ans = "No"
    used.append(t)
    past = t

print(ans)

Submission status: Runtime Error

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

def solve(n,ls):
    if n == -1:
        return print("Yes")
    else:
        if ls[n][-1] == ls[n+1][0]:
            return solve(n-1,ls)
        else:
            return print("No")

solve(n,w)

Submission status: Runtime Error

Solution code:
n = int(input())
*w, = open(0).read().split()
for i in range(1,n):
  if w.count(w[i]) > 1 or w[i-1][-1] == w[i][0]:
    print('No')
    break
  else: 
    print('Yes')

Submission status: Runtime Error

Solution code:
n = int(input())
*w, = open(0).read().split()
for i in range(1,n):
  if w.count(w[i])==1 and w[i-1][-1] == w[i][0]:
    pass
  else:
    print('No')
    break
  if i == n-1:
    print('Yes)

Submission status: Runtime Error

Solution code:
n = int(input())
*w,=open(0).read().split()
for i in range(1,n):
  if w.count(w[i]) == 1 and w[i-1][-1] == w[i][0]:
    pass
  else:
    print('No')
    break
  if i == n-1:
    print('Yes')
  else:
    pass

Submission status: Runtime Error

Solution code:
n=int(input())
w=list(input().split())
a=0
for i in range(1,n):
    if w.count(w[i])==1 and w[i-1][-1]==w[i][0]:
        a+=1
    else:
        print('No')
        break
    if a==n-1:
        print('Yes')
    else:
        pass

Submission status: Runtime Error

Solution code:
n=int(input())
*w,=open(0).read().split()
a=0
for i in range(1,n):
    if w.count(w[i])==1 and w[i-1][-1]==w[i][0]:
        a+=1
    else:
        print('No')
        break
    if a==n-1:
        print('Yes')
    else:
        pass

Submission status: Runtime Error

Solution code:
n = int(input())
words = [input() for _ in range(n)]
print("Yes" if all([y[0] == x[-1] for x, y in zip(words, words[1:]]) and len(set(words)) == n else "No")

Submission status: Runtime Error

Solution code:
n = int(input())
words = [input() for _ in range(n)]
print("Yes" if all([y[0] == x[-1] for x, y in zip(words, words[1:])) and len(set(words)) == n else "No")

Submission status: Runtime Error

Solution code:
n = int(input())
words = [input() for _ in range(n)]
print("Yes" if all([y[0] == x[-1] for x, y in zip(words, words[1:]) and len(set(words)) == n else "No")

Submission status: Runtime Error

Solution code:
N = int(input())
W = []
W.append(input())
for n in range(N):
  w = input()
  if w[0] != W[-1][-1]:
    print("No")
    break
  elif W.count(w) != 0:
    print("No")
    break
  W.append(w)
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
W = []
W.append(input())
for n in range(N):
  w = input()
  if w[0] != W[-1][-1]:
    print("No")
    break
  elif W.count(w) != 0:
    print("No")
    break
else:
  print("Yes")

Submission status: Runtime Error

Solution code:

N = int(input())

lst_W = []
for i in range(N):
    lst_W.extend(input().split())

ans = "Yes"

for i in range(N - 1):
    if (lst_W[i])[-1:] != (lst_W[i+1])[:1]:
        ans = "No"
        break

if len(lst_W) != len(set(lst_W)):
    #ans = "No"

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
W=[]
for i in range(N):
    w=input()
    W.append(w)
    last=W[0][-1]
    S=set()
    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")

Submission status: Runtime Error

Solution code:
a = input()
b = input()

words = b.split('\n')
print(words)
def main():
    ed = []
    for i in range(int(a)-2):
        w1 = words[i]
        ed.append(w1)
        w2 = words[i+1]
        print(ed)
        if w1[-1] != w2[0] or w1 in ed:
            return 'No'
    return 'Yes'

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a = input()
b = input()

words = b.split()

for i in range(len(words)-1):
    w1 = words[i]
    w2 = words[i+1]

    if w1[-1] != w2[0]:
        return 'No'

return 'Yes'

Submission status: Runtime Error

Solution code:
n = int(input())
shiritori = [list(input()) for i in range(n)]
for i in range(n-1):
  if shiritori[i][-1] != shiritori[i+1][0]:
    print("No")
    break
  if i =n-2:
    print("Yes")

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
wls =[]
for i in range(N):
    wls.append(input())
count =0
if count(wls) != count(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')

Submission status: Runtime Error

Solution code:
W = []
judge = True
a = ""
N = int(input())
for i in range(N):
    s = input()
    W.append(s)
    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]
if judge:
    print("Yes"):
else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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][len(w[i+1] - 1)]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
W = []
for i in range(N):
    tmp = input()
    if tmp in W and i != 0:
        print("No")
        exit()
    W.append(tmp)

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

Submission status: Runtime Error

Solution code:
from sys import exit
n=int(input())
s=input()
w=[]
w.append(s)
for i in range(n-1):
  s=input()
  if w[i][-1]!=a[0] or s in w:
    print('No')
    exit()
  else:
    w.append(s)
print('Yes')

Submission status: Runtime Error

Solution code:
n = int(input())
w = [input().rsprit() for i in range(n)]
use = [w[0]]
for i in range(1,n):
  if w[i][0] == w[i-1][-1] and w[i] not in use:
    use.append(w[i])
  else:
    print('No')
    exit()
print('Yes')

Submission status: Runtime Error

Solution code:
N = int(input())
list = []
bool = True

for i in range(N):
    list.append(input())
if len(set(list)) != len(list):
    bool = False
else:
    for i in range(N - 1):
        if list[i][-1] != li[i+1][0]:
            bool = False

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

Submission status: Runtime Error

Solution code:
N = int(input())
w_list = ""
is_cor = True
for i in range(N):
  w_list[i] = input()
a = w_list[0]
for i in range(1, N-1):
  b = w_list
  b[i] = 0
  if a[len(a)-1] != w_list[i][0] or w_list[i] in b:
    print("No")
    is_cor = False
    break
if is_cor:
  print("Yes")

Submission status: Runtime Error

Solution code:
n  = int(input())
w = []

w.append(input())

ans = 'Yes'
for i in range(1,n,1):
  w.append(input())
  l = len(w[j])
  if w[i][0:1] != w[j][l-1:l]: ans = 'No'
  for j in range(i):
    if w[i] == w[j]: ans = 'No'

print(ans)

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
w=[input() for i in range(n)]
if all(w[j][len(w[j])]==w[j+1][0] for j in range(n-1)) and len(set(w))==n:
  print('Yes')
  sys.exit()
print('No')

Submission status: Runtime Error

Solution code:
N=int(inout())
before=[]
ans="Yes"
for i in range(N):
        s=input()
        if s in before:
                ans="No"
        if len(before)>0:
                if before[-1][-1]!=s[0]:
                        ans="No"
        before.append(s)

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(input())]
b=True
for i in range(n-1):
  w=list(input())
  if l[-1][-1]==w[0]:
    l.append(w)
  else:
    b=False
    break
if len(set(l))==n and b==True:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(input())]
b=True
for i in range(n-1):
  w=list(input())
  if l[-1][-1]==w[0]:
    l.append(w)
  else:
    b=False
    break
if len(set(l))=n and b==True:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n,w=int(input()),[input()for i in range(n)]
def sortex(X):
  b=sorted(X)
  b.append("null")
  a=[]
  for i in range(len(X)):
    if b[i]!=b[i+1]:a.append(b[i])
  return a
if len(w)!=len(sortex(w)):
  print("No")
  exit()
for i in range(len(w)-1):
  if w[i][-1]!=w[i+1][0]:
    print("No")
    exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import math
N,X = map(int,input().split())
x = list(map(int,input().split()))

x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(1,N):
    ans = math.gcd(ans,x[i+1]-x[i])
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

used = [a[0]]
pre = a[0]
for i in a[1:]:
    if i not in used and pre[-1] == i[0]:
        used.append(i)
        pre = i
    else:
        print("No")
        exit()

print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list()
cnt = 0
A.append(input())
for i in range(N-1):
  x = input()
  if x in A:
    cnt = 1
  elif A[i][-1:] != x[0]:
    cnt = 1
  else:
    A.append(x)
print('Yes' if cnt == 0 else 'No')

Submission status: Runtime Error

Solution code:
from collections import defaultdict
dic = defaultdict(str)
n = int(input())
lst = [input() for _ in range(n)]
last = lst[0]
flag = True
for i in range(1, n):
  if lst[i][0] != last[-1]:
  	flag = False
    break
  dic[lst[i]] += 1
  if dic[lst[i]] > 1
  	flag = False
    break
if flag:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
import sys
n=input()
w=input()
l=[]
l.append(w)
for i in range(1,n):
    w=input()
    if w[0]!=l[-1][-1] or w in l:
        print("No")
        sys.exit()
    else:
        l.append(w)
print("Yes")

Submission status: Runtime Error

Solution code:
N=int(input())
L=[]
a=True
for i in range(n):
  L.append(input())
if len(L)!=len(set(L)):
  print('No')
else:
  for i in range(1,len(L)):
    if L[i][0]==L[i-1][-1]:
      continue
    else:
      a=False
  if a is True:
    print('Yes')
  else:
    print('No')

Submission status: Runtime Error

Solution code:
n = int(input())
li = []
c = 0
for i in range(n):
    w = input()
    if w in li:
        print("No")
        break
    else:
        li.append(w)
for i in range(n-1):
    if li[i][-1] == li[i + 1][0]:
        c = 1
    else:
        c = 0
        break
if c == 0:
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
_,a=open(0).readlines()
if len(set(a))<len(a):
  print("No")
  exit()
b=[(i[0],i[-2]) for i in a]
for k in range(len(b)-1):
  if b[k][1]!=b[k+1][0]:
    print("No")
    exit()
print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

print(answer)

Submission status: Runtime Error

Solution code:
n = int(input())

lastch = ''
answer = 'No'
words = []

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

print('Yes' if len(words) == len(set(words)) and answer == 'Yes' else 'No')

Submission status: Runtime Error

Solution code:
n = int(input())

lastch = ''
answer = 'No'
words = []

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

print('Yes' if len(words) == len(set(words)) and answer == 'Yes' else 'No')