Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=b[n//2]
d=b[n//2+1]
if c==d:
  for i in range(n):print(c)
else:
  for i in range(n):
    if a[i]<=c:print(d)
    else:print(c)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
l=b[:n//2]
u=b[n//2:]
for i in a:
  if i <= l[-1]:
    print(u[0])
  else:
    print(l[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
l=b[:n//2]
u=b[n//2:]
for i in a:
  if i in l:
    print(u[0])
  else:
    print(l[-1])

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
l=b[:n//2]
u=b[n//2:]
for i in a:
  if i <= l[-1]:
    print(u[0])
  else:
    print(l[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
l=b[:n//2]
u=b[n//2:]
for i in a:
  if i in l:
    print(u[0])
  else:
    print(l[-1])

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
l=b[:n//2]
u=b[n//2:]
for i in a:
  if i <= l[-1]:
    print(u[0])
  else:
    print(l[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  if i==0:
    b=a[1:]
  elif i==n-1:
    b=a[:n-1]
  else:
    b=a[:i]+a[i+1:]
  b.sort()
  print(b[n//2-1])

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
l=b[:n//2]
u=b[n//2:]
for i in a:
  if i <= l[-1]:
    print(u[0])
  else:
    print(l[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
for i in range(n//2):
  print(a[n//2+1])
for i in range(n//2):
  print(a[n//2])


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
l=b[:n//2]
u=b[n//2:]
for i in a:
  if i <= l[-1]:
    print(u[0])
  else:
    print(l[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input()))
for i in range(n//2):
  print(a[n//2+1])
for i in range(n//2):
  print(a[n//2])

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
l=b[:n//2]
u=b[n//2:]
for i in a:
  if i <= l[-1]:
    print(u[0])
  else:
    print(l[-1])
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
if 2*k=>b-a+1:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+k):
    print(i)
  for i in range(b-k+1,b+1):
    print(i)

Fixed submission:
a,b,k=map(int,input().split())
if 2*k>=b-a+1:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+k):
    print(i)
  for i in range(b-k+1,b+1):
    print(i)
Buggy python submission (verdict: Runtime Error):
n=int(input())
de=list(map(int,input().split()))
de.insert(0,0)
de.append(0)
di=[]
for i in range(n+1):
  di.append(abs(de[i]-de[i+1]))
ans=sum(di)
for i in range(1,n+1):
  if max(de[i-1],de[i],de[i+1])==de[i] or min(de[i-1],de[i],de[i+1])==de[i]:
    print(ans-2*min(di[i],di[i+1]))
  else:
    print(ans)

Fixed submission:
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
ans=sum(abs(l[i+1]-l[i]) for i in range(n+1))
for i in range(1,n+1):
  if l[i-1]<=l[i]<=l[i+1] or l[i-1]>=l[i]>=l[i+1]:
    print(ans)
  else:
    print(ans-2*min(abs(l[i-1]-l[i]),abs(l[i+1]-l[i])))

Buggy python submission (verdict: Runtime Error):
n=int(input())
de=list(map(int,input().split()))
de.insert(0,0)
de.append(0)
di=[]
for i in range(n+1):
  di.append(abs(di[i]-di[i+1]))
ans=sum(di)
for i in range(n):
  print(ans-2*di[i])

Fixed submission:
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
ans=sum(abs(l[i+1]-l[i]) for i in range(n+1))
for i in range(1,n+1):
  if l[i-1]<=l[i]<=l[i+1] or l[i-1]>=l[i]>=l[i+1]:
    print(ans)
  else:
    print(ans-2*min(abs(l[i-1]-l[i]),abs(l[i+1]-l[i])))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
ans=0
for i in range(a,b+1):
  s=str(i)
  if i[0]==i[4] and i[1]==i[3]:
    ans+=1
print(ans)

Fixed submission:
a,b=map(int,input().split())
cnt=0
for i in range(a,b+1):
  if str(i) == str(i)[::-1]:
    cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
h,w,d=map(int,input().split())
nums=[[0 for s in range(w)] for i in range(h)]
gya=[[0,0] for i in range(h*w)]
for i in range(h):
    nums[i]=list(map(int,input().split()))
    for j in range(w):
        gya[nums[i][j]-1]=[i,j]
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    m=(r-l)//d
    ans=0
    for j in range(1,m+1):
        ans+=abs(gya[l+j*d-1][0]-gya[l+d*(j-1)-1][0])+abs(gya[l+j*d-1][1]-gya[l+d*(j-1)-1][1])
    print(ans)


Fixed submission:
print(int(input())//3)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
h,w,d=map(int,input().split())
nums=[[0 for s in range(w)] for i in range(h)]
gya=[[0,0] for i in range(h*w)]
for i in range(h):
    nums[i]=list(map(int,input().split()))
    for j in range(w):
        gya[nums[i][j]-1]=[i,j]
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    m=(r-l)//d
    ans=0
    for j in range(1,m+1):
        ans+=abs(gya[l+j*d-1][0]-gya[l+d*(j-1)-1][0])+abs(gya[l+j*d-1][1]-gya[l+d*(j-1)-1][1])
    print(ans)


Fixed submission:
h,w,d=map(int,input().split())
nums=[[0 for s in range(w)] for i in range(h)]
gya=[[0,0] for i in range(h*w)]
for i in range(h):
    nums[i]=list(map(int,input().split()))
    for j in range(w):
        gya[nums[i][j]-1]=[i,j]
cost=[0]*(h*w+d)
for i in range(d):
    s=i
    while s<h*w-d:
        cost[s+d]=cost[s]+abs(gya[s+d][0]-gya[s][0])+abs(gya[s+d][1]-gya[s][1])
        s+=d
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    print(cost[r-1]-cost[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
h,w,d=map(int,input().split())
nums=[[0 for s in range(w)] for i in range(h)]
gya=[[0,0] for i in range(h*w)]
for i in range(h):
    nums[i]=list(map(int,input().split()))
    for j in range(w):
        gya[nums[i][j]-1]=[i,j]
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    m=(r-l)//d
    ans=0
    for j in range(1,m+1):
        ans+=abs(gya[l+j*d-1][0]-gya[l+d*(j-1)-1][0])+abs(gya[l+j*d-1][1]-gya[l+d*(j-1)-1][1])
    print(ans)


Fixed submission:
h,w,d=map(int,input().split())
nums=[[0 for s in range(w)] for i in range(h)]
gya=[[0,0] for i in range(h*w)]
for i in range(h):
    nums[i]=list(map(int,input().split()))
    for j in range(w):
        gya[nums[i][j]-1]=[i,j]
cost=[0]*(h*w+d)
for i in range(d):
    s=i
    while s<h*w-d:
        cost[s+d]=cost[s]+abs(gya[s+d][0]-gya[s][0])+abs(gya[s+d][1]-gya[s][1])
        s+=d
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    print(cost[r-1]-cost[l-1])
Buggy python submission (verdict: Runtime Error):
n=input()
l=len(n)
flag=0
for i in range(l-1):
  if n[-i]!=9:
    flag=1
    break
ans=int(n[0]-1)+9*(l-1)
if flag==1:
  print(ans)
else:
  print(ans+1)
    

Fixed submission:
n=input()
l=len(n)
flag=0
for i in range(1,l):
  if n[i]!="9":
    flag=1
    break
ans=int(n[0])-1+9*(l-1)
if flag==1:
  print(ans)
else:
  print(ans+1)
Buggy python submission (verdict: Runtime Error):
num=[]
for i in range(3):
  nums.append(list(map(int,input().split())))
subd=[]
for i in range(3):
  subd.append([nums[i][0]-nums[i][1],nums[i][1]-nums[i][2]])
for i in range(3):
  subd.append([nums[0][i]-nums[1][i],nums[1][i]-nums[2][i]])
if subd[0]==subd[1] and subd[1]==subd[2] and subd[3]==subd[4] and subd[4]==subd[5]:
  print("Yes")
else:
  print("No")



Fixed submission:
nums=[]
for i in range(3):
  nums.append(list(map(int,input().split())))
subd=[]
for i in range(3):
  subd.append([nums[i][0]-nums[i][1],nums[i][1]-nums[i][2]])
for i in range(3):
  subd.append([nums[0][i]-nums[1][i],nums[1][i]-nums[2][i]])
if subd[0]==subd[1] and subd[1]==subd[2] and subd[3]==subd[4] and subd[4]==subd[5]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
from collections import deque
h,w=map(int,input().split())
field=["#" for i in range(w+2)]+[["#"]+list(input())+["#"] for i in range(h)]+["#" for i in range(w+2)]
queue=deque([[1,1]])
cost=[[50000 for i in range(w)]for j in range(h)]
cost[0][0]=0
while queue:
  now=queue.popleft()
  for i in [(-1,-1),(-1,1),(1,1),(1,-1)]:
    if field[now[0]+i[0]][now[1]+i[1]]=="#":continue
    if cost[now[0]+i[0]-1][now[1]+i[1]-1]!=50000
    if cost[now[0]+i[0]-1][now[1]+i[1]-1]>cost[now[0]-1][now[1]-1]+1:
      cost[now[0]+i[0]-1][now[1]+i[1]-1]=cost[now[0]-1][now[1]-1]+1
cnt=0
for i in range(h+2):
  for j in range(w+2):
    if field[i][j]=="#":cnt+=1
cnt-=(h+w)*2+4
blackable=h*w-cnt
if cost[-1][-1]==50000:print(-1)
else:
  print(blackable-cost[-1][-1])

Fixed submission:
from collections import deque
h,w=map(int,input().split())
field=[["#" for i in range(w+2)]]+[["#"]+list(input())+["#"] for i in range(h)]+[["#" for i in range(w+2)]]
queue=deque([[1,1]])
cost=[[50000 for i in range(w)]for j in range(h)]
cost[0][0]=0
while queue:
  now=queue.popleft()
  for i in [(-1,0),(1,0),(0,1),(0,-1)]:
    if field[now[0]+i[0]][now[1]+i[1]]=="#":continue
    if cost[now[0]+i[0]-1][now[1]+i[1]-1]!=50000:continue
    queue.append((now[0]+i[0],now[1]+i[1]))
    cost[now[0]+i[0]-1][now[1]+i[1]-1]=cost[now[0]-1][now[1]-1]+1
cnt=0
for i in range(h+2):
  for j in range(w+2):
    if field[i][j]=="#":cnt+=1
cnt-=(h+w)*2+4
blackable=h*w-cnt
if cost[-1][-1]==50000:print(-1)
else:
  print(blackable-cost[-1][-1]-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=0;r=n-1
print(0);seat0=input()
if seat0="Vacant";exit()
while True:
  mid=(l+r)//2
  print(mid)
  seat=input()
  if seat=="Vacant":
    exit()
  if mid%2==0:
    if seat!=seat0:
      r=mid
    else:
      l=mid
  elif mid%2==1:
    if seat==seat0:
      l=mid
    else:
      r=mid
 


Fixed submission:
x,y=map(int,input().split())
if x%y==0:
  print(-1)
else:
  flag=0
  for i in range(10**18//x):
    if (i*x)%y!=0:
      print(i*x)
      flag=1
      break
  if flag==0:
    print(-1)

Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split)
if x%y==0:
  print(-1)
else:
  flag=0
  for i in range(10**18//x):
    if (i*x)%y!=0:
      print(i*x)
      flag=1
      break
    if flag==0:
      print(-1)

Fixed submission:
x,y=map(int,input().split())
if x%y==0:
  print(-1)
else:
  flag=0
  for i in range(10**18//x):
    if (i*x)%y!=0:
      print(i*x)
      flag=1
      break
  if flag==0:
    print(-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[]
ans=0
for i in range(2):
l.append(list(map(int,input().split())))
for i in range(n):
  c=sum(l[0][:i+1])+sum(l[1][i:])
  if c>ans:ans=c
print(ans)

Fixed submission:
n=int(input())
l=[]
ans=0
for i in range(2):
  l.append(list(map(int,input().split())))
for i in range(n):
  c=sum(l[0][:i+1])+sum(l[1][i:])
  if c>ans:ans=c
print(ans)
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
ans=0
def digitsum(n):
  l=len(str(n))
  re=0
  for i in range(l):
    re+=int(str(n[i]))
  return re
for i in range(n):
  if a<=digitsum(i)<=b:
    ans+=i
print(ans)


Fixed submission:
n,a,b=map(int,input().split())
ans=0
def digitsum(n):
  l=len(str(n))
  re=0
  for i in range(l):
    re+=int(str(n)[i])
  return re
for i in range(n+1):
  if a<=digitsum(i)<=b:
    ans+=i
print(ans)

Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
ans=0
def digitsum(n):
  l=len(str(n))
  re=0
  for i in range(l):
    re+=int(str(n[i]))
  return re
for i in range(n):
  if a<=digitsum(i)<=b:
    ans+=i
print(i)

Fixed submission:
n,a,b=map(int,input().split())
ans=0
def digitsum(n):
  l=len(str(n))
  re=0
  for i in range(l):
    re+=int(str(n)[i])
  return re
for i in range(n+1):
  if a<=digitsum(i)<=b:
    ans+=i
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
c=b.most_common()
ans=0
for i in range(len(c)):
  ans+=abs(int(c[0])-c[1])
print(ans)

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
c=b.most_common()
ans=0
for i in range(len(c)):
  if c[i][0]>c[i][1]:
    ans+=c[i][1]
  else:
    ans+=c[i][1]-c[i][0]
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
nums = list(map(int,input().split()))
nums.sort()
dif = []
cnt=[]
for i in range(N-1):
  if nums[i] != nums[i+1]:
    dif.append(i+1) #玉の番号の変わり目を記録する
for i in range(len(dif)+1):
  if i == 0:
    cnt.append(dif[0])
  if i == len(dif):
    cnt.append(N-dif[-1])
    break
  cnt.append(dif[i]-dif[i-1])
cnt.sort(reverse=True)#それぞれの球が何個ずつあるかのリスト作成
n = 0
if len(cnt)<=K:
  print(0)
else:
  for i in range(K):
    n+=cnt[i]
  print(N-n)
  
    
  


Fixed submission:
N,K = map(int,input().split())
nums = list(map(int,input().split()))
nums.sort()
dif = []
cnt=[]
for i in range(N-1):
  if nums[i] != nums[i+1]:
    dif.append(i+1) #玉の番号の変わり目を記録する
if len(dif)==0:
  print(0)
else:
  for i in range(len(dif)+1):
    if i == 0:
      cnt.append(dif[0])
    if i == len(dif):
      cnt.append(N-dif[-1])
      break
    cnt.append(dif[i]-dif[i-1])
  cnt.sort(reverse=True)#それぞれの球が何個ずつあるかのリスト作成
  n = 0
  if len(cnt)<=K:
    print(0)
  else:
    for i in range(K):
      n+=cnt[i]
    print(N-n)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
nums = list(map(int,input().split()))
nums.sort()
dif = []
cnt=[]
for i in range(N-1):
  if nums[i] != nums[i+1]:
    dif.append(i+1) #玉の番号の変わり目を記録する
for i in range(len(dif)+1):
  if i == 0:
    cnt.append(dif[0])
  if i == len(dif):
    cnt.append(N-dif[-1])
  cnt.append(dif[i]-dif[i-1])
cnt.sort(reverse=True)#それぞれの球が何個ずつあるかのリスト作成
n = 0
if len(cnt)<=K:
  print(0)
else:
  for i in range(K):
    n+=cnt[i]
  print(N-n)
  
    
  

Fixed submission:
N,K = map(int,input().split())
nums = list(map(int,input().split()))
nums.sort()
dif = []
cnt=[]
for i in range(N-1):
  if nums[i] != nums[i+1]:
    dif.append(i+1) #玉の番号の変わり目を記録する
if len(dif)==0:
  print(0)
else:
  for i in range(len(dif)+1):
    if i == 0:
      cnt.append(dif[0])
    if i == len(dif):
      cnt.append(N-dif[-1])
      break
    cnt.append(dif[i]-dif[i-1])
  cnt.sort(reverse=True)#それぞれの球が何個ずつあるかのリスト作成
  n = 0
  if len(cnt)<=K:
    print(0)
  else:
    for i in range(K):
      n+=cnt[i]
    print(N-n)
Buggy python submission (verdict: Runtime Error):
s=input()
a=int(s[0]);b=int(s[1]);c=int(s[2]);d=int(s[3])
if a+b+c+d==7:
  print(str(a)+"+"str(b)+"+"str(c)+"+"+str(d)+"=7")
  break
elif a+b+c-d==7:
  print(str(a)+"+"str(b)+"+"str(c)+"-"+str(d)+"=7")
  break
elif a+b-c+d==7:
  print(str(a)+"+"str(b)+"-"str(c)+"+"+str(d)+"=7")
  break
elif a+b-c-d==7:
  print(str(a)+"+"str(b)+"-"str(c)+"-"+str(d)+"=7")
  break
elif a-b+c+d==7:
  print(str(a)+"-"str(b)+"+"str(c)+"+"+str(d)+"=7")
  break
elif a-b+c-d==7:
  print(str(a)+"-"str(b)+"+"str(c)+"-"+str(d)+"=7")
  break
elif a-b-c+d==7:
  print(str(a)+"-"str(b)+"-"str(c)+"+"+str(d)+"=7")
  break
elif a-b-c-d==7:
  print(str(a)+"-"str(b)+"-"str(c)+"-"+str(d)+"=7")
  break

Fixed submission:
import sys
s=input()
a=int(s[0]);b=int(s[1]);c=int(s[2]);d=int(s[3])
if a+b+c+d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
  sys.exit()
elif a+b+c-d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
  sys.exit()
elif a+b-c+d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
  sys.exit()
elif a+b-c-d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
  sys.exit()
elif a-b+c+d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
  sys.exit()
elif a-b+c-d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
  sys.exit()
elif a-b-c+d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
  sys.exit()
elif a-b-c-d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
  sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(n):
  ans+=sum(x<b[i] for x in a)*sum(x>b[i] for x in c)
print(ans)

Fixed submission:
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
  d=bisect.bisect_left(a,b[i])
  e=bisect.bisect_right(c,b[i])
  ans+=d*(n-e)
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if S[i+j]=="?":
      continue
    if S[i+j]!=T[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    posstr.replace("?","a")
    strs.append(posstr)
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])

Fixed submission:
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if s[i+j]=="?":
      continue
    if s[i+j]!=t[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    strs.append(posstr.replace("?","a",50))
strs.sort()
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
field=[]
nfield=[[] for i in range(h)]
for i in range(n):
  field.append(input())
def check(a,b):
  num=0
  if field[a][b]=="#":
    return
  for i in range(a-1,a+2):
    for j in range(b-1,b+2):
      try:
        if field[i][j]=="#":
          num+=1
      except:
        pass
  return num
for i in range(h):
  for j in range(w):
    if field[i][j]==".":
      nfield[i][j]=check(i,j)
    else:
      nfield[i][j]="#"
for i in range(h):
  for j in range(w):
    if j != w-1:
      print(nfield[i],end="")
    else:
      print(nfield[i])


Fixed submission:
h,w=map(int,input().split())
field=[]
nfield=[[] for i in range(h)]
for i in range(h):
  field.append(input())
def check(a,b):
  num=0
  if field[a][b]=="#":
    return
  for i in range(a-1,a+2):
    for j in range(b-1,b+2):
      try:
        if j !=-1 and i!=-1 and field[i][j]=="#":
          num+=1
      except:
        pass
  return num
for i in range(h):
  for j in range(w):
    if field[i][j]==".":
      nfield[i].append(check(i,j))
    else:
      nfield[i].append("#")
for i in range(h):
  for j in range(w):
    if j != w-1:
      print(nfield[i][j],end="")
    else:
      print(nfield[i][j])

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
field=[]
for i in range(n):
  field.append(input())
def check(a,b):
  num=0
  if field[a][b]=="#":
    return
  for i in range(a-1,a+2):
    for j in range(b-1,b+2):
      try:
        if field[i][j]=="#":
          num+=1
      except:
        pass
  return num
for i in range(h):
  for j in range(w):
    if field[i][j]==".":
      field[i][j]==check(i,j)
for i in range(h):
  print(field[i])

Fixed submission:
h,w=map(int,input().split())
field=[]
nfield=[[] for i in range(h)]
for i in range(h):
  field.append(input())
def check(a,b):
  num=0
  if field[a][b]=="#":
    return
  for i in range(a-1,a+2):
    for j in range(b-1,b+2):
      try:
        if j !=-1 and i!=-1 and field[i][j]=="#":
          num+=1
      except:
        pass
  return num
for i in range(h):
  for j in range(w):
    if field[i][j]==".":
      nfield[i].append(check(i,j))
    else:
      nfield[i].append("#")
for i in range(h):
  for j in range(w):
    if j != w-1:
      print(nfield[i][j],end="")
    else:
      print(nfield[i][j])
Buggy python submission (verdict: Runtime Error):
N=int(input())
for w in range(1,3501):
  for n in range(1,3501):
    if N*w*n%(4*w*n-N*n-N*w)==0:
      print(N*w*n//(4*w*n-N*n-N*w),w,n)
      break


Fixed submission:
N=int(input())
flag=0
for w in range(1,3501):
  if flag==1:
    break
  for n in range(1,3501):
    if 4*w*n-N*n-N*w<=0:
      continue
    if N*w*n%(4*w*n-N*n-N*w)==0:
      print(N*w*n//(4*w*n-N*n-N*w),w,n)
      flag=1
      break
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
a={}
for i in range(26):
  a[chr(i+97)]=0
for i in range(h):
  s=input()
  for j in s:
    a[j]+=1
if h==1 and w==1:print("Yes")
elif h==1 or w==1:
  cnt=0
  for i in a.values():
    if i%2==1:cnt+=1
  if cnt!=1:print("No")
  else:print("Yes")
elif h%2==0 and w%2==0:
  for i in a.values():
    if i%4!=0:print("No");exit()
  print("Yes")
elif h%2==1 and w%2==0:
  cnt=0
  for i in a.values():
    if i%4==1 or i%4==3:
      print("No");exit()
    if i%4==2:cnt+=1
  if cnt>w//2:
    print("No")
  else:print("Yes")
elif h%2==0 and w%2==1:
  cnt=0
  for i in a.values():
    if i%4==1 or i%4==3:
      print("No");exit()
    if i%4==2:cnt+=1
  if cnt>h//2:
    print("No")
  else:print("Yes")
else:
  cnt3=0;cnt2=0;cnt1=0
  for i in a.values():
    if i%4==1:cnt1+=1
    elif i%4==2:cnt2+=1
    elif i%4==3:cnt3+=1
  rem=1-cnt1
  elif cnt1+cnt3!=1:print("No")
  elif cnt2+cnt3>h+w-2:print("No")
  else:
    print("Yes")


Fixed submission:
s=input()
if len(s)<=3:
  print("No")
else:
  if s[0:4]=="YAKI":
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
n,m,r=map(int,input().split())
visit=list(map(int,input().split()))
dist=[[10**9]*n for i in range(n)]
for i in range(m):
  a,b,c=map(int,input().split())
  dist[a-1][b-1],dist[b-1][a-1]=c,c
for i in range(n):
  dist[i-1][i-1]=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k])
ans=10**9
check=permutations(visit)
for i in check:
  c=0
  for j in range(1,r):
    c+=dist[i[j-1]-1][i[j]-1]
  if c<ans:ans=c
print(ans)


Fixed submission:
from itertools import permutations
n,m,r=map(int,input().split())
visit=list(map(int,input().split()))
dist=[[10**9]*n for i in range(n)]
for i in range(m):
  a,b,c=map(int,input().split())
  dist[a-1][b-1],dist[b-1][a-1]=c,c
for i in range(n):
  dist[i-1][i-1]=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k])
ans=10**9
check=permutations(visit)
for i in check:
  c=0
  for j in range(1,r):
    c+=dist[i[j-1]-1][i[j]-1]
  if c<ans:ans=c
print(ans)

Buggy python submission (verdict: Runtime Error):
from itertools import permutations
n,m,r=map(int,input().split())
visit=list(map(int,input().split()))
dist=[[10**9]*n for i in range(n)]
for i in range(m):
  a,b,c=map(int,input().split())
  dist[a-1][b-1],dist[b-1][a-1]=c,c
for i in range(n):
  dist[i-1][i-1]=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      dist[j][k]=min(dist[j][i]+dist[i][k])
ans=10**9
check=permutations(visit)
for i in check:
  c=0
  for j in range(r-1):
    c+=dist[i[j]][i[j+1]]
  if c<ans:ans=c
print(ans)

Fixed submission:
from itertools import permutations
n,m,r=map(int,input().split())
visit=list(map(int,input().split()))
dist=[[10**9]*n for i in range(n)]
for i in range(m):
  a,b,c=map(int,input().split())
  dist[a-1][b-1],dist[b-1][a-1]=c,c
for i in range(n):
  dist[i-1][i-1]=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k])
ans=10**9
check=permutations(visit)
for i in check:
  c=0
  for j in range(1,r):
    c+=dist[i[j-1]-1][i[j]-1]
  if c<ans:ans=c
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
cnt=0
for i in range(n):
  if l[i] == i+1:
    change=l[i]
    l[i]=l[i+1]
    l[i+1]=change
    cnt+=1
print(cnt)


Fixed submission:
x,t=map(int,input().split())
print(max(x-t,0))
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
l.sort()
a=[0]*(l[-1]-l[0]+3)
for i in range(n):
  l[i]-=l[0]
for i in range(n):
  a[l[i]]+=1
  a[l[i]+1]+=1
  a[l[i]+2]+=1
print(max(a))

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l.sort()
a=[0]*(l[-1]-l[0]+3)
b=l[0]
for i in range(n):
  l[i]-=b
for i in range(n):
  a[l[i]]+=1
  a[l[i]+1]+=1
  a[l[i]+2]+=1
print(max(a))