Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,f=map(int,input().split())
a*=100
b*=100
x=set()
for i in range(f//a+1):
    for j in range(f//b+1):
        if 0<(a*i+b*j)<=f:
            x.add(a*i+b*j)
y=set()
for i in range(f//c+1):
    for j in range(f//d+1):
        if 0<(c*i+d*j)<=f:
            y.add(c*i+d*j)

ans=[]
noudoma=e/100
for n in x:
    for m in y:
        if n==0:
            continue
        if m/n<=noudoma and (n+m)<=f:
            ans.append([n+m,m,m/(n+m)])

ans.sort(key=lambda x:x[2], reverse=True)


print(ans[0][0],ans[0][1])


Fixed submission:
n=int(input())
a=int(input())

print(n**2-a)
Buggy python submission (verdict: Runtime Error):
n=input()
if n%10==9 or n//10==9:
    print("Yes")
else:
    print("No")


Fixed submission:
n=int(input())
if n%10==9 or n//10==9:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

n,m,r=map(int,input().split())
iku=list(map(int,input().split()))
iku=list(map(lambda x:x-1,iku))
iku="".join(list(map(str,iku)))

g=[[float("inf")]*n for _ in range(n)]

for _ in range(m):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    g[a][b]=c
    g[b][a]=c

for i in range(n):
    g[i][i]=0

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
warshall_floyd(g)

from itertools import permutations
x=list(permutations(iku,len(iku)))
ans=float("inf")
for l in x:
    ans2=0
    for i in range(1,r):
        ans2+=g[int(l[i-1])][int(l[i])]
    ans=min(ans,ans2)

print(ans)


Fixed submission:
from scipy.sparse.csgraph import shortest_path
import numpy as np
import itertools

n,m,r=map(int,input().split())
r=list(map(int,input().split()))

edge=np.zeros((n+1,n+1))
for i in range(m):
    a,b,c=map(int,input().split())
    edge[a,b]=c

dist=shortest_path(edge,directed=False).astype(int)

ans=10**18
for v in itertools.permutations(r):
    ans2=0
    p=v[0]
    for x in v[1:]:
        if p!=None:
            ans2+=dist[p,x]
        p=x
    ans=min(ans,ans2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

n,m,r=map(int,input().split())
iku=list(map(int,input().split()))
iku=list(map(lambda x:x-1,iku))
iku="".join(list(map(str,iku)))

g=[[float("inf")]*n for _ in range(n)]

for _ in range(m):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    g[a][b]=c
    g[b][a]=c

for i in range(n):
    g[i][i]=0

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
warshall_floyd(g)

from itertools import permutations
x=list(permutations(iku,len(iku)))
ans=float("inf")
for l in x:
    ans2=0
    for i in range(1,r):
        ans2+=g[int(l[i-1])][int(l[i])]
    ans=min(ans,ans2)

print(ans)


Fixed submission:
from scipy.sparse.csgraph import shortest_path
import numpy as np
import itertools

n,m,r=map(int,input().split())
r=list(map(int,input().split()))

edge=np.zeros((n+1,n+1))
for i in range(m):
    a,b,c=map(int,input().split())
    edge[a,b]=c

dist=shortest_path(edge,directed=False).astype(int)

ans=10**18
for v in itertools.permutations(r):
    ans2=0
    p=v[0]
    for x in v[1:]:
        if p!=None:
            ans2+=dist[p,x]
        p=x
    ans=min(ans,ans2)

print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
l=[]
alf=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o",
"p","q","r","s","t","u","v","w","x","y","z"]
for x in alf:
    if str(x) in s:
        pass
    else:
        l.append(x)
print(min(l))


Fixed submission:
s=input()
l=[]
alf=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o",
"p","q","r","s","t","u","v","w","x","y","z"]
for x in alf:
    if str(x) in s:
        pass
    else:
        l.append(x)
if l==[]:
    print("None")
else:
    print(min(l))
Buggy python submission (verdict: Runtime Error):
a,b,c,d=(int(x) for x in input().split())

if b<=c or d<=a:
    print(0)
else:
    print(min(b,d)-max(a,c))


Fixed submission:
n=str(input())

if n[0]==n[2]:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n=str(input())

if n[0]=n[2]:
    print("Yes")
else:
    print("No")


Fixed submission:
n=str(input())

if n[0]==n[2]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
def gcd(x,y):
    if x==y:
        return x
    elif x>y:
        r=-1
        while r!=0:
            r=x%y
            x=y
            y=r
        return x
    else:
        r=-1
        while r!=0:
            r=y%x
            y=x
            x=r
        return y

g=gcd(a[0],[1])
for i in range(2,n):
    g=gcd(g,a[i])
if k%g==0 and k<=max(a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE") 


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
def gcd(x,y):
    if x==y:
        return x
    elif x>y:
        r=-1
        while r!=0:
            r=x%y
            x=y
            y=r
        return x
    else:
        r=-1
        while r!=0:
            r=y%x
            y=x
            x=r
        return y

if n==1:
    if k==a[0]:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    exit()
g=gcd(a[0],a[1])
for i in range(2,n):
    g=gcd(g,a[i])
if k%g==0 and k<=max(a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k>max(a):
    print("IMPOSSIBLE")
    exit()
    
sa=float("inf")
a.sort()
b=[abs(a[0]-k)]
for i in range(1,n):
    sa=min(sa,abs(a[i]-a[i-1]))
    b.append(abs(a[i]-k))
f=0
for i in range(n):
    if b[i]%sa==0:
        f=1
print("POSSIBLE" if f else "IMPOSSIBLE")


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
def gcd(x,y):
    if x==y:
        return x
    elif x>y:
        r=-1
        while r!=0:
            r=x%y
            x=y
            y=r
        return x
    else:
        r=-1
        while r!=0:
            r=y%x
            y=x
            x=r
        return y

if n==1:
    if k==a[0]:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    exit()
g=gcd(a[0],a[1])
for i in range(2,n):
    g=gcd(g,a[i])
if k%g==0 and k<=max(a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
a,b=(iny(x) for x in input().split())

if a%3==0 or b%3==0 or (a+b)%3==0:
    print("Possible")
else:
    print("Impossible")


Fixed submission:
a,b=(int(x) for x in input().split())

if a%3==0 or b%3==0 or (a+b)%3==0:
    print("Possible")
else:
    print("Impossible")

Buggy python submission (verdict: Runtime Error):
a,b=(iny(x) for x in input().split())

if a%3==0 or b%3==0 or a+b%3==0:
    print("Possible")
else:
    print("Impossible")

    

Fixed submission:
a,b=(int(x) for x in input().split())

if a%3==0 or b%3==0 or (a+b)%3==0:
    print("Possible")
else:
    print("Impossible")
Buggy python submission (verdict: Runtime Error):
n,p=map(int,input().split())
a=list(map(int,input().split()))
gu=0
ki=0
for i in a:
    if a%2==0:
        gu+=1
    else:
        ki+=1
if ki:
    print(2**(n-1))
else:
    if p:
        print(0)
    else:
        print(2**n)


Fixed submission:
n,p=map(int,input().split())
a=list(map(int,input().split()))
gu=0
ki=0
for i in a:
    if i%2==0:
        gu+=1
    else:
        ki+=1
if ki:
    print(2**(n-1))
else:
    if p:
        print(0)
    else:
        print(2**n)
Buggy python submission (verdict: Runtime Error):
n=input()
l=list(map(int,input().split()))
print(max(l)-min(l))


Fixed submission:
s=input()
for i in range(len(s)):
    x=-1
    for j in range(len(s)):
        if s[i]==s[j]:
            x+=1
    if x!=0:
        print("no")
        exit()
print("yes")
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
ab=[]
for i in  range(n):
    a,b=map(int,input().split())
    ab.append([a,b])
ab.sort()
x=[]
for i in range(n):
    x.extend([ab[i][0]]*ab[i][1])
    if len(x)>k:
        break
print(x[k-1])


Fixed submission:
n,k=map(int,input().split())
ab=[]
for i in  range(n):
    a,b=map(int,input().split())
    ab.append([a,b])
ab.sort()
c=0
for i in range(n):
    c+=ab[i][1]
    if c>=k:
        print(ab[i][0])
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
ab=[]
for i in  range(n):
    a,b=map(int,input().split())
    x=[a]*b
    ab.extend(x)
ab.sort()
print(ab[k-1])


Fixed submission:
n,k=map(int,input().split())
ab=[]
for i in  range(n):
    a,b=map(int,input().split())
    ab.append([a,b])
ab.sort()
c=0
for i in range(n):
    c+=ab[i][1]
    if c>=k:
        print(ab[i][0])
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c=map(int,input().split())
l=0
for i in range(100000000):
    l=a*i
    if l%b==c:
        print("YES")
        exit()
print("NO")


Fixed submission:
a,b,c=map(int,input().split())
l=0
for i in range(b+1):
    l=a*i
    if l%b==c:
        print("YES")
        exit()
print("NO")
Buggy python submission (verdict: Runtime Error):
o=list(input())
e=list(input())
l=[]
if len(o)==len(e):
    for i in range(len(o)):
        l.append(o[i])
        l.append(e[i])
    print("".join(l))
else:
    for i in range(len(e)):
        l.append(o[i])
        l.append(e[i])
    l.append(o[len(o)])
    print("".join(l))


Fixed submission:
o=list(input())
e=list(input())
l=[]
if len(o)==len(e):
    for i in range(len(o)):
        l.append(o[i])
        l.append(e[i])
    print("".join(l))
else:
    for i in range(len(e)):
        l.append(o[i])
        l.append(e[i])
    l.append(o[len(o)-1])
    print("".join(l))
Buggy python submission (verdict: Runtime Error):
l=make_divisors(n)


Fixed submission:
n=int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
l=make_divisors(n)
print(len(str(max(l[len(l)//2],l[len(l)//2-1]))))
Buggy python submission (verdict: Runtime Error):
a,b = (str(x) for x in input().split())
if a = "H":
    pass
elif b = "H":
    b = "D"
else:
    b = "H"

print(b)


Fixed submission:
a,b = (str(x) for x in input().split())
if a == "H":
    pass
elif b == "H":
    b = "D"
else:
    b = "H"

print(b)

Buggy python submission (verdict: Runtime Error):
a,b = (str(x) for x in input().split())
if a = "H":
    continue
elif b = "H":
    b = "D"
else:
    b = "H"

print(b)

Fixed submission:
a,b = (str(x) for x in input().split())
if a == "H":
    pass
elif b == "H":
    b = "D"
else:
    b = "H"

print(b)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
p=1
for i in range(1,N+1):
    p=p*i
print(p%(10**9+7))


Fixed submission:
N=int(input())
p=1
for i in range(1,N+1):
    p=p*i
    p=p%(10**9+7)
print(p)
Buggy python submission (verdict: Runtime Error):
a,b = (int(x) for x in input.split())

if a==1:
    a=14
if b==1:
    b=14

if a>b:
    print("Alice")
elif a<b:
    print("Bob")
else:
    print("Draw")


Fixed submission:
a,b = (int(x) for x in input().split())

if a==1:
    a=14
if b==1:
    b=14

if a>b:
    print("Alice")
elif a<b:
    print("Bob")
else:
    print("Draw")

Buggy python submission (verdict: Runtime Error):
a,b = (int(x) for in input.split())

if a==1:
    a=14
if b==1:
    b=14

if a>b:
    print("Alice")
elif a<b:
    print("Bob")
else:
    print("Draw")

Fixed submission:
a,b = (int(x) for x in input().split())

if a==1:
    a=14
if b==1:
    b=14

if a>b:
    print("Alice")
elif a<b:
    print("Bob")
else:
    print("Draw")
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        x=[]
        for k in range(m):
            x.append(a[i+k][j+m])
        if x==b:
            print("Yes")
            exit()
print("No")


Fixed submission:
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        x=[]
        for k in range(m):
            x.append(a[i+k][j:j+m])
        if x==b:
            print("Yes")
            exit()
print("No")
Buggy python submission (verdict: Runtime Error):
a,b,c,d = int(input().split())

s1 = a*b
s2 = c*d

if s1>=s2:
    print(s1)
else:
    print(s2)


Fixed submission:
a,b,c,d = (int(x) for x in input().split())

s1 = a*b
s2 = c*d

if s1>=s2:
    print(s1)
else:
    print(s2)

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())

s1 = a*b
s2 = c*d

if s1>=s2:
    print(s1)
else:
    print(s2)


Fixed submission:
a,b,c,d = (int(x) for x in input().split())

s1 = a*b
s2 = c*d

if s1>=s2:
    print(s1)
else:
    print(s2)
Buggy python submission (verdict: Runtime Error):
s=input()
s[7]=" "
s[15]=" "
print(s)


Fixed submission:
s = input()
ss = s.replace("," , " ")
print(ss)

Buggy python submission (verdict: Runtime Error):
s=input()

s.raplace(","," ")
print(s)


Fixed submission:
s = input()
ss = s.replace("," , " ")
print(ss)

Buggy python submission (verdict: Runtime Error):
str(s)
s=input()

s.raplace(","," ")
print(s)

Fixed submission:
s = input()
ss = s.replace("," , " ")
print(ss)

Buggy python submission (verdict: Runtime Error):
s=str(input())
s.raplace(","," ")
print(s)


Fixed submission:
s = input()
ss = s.replace("," , " ")
print(ss)

Buggy python submission (verdict: Runtime Error):
s=str(input())
s[5]=" "
s[13]=" "
print(s)

Fixed submission:
s = input()
ss = s.replace("," , " ")
print(ss)
Buggy python submission (verdict: Runtime Error):
n=int(input())
t=list(map(int,input().split()))
m=int(input())
for i in range(m):
    p,x=map(int,input().split())
    t[p+1]=x
print(sum(t))


Fixed submission:
n=int(input())
t=list(map(int,input().split()))
m=int(input())
ans=[]
for i in range(m):
    p,x=map(int,input().split())
    ans.append(sum(t)-(t[p-1]-x))
for i in range(m):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
f=True
if n%2==1:
    if a[0]!=0 or a[1]==0:
        f=False
    for i in range(1,n-1,2):
        if not (a[i]==i+1 and a[i+1]==i+1):
            f=False
else:
    for i in range(0,n,2):
        if not (a[i]==i+1 and a[i+1]==i+1):
            f=False
if f:
    print((2**(n//2))%mod)
else:
    print(0)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
f=True
if n==1:
    if a[0]==0:
        print(1)
    else:
        print(0)
    exit()
if n%2==1:
    if a[0]!=0 or a[1]==0:
        f=False
    for i in range(1,n-1,2):
        if not (a[i]==i+1 and a[i+1]==i+1):
            f=False
else:
    for i in range(0,n,2):
        if not (a[i]==i+1 and a[i+1]==i+1):
            f=False
if f:
    print((2**(n//2))%mod)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
f=True
if n%2==1:
    if a.count(0)!=1:
        f=False
    for i in  range(2,n,2):
        if a.count(i)!=2:
            f=False
else:
    for i in range(1,n,2):
        if a.count(i)!=2:
            f=False
if f:
    print((2**(n//2))%mod)
else:
    print(0)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
f=True
if n==1:
    if a[0]==0:
        print(1)
    else:
        print(0)
    exit()
if n%2==1:
    if a[0]!=0 or a[1]==0:
        f=False
    for i in range(1,n-1,2):
        if not (a[i]==i+1 and a[i+1]==i+1):
            f=False
else:
    for i in range(0,n,2):
        if not (a[i]==i+1 and a[i+1]==i+1):
            f=False
if f:
    print((2**(n//2))%mod)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,x=map(int,input().split())
c=0
for i in range(a,b+1):
    if i%x==0:
        c+=1
print(c)


Fixed submission:
a,b,x=map(int,input().split())
fb=b//x
fa=(a-1)//x
if a==0:
    print(fb+1)
else:
    print(fb-fa)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if max(a,b,c)*2==sum(a,b,c):
    print("Yes")
else:
    print("No")


Fixed submission:
l=list(map(int,input().split()))
if max(l)*2==sum(l):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
s=input()
ok=0
x=0
ans=""
for i in range(n):
    ss=s[i]
    if ss=="a" and ok<a+b:
        ok+=1
        ans+="Yes\n"
    elif ss=="b" and ok<a+b and x<b:
        ok+=1
        x+=1
        ans+="Yes\n"
    else:
        ans+="No\n"

print(ans[:-1])


Fixed submission:
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
s=input()
ok=0
x=0
ans=[]
for i in range(n):
    ss=s[i]
    if ss=="a" and ok<a+b:
        ok+=1
        ans.append("Yes")
    elif ss=="b" and ok<a+b and x<b:
        ok+=1
        x+=1
        ans.append("Yes")
    else:
        ans.append("No")

print(*ans, sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
n,a,b=map(int,input().split())
s=input()
ok=0
x=0
ans=""
for i in range(n):
    if s[i]=="a" and ok<a+b:
        ok+=1
        ans+="Yes\n"
    elif s[i]=="b" and ok<a+b and x<b:
        ok+=1
        x+=1
        ans+="Yes\n"
    else:
        ans+="No\n"

print(ans[:-1])


Fixed submission:
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
s=input()
ok=0
x=0
ans=[]
for i in range(n):
    ss=s[i]
    if ss=="a" and ok<a+b:
        ok+=1
        ans.append("Yes")
    elif ss=="b" and ok<a+b and x<b:
        ok+=1
        x+=1
        ans.append("Yes")
    else:
        ans.append("No")

print(*ans, sep="\n")
Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())
for i in range(len(s)):
    if k>=ord("z")-ord(s[i])+1:
        k-=(ord("z")-ord(s[i])+1)
        s[i]="a"

if k>0:
    if ord("z")-(ord(s[-1])+k)<=0:
        k-=ord("z")-ord(s[-1])+1
        k%=26
        s[-1]=chr(ord("a")+k)
    else:
        s[-1]=chr(ord(s[-1])+k)

print("".join(s))


Fixed submission:
s=list(input())
s.insert(4," ")
print("".join(s))
Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())
for i in range(len(s)):
    if k>=ord("z")-ord(s[i])+1:
        k-=(ord("z")-ord(s[i])+1)
        s[i]="a"

if k:
    s[-1]=chr(ord(s[-1])+k)

print("".join(s))


Fixed submission:
s=list(input())
k=int(input())
for i in range(len(s)):
    if s[i]=="a":
        continue
    if k>=ord("z")-ord(s[i])+1:
        k-=(ord("z")-ord(s[i])+1)
        s[i]="a"

if k>0:
    k%=26
    s[-1]=chr(ord(s[-1])+k)

print("".join(s))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
l=[]
for x in range(-100,101):
    c=0
    for i in range(n):
        c+=(a[i]-x)**2
    l.append(c)

print(min(c))


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
l=[]
for x in range(-100,101):
    c=0
    for i in range(n):
        c+=(a[i]-x)**2
    l.append(c)

print(min(l))
Buggy python submission (verdict: Runtime Error):
a,b,c=input().split()
l=[]
l.append(len(a))
l.append(len(b))
l.append(len(c))
if l==[5,5,7] or l=[5,7,5] or l=[7,5,5]:
    print("YES")
else:
    print("NO")


Fixed submission:
a,b,c=map(int,input().split())
l=[]
l.append(a)
l.append(b)
l.append(c)
if l==[5,5,7] or l==[5,7,5] or l==[7,5,5]:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = [int(x) for x in input().split()]
A = [(-1, -1)] * 100000

for y in range(H):
    tmp = [int(x) for x in input().split()]
    for x, e in enumerate(tmp):
        A[e] = (x, y)

Q = int(input())
LR = [[int(e) for e in input().split()] for i in range(Q)]

for start, goal in LR:
    place = start
    point = 0

    while place != goal:
        placeX, placeY = A[place]
        nxtX, nxtY = A[place + D]

        point += (abs(nxtX - placeX) + abs(nxtY - placeY))
        place += D
    print(point)


Fixed submission:
H, W, D = [int(x) for x in input().split()]
size = H*W+1
c = [(-1, -1)] * size
p = [0] * size

for y in range(H):
    for x, a in enumerate([int(s) for s in input().split()]):
        c[a] = (x, y)

for a in range(D+1, size):
    p[a] = p[a-D] + abs(c[a][0] - c[a-D][0]) + abs(c[a][1] - c[a-D][1])

Q = int(input())
for i in range(Q):
    L, R = [int(lr) for lr in input().split()]
    print(p[R] - p[L])

Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = [int(x) for x in input().split()]
A = [(-1, -1)] * 100000

for y in range(H):
    tmp = [int(x) for x in input().split()]
    for x in range(W):
        A[tmp[x]] = (x, y)

Q = int(input())
LR = [tuple([int(x) for x in input().split()]) for i in range(Q)]

for start, goal in LR:
    place = start
    nxt = place + D
    point = 0

    while place != goal:
        placeX, placeY = A[place]
        nxtX, nxtY = A[nxt]

        point += (abs(nxtX - placeX) + abs(nxtY - placeY))
        place += D
        nxt += D
    print(point)


Fixed submission:
H, W, D = [int(x) for x in input().split()]
size = H*W+1
c = [(-1, -1)] * size
p = [0] * size

for y in range(H):
    for x, a in enumerate([int(s) for s in input().split()]):
        c[a] = (x, y)

for a in range(D+1, size):
    p[a] = p[a-D] + abs(c[a][0] - c[a-D][0]) + abs(c[a][1] - c[a-D][1])

Q = int(input())
for i in range(Q):
    L, R = [int(lr) for lr in input().split()]
    print(p[R] - p[L])
Buggy python submission (verdict: Runtime Error):
from queue import Queue

H, W = [int(x) for x in input().split()]
realH = H + 2
realW = W + 2
s = ["#" + input() + "#" for x in range(H)]
wall = "#" * (realW)
s.insert(0, wall)
s.append(wall)
dxy = [0, 1, 0, -1, 0]
inf = float("inf")

visited = [[False] * realW for x in range(realH)]
depth = [[inf] * realW for x in range(realH)]
depth[1][1] = 1
q = Queue()
q.put((1,1))

while not q.empty():
    place = q.get()
    if place == (H, W):
        break
    for i in range(4):
        nxt = (place[0] + dxy[i], place[1] + dxy[i+1])
        if s[nxt[0]][nxt[1]] == "." and not visited[nxt[0]][nxt[1]]:
            q.put(nxt)
            depth[nxt[0]][nxt[1]] = depth[place[0]][place[1]] + 1
            visited[nxt[0]][nxt[1]] = True

if depth[H][W] == inf:
    print(-1)
elif:
    print(realH * realW - sum(map(lambda x: x.count("#"), s)) - depth[H][W])



Fixed submission:
from queue import Queue

H, W = [int(x) for x in input().split()]
realH = H + 2
realW = W + 2
s = ["#" + input() + "#" for x in range(H)]
wall = "#" * (realW)
s.insert(0, wall)
s.append(wall)
dxy = [0, 1, 0, -1, 0]
inf = float("inf")

visited = [[False] * realW for x in range(realH)]
depth = [[inf] * realW for x in range(realH)]
depth[1][1] = 1
q = Queue()
q.put((1,1))

while not q.empty():
    place = q.get()
    if place == (H, W):
        break
    for i in range(4):
        nxt = (place[0] + dxy[i], place[1] + dxy[i+1])
        if s[nxt[0]][nxt[1]] == "." and not visited[nxt[0]][nxt[1]]:
            q.put(nxt)
            depth[nxt[0]][nxt[1]] = depth[place[0]][place[1]] + 1
            visited[nxt[0]][nxt[1]] = True

if depth[H][W] == inf:
    print(-1)
else:
    print(realH * realW - sum(map(lambda x: x.count("#"), s)) - depth[H][W])
Buggy python submission (verdict: Runtime Error):
s=input()
if s=="SSS":
  print(0)
else if s=="RRS" or s== "SRR":
  print(2)
else if s== "RRR":
  print(3)
else:
  print(1)

Fixed submission:
s=input()
if s=="SSS":
  print(0)
elif s=="RRS" or s== "SRR":
  print(2)
elif s== "RRR":
  print(3)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
s=input()
if s=="SSS":
  print(0)
else if s=="RRS" or s= "SRR":
  print(2)
else if s= "RRR":
  print(3)
else:
  print(1)

Fixed submission:
s=input()
if s=="SSS":
  print(0)
elif s=="RRS" or s== "SRR":
  print(2)
elif s== "RRR":
  print(3)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N%2 == 1:
  ans = (N//2+1)/(N//2)
else:
  ans = 0.5
print(ans)

Fixed submission:
N = int(input())
if N%2 == 1:
  ans = (N//2+1)/N
else:
  ans = 0.5
print(ans)