Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

Lists=[]
moto=0
for i in range(n):
    Lists.append(a.count(i+1))
    if ((Lists[i]>1)):
        moto+=Lists[i]*(Lists[i]-1)//2
#print(a)
#print(Lists)
#print(moto)
#print(Lists)
for i in range(n):
    if (Lists[a[i]-1]>1):
        ans=moto+1-Lists[a[i]-1]
    else:
        ans=moto
    print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
List={}
x=0
for i in range(n):
    if not a[i] in List:
        List[a[i]] = 1
    else:
        List[a[i]]+=1
    
sigma=0

for key,item in List.items():
    sigma += item*(item-1)//2
for i in range(n):
    print(sigma-List[a[i]]+1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

Lists=[]
for i in range(n):
    Lists.append(a.count(i+1))
#print(a)
#print(Lists)
moto=0
for j in range(n):
    if ((Lists[j]>1)):
        moto+=Lists[j]*(Lists[j]-1)//2

#print(moto)
#print(Lists)
for i in range(n):
    if (Lists[a[i]-1]>1):
        ans=moto+1-Lists[a[i]-1]
    else:
        ans=moto
    print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
List={}
x=0
for i in range(n):
    if not a[i] in List:
        List[a[i]] = 1
    else:
        List[a[i]]+=1
    
sigma=0

for key,item in List.items():
    sigma += item*(item-1)//2
for i in range(n):
    print(sigma-List[a[i]]+1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

Lists=[]
for i in range(n):
    Lists.append(a.count(i+1))
#print(a)
#print(Lists)
for i in range(n):
    ans=0
    Lists[(a[i])-1]-=1
    for j in range(n):
        if ((Lists[j])>1):
            ans+=Lists[j]*(Lists[j]-1)//2
    Lists[a[i]-1]+=1
    print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
List={}
x=0
for i in range(n):
    if not a[i] in List:
        List[a[i]] = 1
    else:
        List[a[i]]+=1
    
sigma=0

for key,item in List.items():
    sigma += item*(item-1)//2
for i in range(n):
    print(sigma-List[a[i]]+1)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
check=0
query=["","",""]
for i in range(q):
    query=list(map(str,input().split()))
    if (query[0]=="1"):
        check+=1
    else:
        if (query[1]=="1"):
            if (check%2==0):
                s=query[2]+s
            else:
                s=s+query[2]
        else:
            if (check%2==0):
                s=s+query[2]
            else:
                s=query[2]+s
            
print(s if check%2==0 else s[::-1])

Fixed submission:
s=input()
q=int(input())
check=0
query=["","",""]
tfel=""
right=""
for i in range(q):
    query=list(map(str,input().split()))
    if (query[0]=="1"):
        check+=1
    else:
        if (query[1]=="1"):
            if (check%2==0):
                tfel+=query[2]
            else:
                right+=query[2]
        else:
            if (check%2==0):
                right+=query[2]
            else:
                tfel+=query[2]
            
s=tfel[::-1]+s+right
print(s if check%2==0 else s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
query=["","",""]
for i in range(q):
    query=list(map(str,input().split()))
    if (query[0]=="1"):
        s=s[::-1]
    else:
        if (query[1]=="1"):
            s=query[2]+s
        else:
            s=s+query[2]
            
print(s)

Fixed submission:
s=input()
q=int(input())
check=0
query=["","",""]
tfel=""
right=""
for i in range(q):
    query=list(map(str,input().split()))
    if (query[0]=="1"):
        check+=1
    else:
        if (query[1]=="1"):
            if (check%2==0):
                tfel+=query[2]
            else:
                right+=query[2]
        else:
            if (check%2==0):
                right+=query[2]
            else:
                tfel+=query[2]
            
s=tfel[::-1]+s+right
print(s if check%2==0 else s[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[""]*n
ans=[""]

for i in range(n):
  s[i]=input()
  
  
ind=list(set(s))
num=s.count(ind[0])

for i in range(len(ind)):
  if (s.count(ind[i])>num):
    ans=[ind[i]]
    num=s.count(ind[i])
  elif (s.count(ind[i])==num and ans!=[""]):
    ans.append(ind[i])
  elif (s.count(ind[i])==num and ans==[""]):
    ans=[ind[i]]
ans=sorted(ans)
for i in range(len(ans)):
  print(ans[i])

Fixed submission:
n=int(input())
s=[""]*n
dic={}
for i in range(n):
  a=input()
  if (a in dic):
    dic[a]+=1
  else:
    dic[a]=1
#dic=sorted(dic.items(), key=lambda x:x[1], reverse=True)
v_max=max(dic.values())
keys=[k for k,v in dic.items() if v==v_max ]
keys=sorted(keys)
for i in range(len(keys)):
  print(keys[i])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[""]*n
ans=[""]

for i in range(n):
  s[i]=input()
  
  
ind=list(set(s))
num=s.count(ind[0])

for i in range(len(ind)):
  if (s.count(ind[i])>num):
    ans=[ind[i]]
    num=s.count(ind[i])
  elif (s.count(ind[i])==num and ans!=[""]):
    ans.append(ind[i])
  elif (s.count(ind[i])==num and ans==[""]):
    ans=[ind[i]]
ans=sorted(ans)
for i in range(len(ans)):
  print(ans[i])

Fixed submission:
n=int(input())
s=[""]*n
dic={}
for i in range(n):
  a=input()
  if (a in dic):
    dic[a]+=1
  else:
    dic[a]=1
#dic=sorted(dic.items(), key=lambda x:x[1], reverse=True)
v_max=max(dic.values())
keys=[k for k,v in dic.items() if v==v_max ]
keys=sorted(keys)
for i in range(len(keys)):
  print(keys[i])
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
count=0
for i in range(1000):
    if (i<10):
        num="00"+str(i)
    elif (i<100):
        num="0"+str(i)
    else:
        num=str(i)
    k=0
    flag=num[0]
    for j in range(len(s)):
        if (flag==s[j]):
            if (k<2):
                k=k+1
                flag=num[k]
            elif (k==2):
                count+=1
                #print(num)
                break
print(count)

Fixed submission:
a,b=map(int,input().split())
c,d=map(int,input().split())
print(0 if a==c else 1 )
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
count=0
for i in range(1000):
    if (i<10):
        num="00"+str(i)
    elif (i<100):
        num="0"+str(i)
    else:
        num=str(i)
    k=0
    flag=num[0]
    for j in range(len(s)):
        if (flag==s[j]):
            if (k<2):
                k=k+1
                flag=num[k]
            elif (k==2):
                count+=1
                #print(num)
                break
print(count)

Fixed submission:
n=int(input())
s=input()
count=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            num=str(i)+str(j)+str(k)
            a=s.find(num[0])
            if (a==-1):
                continue
            b=s[a+1::].find(num[1])
            if (b==-1):
                continue
            c=s[a+b+2::].find(num[2])
            if (c==-1):
                continue
            count+=1
            #print(num,a,b,c)
        ##
    ##
##
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
dat=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            dat.append(s[i]+s[j]+s[k])
print(len(list(set(dat))))

Fixed submission:
n=int(input())
s=input()
count=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            num=str(i)+str(j)+str(k)
            a=s.find(num[0])
            if (a==-1):
                continue
            b=s[a+1::].find(num[1])
            if (b==-1):
                continue
            c=s[a+b+2::].find(num[2])
            if (c==-1):
                continue
            count+=1
            #print(num,a,b,c)
        ##
    ##
##
print(count)
Buggy python submission (verdict: Runtime Error):
print(a*b if (a<10 and b<10) else -1)

Fixed submission:
a,b=map(int,input().split())
print(a*b if (a<10 and b<10) else -1)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
print(a-b*2 if (a-b*2>0) else 0)

Fixed submission:
a,b=map(int,input().split())
print(a-b*2 if (a-b*2>0) else 0)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[0]*n
b=[0]*m
c=[0]*m
a=list(map(int,input().split()))
for i in range(m):
  b[i],c[i]=map(int,input().split())
  for j in range(b[i]):
    a.append(c[i])
    
a=sorted(a,reverse=True)
print(sum(a[:n]))

Fixed submission:
n,m=map(int,input().split())
a=[0]*n
List={}
a=list(map(int,input().split()))
for i in range(n):
  List.setdefault(a[i],0)
  List[a[i]]+=1
ans=0

for i in range(m):
  b,c=map(int,input().split())
  List.setdefault(c,0)
  List[c]+=b
  
List_sorted=sorted(List, reverse=True)

#print(List)
#print(List_sorted)
for i in List_sorted:
  if (List[i]<n):
    ans+=i*List[i]
    n-=List[i]
  else:
    ans+=i*n
    break
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[0]*n
b=[0]*m
c=[0]*m
a=list(map(int,input().split()))
for i in range(m):
  b[i],c[i]=map(int,input().split())
  for j in range(b[i]):
    a.append(c[i])
    
a=sorted(a,reverse=True)
print(sum(a[:n]))

Fixed submission:
n,m=map(int,input().split())
a=[0]*n
List={}
a=list(map(int,input().split()))
for i in range(n):
  List.setdefault(a[i],0)
  List[a[i]]+=1
ans=0

for i in range(m):
  b,c=map(int,input().split())
  List.setdefault(c,0)
  List[c]+=b
  
List_sorted=sorted(List, reverse=True)

#print(List)
#print(List_sorted)
for i in List_sorted:
  if (List[i]<n):
    ans+=i*List[i]
    n-=List[i]
  else:
    ans+=i*n
    break
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

input=sys.stdin.readline

n,k=map(int,input().split())
h=[0]*n
h=list(map(int,input().split()))

dp=np.zeros(n,dtype=int)
h=np.array(h)

for i in range(1,n):
  start=max(0,i-k)
  dp[i]=min(dp[start:i] + np.abs(h[i]-h[start:i]))

print(dp[n-1])

Fixed submission:
import sys
import numpy as np

input=sys.stdin.readline

n,k=map(int,input().split())
h=[0]*n
h=list(map(int,input().split()))

dp=np.zeros(n,dtype=int)
h=np.array(h)

for i in range(1,n):
  start=max(0,i-k)
  dp[i]=min(dp[start:i] + np.abs(h[i]-h[start:i]))

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=[0]*n
h=list(map(int,input().split()))


ans=[0]*n

ans[0]=0
ans[1]=abs(h[1]-h[0])

for i in range(2,n):
  if (k==1):
    ans[i]=ans[i-1]+abs(h[i]-h[i-1])
  else:
    j=1
    check=max(h)
    while j<=k and i-j>=0:
      check=min(check,ans[i-j]+abs(h[i]-h[i-j]))
      j+=1
    ans[i]=check

print(ans[n-1])

Fixed submission:
import sys
import numpy as np

input=sys.stdin.readline

n,k=map(int,input().split())
h=[0]*n
h=list(map(int,input().split()))

dp=np.zeros(n,dtype=int)
h=np.array(h)

for i in range(1,n):
  start=max(0,i-k)
  dp[i]=min(dp[start:i] + np.abs(h[i]-h[start:i]))

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k=map(int,input().split())

for i in range(a,b+1):
  if (i<a+k or b-k<i):
    print(i)



Fixed submission:
a,b,k=map(int,input().split())

if (b-a<1000):
  for i in range(a,b+1):
    if (i<a+k or b-k<i):
      print(i)
else:
  for i in range(k):
    print(a+i)
  for i in range(k-1,-1,-1):
    print(b-i)
Buggy python submission (verdict: Runtime Error):
a=[0,0,0]
a[0],a[1],a[2]=map(int,input().split())
a=sorted(a)
sa1=a[2]-a[0]
sa2=a[2]-a[1]
if (a[0]%2==a[1]%2==a[2]%2):
  print(sa1//2 + sa2//2)
else:
  if (sa1%2==0 and sa2%2==1):
    print((sa1//2)+1 + (sa2+1)//2)
  elif (sa1%2==1 and sa2%2==0):
    print(((sa1+1)//2) (sa2//2)+1)
  else:
    print((sa2-sa1)//2+sa1)

Fixed submission:
a=[0,0,0]
a[0],a[1],a[2]=map(int,input().split())
a=sorted(a)
sa1=a[2]-a[0]
sa2=a[2]-a[1]
if (a[0]%2==a[1]%2==a[2]%2):
  print(sa1//2 + sa2//2)
else:
  if (sa1%2==0 and sa2%2==1):
    print((sa1//2)+1 + (sa2+1)//2)
  elif (sa1%2==1 and sa2%2==0):
    print(((sa1+1)//2)+(sa2//2)+1)
  else:
    print((sa2-sa1)//2+sa1)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())

ans=[[0]*w for i in range(h)]
s=[[""]*w for i in range(h)]
for i in range(h):
  s[i]=input()
  for j in range(w):
    if (s[i][j]=="#"):
      ans[i][j]="#"
      if (i-1>=0 and j-1>=0):
        ans[i-1][j-1]+=1
      if (i-1>=0):
        ans[i-1][j]+=1
      if (i-1>=0 and j+1<w):
        ans[i-1][j+1]+=1
      if (j-1>=0):
        ans[i][j-1]+=1
      if (j+1<w):
        ans[i][j+1]+=1
      if (i+1<h and j-1>=0):
        ans[i+1][j-1]+=1
      if (i+1<h):
        ans[i+1][j]+=1
      if (i+1<h and j+1<w):
      	ans[i+1][j+1]+=1
    

for i in range(h):
  answer=""
  for j in range(w):
    answer+=str(ans[i][j])
  print(answer)
    

Fixed submission:
h,w=map(int,input().split())

ans=[[0]*w for i in range(h)]
s=[[""]*w for i in range(h)]
for i in range(h):
  s[i]=input()

for i in range(h):
  for j in range(w):
    if (s[i][j]=="#"):
      ans[i][j]="#"
      if (i-1>=0 and j-1>=0):
        if (ans[i-1][j-1]!="#"):
            ans[i-1][j-1]+=1
      if (i-1>=0):
         if (ans[i-1][j]!="#"):
            ans[i-1][j]+=1
      if (i-1>=0 and j+1<w):
        if (ans[i-1][j+1]!="#"):
          ans[i-1][j+1]+=1
      if (j-1>=0):
        if (ans[i][j-1]!="#"):
          ans[i][j-1]+=1
      if (j+1<w):
        if (ans[i][j+1]!="#"):
          ans[i][j+1]+=1
      if (i+1<h and j-1>=0):
        if (ans[i+1][j-1]!="#"):
          ans[i+1][j-1]+=1
      if (i+1<h):
        if (ans[i+1][j]!="#"):
          ans[i+1][j]+=1
      if (i+1<h and j+1<w):
        if (ans[i+1][j+1]!="#"):
          ans[i+1][j+1]+=1
    

for i in range(h):
  answer=""
  for j in range(w):
    answer+=str(ans[i][j])
  print(answer)
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
print("A" if (abs(a-b)<abs(a-c)) else "B")

Fixed submission:
x,a,b=map(int,input().split())
print("A" if (abs(a-x)<abs(b-x)) else "B")
Buggy python submission (verdict: Runtime Error):
s=sorted(set(input()))
test="abcdefghijklmnopqrstuvwxyz"
for i in range(len(test)):
    if (s[i]!=test[i]):
        print(test[i])
        break
    if (s[i]==test[i] and i==len(s)-1 and i!=len(test)):
        print(test[i+1])
        break
else:
    print("None")

Fixed submission:
s=sorted(set(input()))
test="abcdefghijklmnopqrstuvwxyz"
for i in range(len(test)):
    if (s[i]!=test[i]):
        print(test[i])
        break
    if (s[i]==test[i] and i==len(s)-1 and i!=len(test)-1):
        print(test[i+1])
        break
else:
    print("None")

Buggy python submission (verdict: Runtime Error):
s=sorted(set(input()))
test="abcdefghijklmnopqrstuvwxyz"
for i in range(len(test)):
    if (s[i]!=test[i]):
        print(test[i])
        break
else:
    print("None")

Fixed submission:
s=sorted(set(input()))
test="abcdefghijklmnopqrstuvwxyz"
for i in range(len(test)):
    if (s[i]!=test[i]):
        print(test[i])
        break
    if (s[i]==test[i] and i==len(s)-1 and i!=len(test)-1):
        print(test[i+1])
        break
else:
    print("None")
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c=map(int,input().split())
num=0
while (a%2==0 and b%2==0 and c%2==0):
  a,b,c=(b//2+c//2),(a//2+c//2),(a//2+b//2)
  num+=1
  if (num>10**9):
    print(-1)
    break
else:
  print(num)

Fixed submission:
a,b,c=map(int,input().split())
num=0
while (a%2==0 and b%2==0 and c%2==0):
  a,b,c=(b//2+c//2),(a//2+c//2),(a//2+b//2)
  num+=1
  if (num>10**7):
    print(-1)
    break
else:
  print(num)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c=map(int,input().split())
num=0
while (a%2==0 and b%2==0 and c%2==0):
  a,b,c=(b//2+c//2),(a//2+c//2),(a//2+b//2)
  num+=1
  if (num>10**9):
    print(-1)
    break
else:
  print(num)

Fixed submission:
a,b,c=map(int,input().split())
num=0
while (a%2==0 and b%2==0 and c%2==0):
  a,b,c=(b//2+c//2),(a//2+c//2),(a//2+b//2)
  num+=1
  if (num>10**7):
    print(-1)
    break
else:
  print(num)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print("YES" if (b-a==c-b) else "NO)

Fixed submission:
a,b,c=map(int,input().split())
print("YES" if (b-a==c-b) else "NO")
Buggy python submission (verdict: Runtime Error):
#!/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

X, A = map(int, input().split())
if X < A:
    print(0)
else:jprint(10)


Fixed submission:
#!/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

X, A = map(int, input().split())
if X < A:
    print(0)
else:
    print(10)
Buggy python submission (verdict: Time Limit Exceeded):
#!/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

S = input()
stack = []
ans = 0
for ch in S:
    if len(stack) == 0 or stack[-1] == ch:
        stack.append(ch)
    else:
        ans += 2
        stack = stack[:-1]
print(ans)




Fixed submission:
#!/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

S = input()
stack = []
ans = 0
for ch in S:
    if len(stack) == 0 or stack[-1] == ch:
        stack.append(ch)
    else:
        ans += 2
        # stack = stack[:-1]  # 遅い??
        del stack[-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/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, M = map(int, input().split())
As = list(map(int, input().split()))

needs = [0,2,5,5,4,5,6,3,7,6]
need_to_ch = {}
for a in sorted(As):
    need = needs[a]
    need_to_ch[need] = str(a)

ans = 0
needs = list(need_to_ch.keys())
def dfs(idx, remain, used):
    global ans
    need = needs[idx]
    if idx == len(needs) - 1:
        if remain % need:
            return
        used += [remain // need]
        s = ''
        for (n, ch), use in zip(need_to_ch.items(), used):
            s += ch * use
        ans = max(ans, int(''.join(sorted(s, reverse=True))))
    else:
        for i in range(0, remain + 1, need):
            dfs(idx + 1, remain - i, used + [i // need])
dfs(0, N, [])
print(ans)


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 自力実装できず
#
# 解説PDFが理解できなかったので
# http://drken1215.hatenablog.com/entry/2019/02/16/224100
# を参考に実装

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


def str_max(s1, s2):
    if len(s1) > len(s2):
        return s1
    elif len(s1) < len(s2):
        return s2
    if s1 > s2:
        return s1
    else:
        return s2


def main():
    N, M = map(int, input().split())
    As = list(map(int, input().split()))
    
    needs = [0,2,5,5,4,5,6,3,7,6]
    need_to_ch = {}
    for a in sorted(As):
        need = needs[a]
        need_to_ch[need] = str(a)
    
    dp = [None for _ in range(N + 1)]
    dp[0] = ''
    for i in range(1, N + 1):
        for need, ch in need_to_ch.items():
            if i - need < 0 or dp[i - need] is None:
                continue
            cand = dp[i - need] + ch
            if dp[i] is None:
                dp[i] = cand
            else:
                dp[i] = str_max(dp[i], cand)
        # print("dp[{}] = {}".format(i, dp[i]))
    print(dp[N])


main()
Buggy python submission (verdict: Runtime Error):
#!/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

S = int(input())

diff = 9999
for i in range(N-2):
    s = int(S[i:i+3])
    if abs(s - 753) < diff:
        diff = s - 753
print(diff)


Fixed submission:
#!/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

S = input()

diff = 9999
for i in range(len(S)-2):
    s = int(S[i:i+3])
    if abs(s - 753) < diff:
        diff = abs(s - 753)
print(diff)
Buggy python submission (verdict: Runtime Error):

N, T = map(int, input().split())
ans = 1e9
for n in range(T):
    c, t = map(int, input().split())
    if t <= T:
        ans = min(ans, c)
if ans == 1e9:
    print('TLE')
else:
    print(ans)



Fixed submission:
N, T = map(int, input().split())
ans = 1e9
for n in range(N):
    c, t = map(int, input().split())
    if t <= T:
        ans = min(ans, c)
if ans == 1e9:
    print('TLE')
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
#!/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')
    
 


Fixed submission:
#!/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 = True
seen = set()
for n in range(N):
    w = input()
    if prev is None:
        prev = w
    else:
        if prev[-1] != w[0]:
            ok = False
    if w in seen:
        ok = False
    seen.add(w)
    prev = w
if ok:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

N, X = map(int, input().split())
Xs = map(int, input().split())
diffs = [abs(X - x) for x in Xs]
ans = reduce(gcd, diffs)
print(ans)



Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

# python3.4では存在しない!!
# from math import gcd

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

N, X = map(int, input().split())
Xs = map(int, input().split())
diffs = [abs(X - x) for x in Xs]
ans = reduce(gcd, diffs)
print(ans)