Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import time

n=int(input())
x=(n%15)*0.001*100
a=0.037
#time.sleep(x+a)
ls=[1 for i in range((n%100)*10**6)]
print('Yes')

Fixed submission:
x=int(input())
s=str(x)
keta=0
for i in s:
  keta+=int(i)
if x%keta==0:
  ans='Yes'
else:
  ans='No'
print(ans)

Buggy python submission (verdict: Runtime Error):
import time

n=int(input())
x=(n%15)*0.001*100
a=0.037
#time.sleep(x+a)
ls=[for i in range((n%100)*10**6)]
print('Yes')

Fixed submission:
x=int(input())
s=str(x)
keta=0
for i in s:
  keta+=int(i)
if x%keta==0:
  ans='Yes'
else:
  ans='No'
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
print(‘Yes’ if (n//10)%111==0 or (n%1000)%111==0 else ‘No’)


Fixed submission:
n=int(input())
print('Yes' if (n//10)%111==0 or (n%1000)%111==0 else 'No')
Buggy python submission (verdict: Runtime Error):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
graph=[]
h,w=map(int,input().split())
for i in range(10):
    graph.append(list(map(int,input().split())))
graph = csr_matrix(graph)

d, p = floyd_warshall(csgraph=graph, directed=True, return_predecessors=True)
#print(d)
dic={-1:0}
for i in range(10):
    dic[i]=d[i][1]
ans=0
for i in range(h):
    for j in map(int,input().split()):
        ans+=dic[j]
print(int(ans))


Fixed submission:
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
graph=[]
h,w=map(int,input().split())
for i in range(10):
    graph.append(list(map(int,input().split())))
graph = csr_matrix(graph)

d, p = floyd_warshall(csgraph=graph, directed=True, return_predecessors=True)
#print(d)
dic={-1:0}
for i in range(10):
    dic[i]=d[i][1]
ans=0
for i in range(h):
    for j in map(int,input().split()):
        ans+=dic[j]
print(int(ans))

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
graph=[]
h,w=map(int,input().split())
for i in range(10):
    graph.append(list(map(int,input().split())))
graph = csr_matrix(graph)

d, p = floyd_warshall(csgraph=graph, directed=True, return_predecessors=True)
#print(d)
dic={-1:0}
for i in range(10):
    dic[i]=d[i][1]
ans=0
for i in range(h):
    for j in map(int,input().split()):
        ans+=dic[j]
print(int(ans))

Fixed submission:
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
graph=[]
h,w=map(int,input().split())
for i in range(10):
    graph.append(list(map(int,input().split())))
graph = csr_matrix(graph)

d, p = floyd_warshall(csgraph=graph, directed=True, return_predecessors=True)
#print(d)
dic={-1:0}
for i in range(10):
    dic[i]=d[i][1]
ans=0
for i in range(h):
    for j in map(int,input().split()):
        ans+=dic[j]
print(int(ans))
Buggy python submission (verdict: Runtime Error):
n,z,w=map(int,input().split())
a=[int(i) for i in input().split()]
if n>=2:
    print(max(abs(a[-1]-w),abs(a[-1]-a[-2]) ))
else:
    print(max(abs(a[-1]-w)))

Fixed submission:
n,z,w=map(int,input().split())
a=[int(i) for i in input().split()]
if n>=2:
    print(max(abs(a[-1]-w),abs(a[-1]-a[-2]) ))
else:
    print(abs(a[-1]-w))

Buggy python submission (verdict: Runtime Error):
n,z,w=map(int,input().split())
a=[int(i) for i in input().split()]
print(max(abs(a[-1]-w),abs(a[-1]-a[-2]) ))


Fixed submission:
n,z,w=map(int,input().split())
a=[int(i) for i in input().split()]
if n>=2:
    print(max(abs(a[-1]-w),abs(a[-1]-a[-2]) ))
else:
    print(abs(a[-1]-w))

Buggy python submission (verdict: Runtime Error):
n,z,w=map(int,input())
a=[int(i) for i in input().split()]
print(max(abs(a[-1]-w),abs(a[-1]-a[-2])))

Fixed submission:
n,z,w=map(int,input().split())
a=[int(i) for i in input().split()]
if n>=2:
    print(max(abs(a[-1]-w),abs(a[-1]-a[-2]) ))
else:
    print(abs(a[-1]-w))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

s=input()
t=input()
if len(s)-len(t)<0:
    flg=False
else:
    for i in range(len(s)-len(t)):
        ans=s
        for j in range(len(t)):
            flg=True
            if t[-1-j]==s[-1-j-i] or s[-1-j-i]=='?':
                #print(ans)
                ans=ans[:-1-j-i]+t[-1-j]+('' if -1-i-j+1==0 else ans[-1-i-j+1:])
            else:
                flg=False
                break
        if flg==True:
            break
ans=ans.replace('?','a')
print(ans if flg else 'UNRESTORABLE')

Fixed submission:
# coding: utf-8
# Your code here!

s=input()
t=input()
b=[]

if len(s)-len(t)<0:
    flg=False
else:
    for i in range(len(s)-len(t)+1):
        ans=s
        for j in range(len(t)):
            flg=True
            if s[i+j]=='?' or s[i+j]==t[j]:
                #print(ans)
                ans=ans[:i+j]+t[j]+('' if i+j+1>len(s) else ans[i+j+1:])
            else:
                flg=False
                break
        if flg==True:
            b.append(ans.replace('?','a'))
#print(b)
b.sort()

print(b[0] if len(b)>0 else 'UNRESTORABLE')

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

s=input()
t=input()

for i in range(len(s)-len(t)):
    ans=s
    for j in range(len(t)):
        flg=True
        if t[-1-j]==s[-1-j-i] or s[-1-j-i]=='?':
            #print(ans)
            ans=ans[:-1-j-i]+t[-1-j]+('' if -1-i-j+1==0 else ans[-1-i-j+1:])
        else:
            flg=False
            break
    if flg==True:
        break
ans=ans.replace('?','a')
print(ans if flg else 'UNRESTORABLE')

Fixed submission:
# coding: utf-8
# Your code here!

s=input()
t=input()
b=[]

if len(s)-len(t)<0:
    flg=False
else:
    for i in range(len(s)-len(t)+1):
        ans=s
        for j in range(len(t)):
            flg=True
            if s[i+j]=='?' or s[i+j]==t[j]:
                #print(ans)
                ans=ans[:i+j]+t[j]+('' if i+j+1>len(s) else ans[i+j+1:])
            else:
                flg=False
                break
        if flg==True:
            b.append(ans.replace('?','a'))
#print(b)
b.sort()

print(b[0] if len(b)>0 else 'UNRESTORABLE')
Buggy python submission (verdict: Runtime Error):
print('YNeos'[['AC' not in input()]::2])

Fixed submission:
print(' YNeos'['AC'in input()::2])
Buggy python submission (verdict: Runtime Error):
print(input().replace('FESTIVAL','')

Fixed submission:
print(input()[:-8])
Buggy python submission (verdict: Runtime Error):
print(eval(open(0).read().replace(' ','**2-')))

Fixed submission:
print(eval(input()+'**2-'+input()))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
r=0
t=0
while t<n:
    if a[t]==t+1:
            r+=1
      t+=1+r
print(r)


Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]

ans=0
t=0
while t<n:
    if a[t]==t+1:
        if t+1<n and a[t+1]==t+2:
            ans+=1
            t+=2
        else:
            ans+=1
            t+=2
    else:
        t+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
c

Fixed submission:
n,m=map(int,input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Runtime Error):
a1,a2,a4=0,0,0

for i in range(1):
    # Start Input code ---------------------------------------
    n=int(input())
    for i in range(n):
        x=int(input())
        if x%4==0:
            a4+=1
        elif x%2==0:
            a2=1
        else:
            a1+=1
ans='Yes' if a1+a2<=a4+1 else 'No'
print(ans)


Fixed submission:
a1,a2,a4=0,0,0

for i in range(1):
    # Start Input code ---------------------------------------
    n=int(input())
    y=map(int,input().split())
    for x in y:
        
        if x%4==0:
            a4+=1
        elif x%2==0:
            a2=1
        else:
            a1+=1
ans='Yes' if a1+a2<=a4+1 else 'No'
print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import sys
def input():
    return sys.stdin.readline()
n,m=map(int,input().split())
a=[0]*(n+1)
b=[0]*(n+1)
c=[0]*(n+1)
f1=[]
f2=[]
for i in range(m):
    a[i],b[i]=map(int,input().split())
    if a[i]==1:
        c[b[i]]=1

ans='IMPOSSIBLE'
for i in range(m):
    if b[i]==n:
        if c[a[i]]==1:
            ans='POSSIBLE'
print(ans)


Fixed submission:
# coding: utf-8
# Your code here!
import sys
def input():
    return sys.stdin.readline()
n,m=map(int,input().split())
a=[0]*(m+1)
b=[0]*(m+1)
c=[0]*(n+1)
f1=[]
f2=[]
for i in range(m):
    a[i],b[i]=map(int,input().split())
    if a[i]==1:
        c[b[i]]=1

ans='IMPOSSIBLE'
for i in range(m):
    if b[i]==n:
        if c[a[i]]==1:
            ans='POSSIBLE'
print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import sys
def input():
    return sys.stdin.readline()
n,m=map(int,input().split())
a=[0]*(n+1)
b=[0]*(n+1)
f1=[]
f2=[]
for i in range(m):
    a[i],b[i]=map(int,input().split())
    if a[i]==1:
        f1.append(b[i])
    if b[i]==n:
        f2.append(i)
        

ans='IMPOSSIBLE'
for i in f2:
    if a[i] in f1:
        ans='POSSIBLE'
print(ans)


Fixed submission:
# coding: utf-8
# Your code here!
import sys
def input():
    return sys.stdin.readline()
n,m=map(int,input().split())
a=[0]*(m+1)
b=[0]*(m+1)
c=[0]*(n+1)
f1=[]
f2=[]
for i in range(m):
    a[i],b[i]=map(int,input().split())
    if a[i]==1:
        c[b[i]]=1

ans='IMPOSSIBLE'
for i in range(m):
    if b[i]==n:
        if c[a[i]]==1:
            ans='POSSIBLE'
print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
a=[0]*(n+1)
b=[0]*(n+1)
f1=[]
f2=[]
for i in range(m):
    a[i],b[i]=map(int,input().split())
    if a[i]==1:
        f1.append(b[i])
    if b[i]==n:
        f2.append(i)
        

ans='IMPOSSIBLE'
for i in f2:
    if a[i] in f1:
        ans='POSSIBLE'
print(ans)


Fixed submission:
# coding: utf-8
# Your code here!
import sys
def input():
    return sys.stdin.readline()
n,m=map(int,input().split())
a=[0]*(m+1)
b=[0]*(m+1)
c=[0]*(n+1)
f1=[]
f2=[]
for i in range(m):
    a[i],b[i]=map(int,input().split())
    if a[i]==1:
        c[b[i]]=1

ans='IMPOSSIBLE'
for i in range(m):
    if b[i]==n:
        if c[a[i]]==1:
            ans='POSSIBLE'
print(ans)

Buggy python submission (verdict: Runtime Error):

n,m=map(int,input().split())
a=[0]*(n+1)
b=[0]*(n+1)
pos=[]
for i in range(m):
    a[i],b[i]=map(int,input().split())
    if a[i]==1:
        pos.append(b[i])

ans='IMPOSSIBLE'
for i in range(m):
    if b[i]==n:
        if a[i] in pos:
            ans='POSSIBLE'
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
import sys
def input():
    return sys.stdin.readline()
n,m=map(int,input().split())
a=[0]*(m+1)
b=[0]*(m+1)
c=[0]*(n+1)
f1=[]
f2=[]
for i in range(m):
    a[i],b[i]=map(int,input().split())
    if a[i]==1:
        c[b[i]]=1

ans='IMPOSSIBLE'
for i in range(m):
    if b[i]==n:
        if c[a[i]]==1:
            ans='POSSIBLE'
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
n=len(s)
print(max([n-i for i in range(0,n//2,2) if  s[:(n-i)//2]==s[(n-i)//2:-i]]))

Fixed submission:
s=input()
n=len(s)
print(max([n-i for i in range(2,n,2)if s[:(n-i)//2]==s[(n-i)//2:-i]]))

Buggy python submission (verdict: Runtime Error):
s=input()
n=len(s)
print(max([n-i for i in range(0,n//2,2) if  s[:(n-i)//2]==s[(n-i)//2:-i]]))

Fixed submission:
s=input()
n=len(s)
print(max([n-i for i in range(2,n,2)if s[:(n-i)//2]==s[(n-i)//2:-i]]))

Buggy python submission (verdict: Runtime Error):
s=input()
n=len(s)
prnt(max([n-i for i in range(0,n//2,2) if  s[:(n-i)//2]==s[(n-i)//2:-i]]))

Fixed submission:
s=input()
n=len(s)
print(max([n-i for i in range(2,n,2)if s[:(n-i)//2]==s[(n-i)//2:-i]]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import string
from collections import Counter
mo=10**9+7
sys.setrecursionlimit(10000000)
alp=string.ascii_uppercase

n=int(input())
a=[int(i) for i in input().split()]
#print(len(a),a)
c=Counter(a)
db=c.most_common()[0][0]
#print(db)
fst=a.index(db)
lst=a.index(db,fst+1)
x=n+1-(lst-fst+1)
#print(fst,lst)

cn=[0]*(n+1+1)
cn[0]=1
cx=[0]*(x+1)
cx[0]=1
def com1(k):
    if k>n+1 or k<0:
        return 0
    if cn[k]!=0:
        return cn[k]
    cn[k]=(n+1-k+1)*cn[k-1]//k
    return cn[k]
    
def com2(k):
    if k>x or k<0:
        return 0
    if cx[k]!=0:
        return cx[k]
    cx[k]=(x-k+1)*cx[k-1]//k
    return cx[k]
    
for i in range(1,n+2):
    ans=com1(i)-com2(i-1)
    print(ans%mo)#,com1(i),com2(i-1))

Fixed submission:
import time
st_time=time.time()

from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
ts=time.time()
sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
show_flg=True

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(2,n+1):
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        if self.fac[n]!=0:
            return self.fac[n]
        self.fac[n]=n*self.fact(n-1)%mo
        return self.fac[n]

    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo
    
n=int(input())
a=[int(i) for i in input().split()]

cm=Comb(n+1)
c=Counter(a)
db=c.most_common()[0][0]
fst=a.index(db)
lst=a.index(db,fst+1)
x=n+1-(lst-fst+1)

for i in range(1,n+2):
    ans=cm.comb(n+1,i)-cm.comb(x,i-1)
    print(ans%mo)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit
mo=10**9+7
def fact(x):
  if x==0:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((2*fact(m)*fact(n))%mo)
else:
  print((fact(m)*fact(n))%mo)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
mo=10**9+7
def fact(x):
  if x==0:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((2*fact(m)*fact(n))%mo)
else:
  print((fact(m)*fact(n))%mo)

Buggy python submission (verdict: Runtime Error):
mo=10**9+7
def fact(x):
  if x==0:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((2*fact(m)*fact(n))%mo)
else:
  print((fact(m)*fact(n))%mo)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
mo=10**9+7
def fact(x):
  if x==0:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((2*fact(m)*fact(n))%mo)
else:
  print((fact(m)*fact(n))%mo)

Buggy python submission (verdict: Runtime Error):
mo=10**9+7
def fact(x):
  if x==1:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((2*fact(m)*fact(n))%mo)
else:
  print((fact(m)*fact(n))%mo)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
mo=10**9+7
def fact(x):
  if x==0:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((2*fact(m)*fact(n))%mo)
else:
  print((fact(m)*fact(n))%mo)

Buggy python submission (verdict: Runtime Error):
mo=10**9+7
def fact(x):
  if x==1:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((fact(m)*fact(n)*2)%mo)
else:
  print(fact(m)*fact(n)%mo)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
mo=10**9+7
def fact(x):
  if x==0:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((2*fact(m)*fact(n))%mo)
else:
  print((fact(m)*fact(n))%mo)

Buggy python submission (verdict: Runtime Error):
mo=10**9+7
def fact(x):
  if x==1:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((fact(m)*fact(n)*2)%mo)
else:
  print(fact(m)*fact(n))

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
mo=10**9+7
def fact(x):
  if x==0:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((2*fact(m)*fact(n))%mo)
else:
  print((fact(m)*fact(n))%mo)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print('YNEOS'[(b*10+c%)4!=0::2])

Fixed submission:
a,b,c=map(int,input().split())
print('YNEOS'[(b*10+c)%4!=0::2])
Buggy python submission (verdict: Runtime Error):
g


Fixed submission:
a,b=map(int,input().split())
if a+b>=10:
  ans='error'
else:
  ans=a+b
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    x=int(input())
    c.append(x)
    
dp=[0]
for i in range(n):
    tmp=dp
    for v in tmp:
        dp.append(v+c[i])
#dp.sort()[::-1]
ans=0
for i in dp:
    if dp[i]%10!=0:
        ans=max(dp[i],ans) 
print(ans)



Fixed submission:
n=int(input())
a=[]
b=[]
for i in range(n):
  x=int(input())
  if x%10==0:
    b.append(x)
  else:
    a.append(x)
a.sort()
ans=sum(a)+sum(b)
if ans%10==0:
  if len(a)>0:
    ans-=a[0]
  else:
    ans=0
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]
b=[]
for i in range(n):
  x=int(input())
  c.append(x)
  if x%10==0:
    b.append(x)
  else:
    a.append(x)
a.sort()
ans=sum(a)+sum(b)
if ans%10==0:
  if len(a)>0:
    ans-=a[0]
  else:
    ans=0

    
dp=[0]
for i in range(n):
  for v in dp:
    dp.append(v+c[i])
#dp.sort()[::-1]
ans=0
for i in dp:
  if dp[i]%10!=0:
    ans=max(dp[i],ans) 
print(ans)

Fixed submission:
n=int(input())
a=[]
b=[]
for i in range(n):
  x=int(input())
  if x%10==0:
    b.append(x)
  else:
    a.append(x)
a.sort()
ans=sum(a)+sum(b)
if ans%10==0:
  if len(a)>0:
    ans-=a[0]
  else:
    ans=0
print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    x=int(input())
    h.append(x)

def check(t):
    c=0
    for i in range(n):
        c+=1+(max(0,h[i]-b*t)-1)//(a-b)
    return t>=c

l=1
r=1+max(h)//b
while r-l>1:
    mid=(r-l)//2+l
    if check(mid):
        r=mid
    else:
        l=mid
ans=l
if check(r):
    #ans=r
print(ans)



Fixed submission:
# coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    x=int(input())
    h.append(x)

def check(t):
    c=0
    for i in range(n):
        c+=1+(max(0,h[i]-b*t)-1)//(a-b)
    return t>=c

l=0
r=3+max(h)//b
while r-l>1:
    mid=(r-l)//2+l
    if check(mid):
        r=mid
    else:
        l=mid
ans=l
if check(r):
    ans=r
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split());print('
NYoe s'[a<=c<=b::2])

Fixed submission:
a,b,c=map(int,input().split());print('NYoe s'[a<=c<=b::2])
Buggy python submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
b=[]
v=[[0]*w for _ in range(h)]
sh=0
sw=0
for i in range(h):
    s=list(input())
    b.append(s)
    
    if 'S' in s:
        sh=i
        sw=s.index('S')
#ans=10**18
d=[[0,1],[1,0],[-1,0],[0,-1]]

def bfs(y,x):
    ans=10**18
    c=0
    q=[(y,x)]
    v[y][x]=1
    while c<k:
        p=[]
        c+=1
        for i,j in q:
            for di,dj in d:
                if v[i+di][j+dj]!=1 and b[i+di][j+dj]!='#' and 0<=i+di<h and 0<=j+dj<w:
                    p.append((i+di,j+dj))
                    v[i+di][j+dj]=1
                    ans=min(ans,i+di,j+dj,h-1-i-di,w-1-j-dj)
        q=p
    return ans
ans=bfs(sh,sw)
print(1+(ans+k-1)//k)
#print(b,sh,sw)
#print(v)


Fixed submission:
h,w,k=map(int,input().split())
b=[]
v=[[0]*w for _ in range(h)]
sh=0
sw=0
for i in range(h):
    s=list(input())
    b.append(s)
    
    if 'S' in s:
        sh=i
        sw=s.index('S')
#ans=10**18
d=[[0,1],[1,0],[-1,0],[0,-1]]

def bfs(y,x):
    ans=10**18
    c=0
    q=[(y,x)]
    v[y][x]=1
    ans=min(y,x,h-1-y,w-1-x)
    while c<k:
        p=[]
        c+=1
        for i,j in q:
            for di,dj in d:
                if 0<=i+di<h and 0<=j+dj<w and v[i+di][j+dj]!=1 and b[i+di][j+dj]!='#':
                    p.append((i+di,j+dj))
                    v[i+di][j+dj]=1
                    ans=min(ans,i+di,j+dj,h-1-i-di,w-1-j-dj)
        q=p
    return ans
ans=bfs(sh,sw)
print(1+(ans+k-1)//k)

Buggy python submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
b=[]
v=[[0]*w for _ in range(h)]
sh=0
sw=0
for i in range(h):
    s=list(input())
    b.append(s)
    
    if 'S' in s:
        sh=i
        sw=s.index('S')
#ans=10**18
d=[[0,1],[1,0],[-1,0],[0,-1]]

def bfs(y,x):
    ans=10**18
    c=0
    q=[(y,x)]
    v[y][x]=1
    while c<k:
        p=[]
        c+=1
        for i,j in q:
            for di,dj in d:
                if v[i+di][j+dj]!=1 and b[i+di][j+dj]!='#':
                    p.append((i+di,j+dj))
                    v[i+di][j+dj]=1
                    ans=min(ans,i+di,j+dj,h-1-i-di,w-1-j-dj)
        q=p
    return ans
ans=bfs(sh,sw)
print(1+(ans+k-1)//k)
#print(b,sh,sw)
#print(v)


Fixed submission:
h,w,k=map(int,input().split())
b=[]
v=[[0]*w for _ in range(h)]
sh=0
sw=0
for i in range(h):
    s=list(input())
    b.append(s)
    
    if 'S' in s:
        sh=i
        sw=s.index('S')
#ans=10**18
d=[[0,1],[1,0],[-1,0],[0,-1]]

def bfs(y,x):
    ans=10**18
    c=0
    q=[(y,x)]
    v[y][x]=1
    ans=min(y,x,h-1-y,w-1-x)
    while c<k:
        p=[]
        c+=1
        for i,j in q:
            for di,dj in d:
                if 0<=i+di<h and 0<=j+dj<w and v[i+di][j+dj]!=1 and b[i+di][j+dj]!='#':
                    p.append((i+di,j+dj))
                    v[i+di][j+dj]=1
                    ans=min(ans,i+di,j+dj,h-1-i-di,w-1-j-dj)
        q=p
    return ans
ans=bfs(sh,sw)
print(1+(ans+k-1)//k)
Buggy python submission (verdict: Runtime Error):
_,T,*a=map(int,open(0).read().split())
print(sum([min(i-j,t) for i,j in zip(a,[0]+a)]))

Fixed submission:
n,T=map(int,input().split())
t=[int(i) for i in input().split()]
ans=0
pre=t[0]
for i in range(1,n):
    c=t[i]
    if c-pre>T:
        ans+=T
    else:
        ans+=c-pre
    pre=c
print(ans+T)

Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
p=a[0]
c=0
for i a:
  c+=t-i if p+t>i else t
print(c)

Fixed submission:
n,T=map(int,input().split())
t=[int(i) for i in input().split()]
ans=0
pre=t[0]
for i in range(1,n):
    c=t[i]
    if c-pre>T:
        ans+=T
    else:
        ans+=c-pre
    pre=c
print(ans+T)
Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=1
t=0
for i in input().split():
    a=int(i)
    if pre==0:
        pre=a
    else:
        if pre>a:
            if -t<0 and t**2==1:
                ans+=1
                t=-2
            else:
                t=-1
        elif pre<a:
            if t<0 and t**2==1:
                ans+=1
                t=2
            else:
                t=1
        else:
            continue
print(ans)


Fixed submission:
n=int(input())
pre=0
ans=1
t=0
for i in input().split():
    a=int(i)
    if pre==0:
        pre=a
    else:
        if pre>a:
            if -t<0 and t**2==1:
                ans+=1
                t=-2
            else:
                t=-1
        elif pre<a:
            if t<0 and t**2==1:
                ans+=1
                t=2
            else:
                t=1
        else:
            continue
        pre=a
print(ans)