Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02990 (python)

Fixed submission:
import math
def bi(x, y):
  if x < y or y < 0 or x < 0: return 0
  if y == 0: return 1
  return math.factorial(x) // math.factorial(y) // math.factorial(x - y)

n, k = list(map(int, input().split(' ')))
for i in range(1, k + 1):
  print(bi(k - 1, i - 1) * bi(n - k + 1, i) % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
def BC132_D():
    n, k = list(map(int, input().split(' ')))
    f = [1] * max(k, n - k + 2)
    for i in range(1, len(f) + 1):
        f[i] = f[i - 1] * i

    def comb(n, r, f):
        if n < r: return 0
        return f[n] // f[r] // f[n - r]

    for i in range(1, k + 1):
        print(comb(k - 1, i - 1, f) * comb(n - k + 1, i, f) % (10**9 + 7))

BC132_D()

Buggy submission (verdict: Runtime Error):
def BC132_D():
    n, k = list(map(int, input().split(' ')))
    f = [1] * max(k, n - k + 2)
    for i in range(1, len(f) + 1):
        f[i] = f[i - 1] * i

    def comb(n, r):
        if n < r: return 0
        return f[n] // f[r] // f[n - r]

    for i in range(1, k + 1):
        print(comb(k - 1, i - 1) * comb(n - k + 1, i) % (10**9 + 7))

BC132_D()

Buggy submission (verdict: Runtime Error):
import math
def bi(x, y):
  if x < y or y < 0 or x < 0: return 0
  if y == 0: return 1
  return math.factorial(x) // math.factorial(y) // math.factorial(x - y)

n, b = list(map(int, input().split(' ')))
for i in range(1, k + 1):
  print(bi(k - 1, i - 1) * bi(n - k + 1, i) % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
import math
def bi(x, y):
    if x < y or y < 0: return 0
    if y == 0: return 1
    r = math.factorial(x) // math.factorial(y) // math.factorial(x - y)
    return r % (10**9 + 7)

n, k = list(map(int, input().split(' ')))
for i in range(1, k + 1):
  	if n - k < i - 1: print(0)
    print(bi(k - 1, i - 1) * (bi(n - k - 1, i - 2) + bi(n - k - 1, i - 1) + bi(n - k, i)) % (10**9 + 7))
Problem p02998 (python)

Fixed submission:
from collections import defaultdict
n = int(input())
dx = defaultdict(list)
dy = defaultdict(list)
pts = set()
for _ in range(n):
    x, y = map(int, input().split())
    dx[x].append(y)
    dy[y].append(x)
    pts.add((x, y))

vx, vy = set(), set()
cnt = 0
for x, y in pts:
    if x in vx or y in vy: continue
    sx, sy = [x], [y]
    xs, ys = set(), set()
    while sx or sy:
        while sx:
            x = sx.pop()
            if x not in xs:
                xs.add(x)
                for y in dx[x]:
                    if y not in ys:
                        sy.append(y)
        while sy:
            y = sy.pop()
            if y not in ys:
                ys.add(y)
                for x in dy[y]:
                    if x not in xs:
                        sx.append(x)
    vx.update(xs)
    vy.update(ys)
    cnt += len(xs) * len(ys)
print(cnt - len(pts))

Buggy submission (verdict: Runtime Error):
n = int(input())
dx = defaultdict(list)
dy = defaultdict(list)
pts = set()
for _ in range(n):
    x, y = map(int, input().split())
    dx[x].append(y)
    dy[y].append(x)
    pts.add((x, y))

vx, vy = set(), set()
cnt = 0
for x, y in pts:
    if x in vx or y in vy: continue
    sx, sy = [x], [y]
    xs, ys = set(), set()
    while sx or sy:
        while sx:
            x = sx.pop()
            if x not in xs:
                xs.add(x)
                for y in dx[x]:
                    if y not in ys:
                        sy.append(y)
        while sy:
            y = sy.pop()
            if y not in ys:
                ys.add(y)
                for x in dy[y]:
                    if x not in xs:
                        sx.append(x)
    vx.update(xs)
    vy.update(ys)
    cnt += len(xs) * len(ys)
print(cnt - len(pts))

Buggy submission (verdict: Runtime Error):
n = int(input())
dot = {}
dotset = set()
for i in range(n):
    x, y = map(int, input().split())
    dot[i] = (x, y)
    dotset.add((x, y))

v = set()

cnt = 0
for i, f in dot:
    a, b = f
    for j, g in dot:
        if i == j: continue
        c, d = g
        if a == c or b == d: continue
        f1 = (a, d) in dotset
        f2 = (c, b) in dotset
        if f1 and not f2:
            cnt += 1
            dotset.add((c, b))
        if not f1 and f2:
            cnt += 1
            dotset.add((a, d))
print(cnt)
Problem p03038 (python)

Fixed submission:
N, M = map(int, input("").split(" "))

A = map(int, input("").split(" "))
A = list(A)
A.sort()

potentials = []
for i in range(M):
    B, C = map(int, input("").split(" "))

    potentials.append((B, C))

potentials.sort(key=lambda x: x[1], reverse=True)

c = 0
for p in potentials:
    for b in range(p[0]):
        if p[1] > A[c]:
            A[c] = p[1]
            c += 1
            if c >= len(A):
                break
        else:
            break
    if c >= len(A):
        break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input("").split(" "))

A = map(int, input("").split(" "))
A = list(A)
A.sort()

potentials = []
for i in range(M):
    B, C = map(int, input("").split(" "))

    potentials.append((B, C))

potentials.sort(key=lambda x: x[1], reverse=True)

c = 0
for p in potentials:
    for b in range(p[0]):
        if p[1] > A[c]:
            if c < len(A):
                A[c] = p[1]
                c += 1
            else:
                break
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input("").split(" "))

A = map(int, input("").split(" "))
A = list(A)
A.sort()

potentials = []
for i in range(M):
    B, C = map(int, input("").split(" "))

    potentials.append((B, C))

potentials.sort(key=lambda x: x[1], reverse=True)

c = 0
for p in potentials:
    for b in range(p[0]):
        if p[1] > A[c]:
            if c < N:
                A[c] = p[1]
                c += 1
            else:
                break
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input("").split(" "))

A = map(int, input("").split(" "))
A = list(A)
A.sort()

potentials = []
for i in range(M):
    B, C = map(int, input("").split(" "))

    potentials.append((B, C))

potentials.sort(key=lambda x: x[1], reverse=True)

c = 0
for p in potentials:
    if c < len(A):
        for b in range(p[0]):
            if p[1] > A[c]:
                A[c] = p[1]
                c += 1
            else:
                break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input("").split(" "))

A = map(int, input("").split(" "))
A = list(A)
A.sort()

potentials = []
for i in range(M):
    B, C = map(int, input("").split(" "))

    potentials.append((B, C))

potentials.sort(key=lambda x:x[1], reverse=True)

c = 0
for p in potentials:
    for b in range(p[0]):
        if p[1] > A[c]:
            A[c] = p[1]
            c += 1
        else:
            break

print(sum(A))
Problem p02990 (python)

Fixed submission:
from math import factorial

N, K = map(int, input().split())

# コンビネーションを計算
def calcCombination(m, n):
    return factorial(m) // (factorial(n) * factorial(m-n))

for i in range(1, K+1):
    if N-K+1 < i:
        print(0)
    else:
        print(calcCombination(N-K+1, i) * calcCombination(K-1, i-1) % (10**9+7))

Buggy submission (verdict: Runtime Error):
from math import factorial

N, K = map(int, input().split())

# コンビネーションを計算
def calcCombination(m, n):
    return factorial(m) // (factorial(n) * factorial(m-n))

for i in range(1, K+1):
    print(calcCombination(N-K+1, i) * calcCombination(K-1, i-1) % (10**9+7))
Problem p02984 (python)

Fixed submission:
# -*- coding: utf-8 -*-
 
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
r = [s - 2 * sum(A[1::2])]

for i in range(N-1):
    r.append(2 * A[i] - r[i])
    
r = map(str, r)
print(" ".join(r))

'''
5
3 8 7 5 5
'''

Buggy submission (verdict: Runtime Error):
import sympy

N = int(input())
Y = list(map(int,input().split(' ')))


symbols = []
for i in range(N):
    symbols.append(sympy.Symbol('x' + str(i)))

equation = []
for i in range(N):
    i1 = i
    i2 = i + 1 
    if i2 >= N:
        i2 = 0
    equation.append(0.5*symbols[i1] + 0.5*symbols[i2] - Y[i])

for i in range(N):
    print(str(int(sympy.solve(equation)[symbols[i]])) + " " , end="")
print()

Buggy submission (verdict: Runtime Error):
import sympy

N = input()
Y = list(map(int,input().split(' ')))

symbols = []
for i in range(N):
    symbols.append(sympy.Symbol('x' + str(i)))

equation = []
for i in range(N):
    i1 = i
    i2 = i + 1 
    if i2 >= N:
        i2 = 0
    equation.append(0.5*symbols[i1] + 0.5*symbols[i2] - Y[i])

for i in range(N):
    print(str(int(sympy.solve(equation)[symbols[i]])) + " " , end="")
print()

Buggy submission (verdict: Runtime Error):
import sympy

N = 3
Y = list(map(int,input().split(' ')))


symbols = []
for i in range(N):
    symbols.append(sympy.Symbol('x' + str(i)))

equation = []
for i in range(N):
    i1 = i
    i2 = i + 1 
    if i2 >= N:
        i2 = 0
    equation.append(0.5*symbols[i1] + 0.5*symbols[i2] - Y[i])

for i in range(N):
    print(str(int(sympy.solve(equation)[symbols[i]])) + " " , end="")
print()
Problem p02987 (python)

Fixed submission:
S = list(str(input()))
import collections
c = collections.Counter(S)
t = c.most_common()
if (len(t) > 1 and t[0][1] == t[1][1] == 2):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
S = list(str(input()))
import collections
c = collections.Counter(S)
t = c.most_common()
if (t[0][1] == t[1][1] == 2):
    print("Yes")
else:
    print("No")
Problem p03011 (python)

Fixed submission:
p,q,r = map(int, input().split())

l = [p, q, r]

l.sort()

print(l[0] + l[1])

Buggy submission (verdict: Runtime Error):
l = [map(int, input())]

l.sort()

print(l[0] + l[1])
Problem p03012 (python)

Fixed submission:
N = int(input())
W = [int(i) for i in input().split()]
s = sum(W)
a = 0

for i in range(N):
	_ = a + W[i]
	if abs(a - (s - a)) <= abs(_ - (s - _)):
		break
	else:
		a = _

print(abs(a-(s - a)))

Buggy submission (verdict: Runtime Error):
N = int(input())
W = [int(i) for i in input().split()]
s = sum(W)
a = 0

for i in range(N):
	_ = a + W[i]
	if abs(a - (s - a)) <= abs(_ - (s - _)):
		break
	else:
		a = _

print abs(a-(s - a))
Problem p03135 (python)

Fixed submission:
import sys

def main():
    arg = sys.stdin.readline().rstrip().split()
    T = int(arg[0])
    X = int(arg[1])
    t = T / X
    print(t)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

arg = sys.argv
T = int(arg[1])
X = int(arg[2])
t = T / X
print(t)

Buggy submission (verdict: Runtime Error):
import sys

def main():
    arg = sys.argv
    T = int(arg[1])
    X = int(arg[2])
    t = T / X
    print(t)


if __name__ == "__main__":
    main()
Problem p03307 (python)

Fixed submission:
N = int(input())
if N % 2 != 0:
    N = N * 2

print(N)

Buggy submission (verdict: Runtime Error):
def maxElem( lis ):
  L = lis[:]#copy
  S = set(lis)
  S = list(S)
  MaxCount=0
  ret='nothing...'

  for elem in S:
    c=0
    while elem in L:
      ind = L.index(elem)
      foo = L.pop(ind)
      c+=1
    if c>MaxCount:
      MaxCount=c
      ret = elem
  return ret

if __name__ == "__main__" :
    n = int(input())
    array = list(map(int, input().split()))

    for i in range(0, n):
        array[i] = array[i] - (i + 1)
    elem = int(maxElem(array))
    
    for i in range(0, n):
        array[i] = abs(array[i] - elem)

    sum_n = sum(array)

    print(sum_n)
Problem p03137 (python)

Fixed submission:
n, m = map(int, input().split())
l=list(map(int, input().split()))

if(n>=m):
    print("0")
    exit()

l.sort()
d=[]
for i in range(m-1):
    d.append(abs(l[i+1]-l[i]))

d.sort()
print(sum(d[:m-n]))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
l=list(map(int, input().split()))
l.sort()
d=[]
for i in range(m-1):
    d.append(abs(l[i+1]-l[i]))

if(len(d)<1):
    print("0")
    exit()

for _ in range(n-1):
    d.remove(max(d))

print(sum(d))
Problem p02990 (python)

Fixed submission:
from math import factorial as fact
def comb(n, r):
  return fact(n) // (fact(n-r) * fact(r))

n,k = map(int, input().split(' '))
mod = 10**9 + 7

for i in range(1, k+1):
  if i <= n-k+1:
    ans = comb(n-k+1, i) * comb(k-1, i-1)
  else:
    ans = 0
  print(ans % mod)

Buggy submission (verdict: Runtime Error):
from math import factorial as fact
def comb(n, r):
  return fact(n) // (fact(n-r) * fact(r))

n,k = map(int, input().split(' '))
mod = 10**9 + 7
ans = 0

for i in range(1, k+1):
  ans = comb(n-k+1, i) * comb(k-1, i-1)
  print(ans % mod)
Problem p03042 (python)

Fixed submission:
s = input()
pre = int(s[:2])
suf = int(s[2:])
if 0 < pre <= 12 and 0 < suf <= 12:
  print('AMBIGUOUS')
elif 0 < suf <= 12:
  print('YYMM')
elif 0 < pre <= 12:
  print('MMYY')
else:
  print('NA')

Buggy submission (verdict: Runtime Error):
s = input()
n = 4
pre = int(s[:2])
suf = int(s[2:])
if 0 < pre <= 12 and 0 < suf <= 12:
  print('AMBIGUOUS')
elif 0 < suf <= 12:
  print('YYMM')
elif 0 < pre <= 12:
  pritn('MMYY')
else:
  print('NA')

Buggy submission (verdict: Runtime Error):
s = input()
n = 4
pre = int(s[:2])
suf = int(s[2:])
if pre > 12 and 0 < suf <= 12:
  print('YYMM')
elif 0 < pre <= 12 and suf > 12:
  pritn('MMYY')
elif 0 < pre <= 12 and 0 < suf <= 12:
  print('AMBIGUOUS')
else:
  print('NA')

Buggy submission (verdict: Runtime Error):
s = input()
n = 4
pre = int(s[:2])
suf = int(s[2:])
if pre > 12 and suf > 12:
  print('NA')
elif pre > 12 and suf <= 12 and suf > 0:
  print('YYMM')
elif pre <= 12 and suf > 12 and pre > 0:
  pritn('MMYY')
elif pre <= 12 and suf <= 12 and pre > 0 and suf > 0:
  print('AMBIGUOUS')
else:
  print('NA')
Problem p02990 (python)

Fixed submission:
def main():
    mod = 10 ** 9 + 7
    N, K = map(int, input().split())
    fact = Fact(2*N)
    for i in range(1, K+1):
        ans = (fact(K-1)*fact(N-K+1))//(fact(i-1)*fact(K-i)*fact(i)*fact(N-K-i+1))
        print(ans % mod)

def answer(N, K, i):
    ans = (fact(K-1)*fact(N-K+1))//(fact(i-1)*fact(K-i)*fact(i)*fact(N-K-i+1))
    return ans

class Fact:

    def __init__(self, n):
        self.l = [1] * n
        for i in range(1, n):
            self.l[i] = self.l[i-1] * i

    def __call__(self, k):
        return self.l[k]


main()

Buggy submission (verdict: Runtime Error):
def main():
    mod = 10 ** 9 + 7
    N, K = map(int, input().split())
    fact = Fact(N)
    for i in range(1, K+1):
        ans = (fact(K-1)*fact(N-K+1))//(fact(i-1)*fact(K-i)*fact(i)*fact(N-K-i+1))
        print(ans % mod)

def answer(N, K, i):
    ans = (fact(K-1)*fact(N-K+1))//(fact(i-1)*fact(K-i)*fact(i)*fact(N-K-i+1))
    return ans

class Fact:

    def __init__(self, n):
        self.l = [1] * n
        for i in range(1, n):
            self.l[i] = self.l[i-1] * i

    def __call__(self, k):
        return self.l[k]


main()
Problem p03053 (python)

Fixed submission:
import sys


def input():
    return sys.stdin.readline()[:-1]


H, W = map(int, input().split())

A = [[1 if s == "#" else 0 for s in input()] for i in range(H)]

lu = [[1<<20] * (W+2) for j in range(H + 2)]

for ii in range(H * W):
    i = ii // W + 1
    j = ii % W + 1
    lu[i][j] = min(lu[i - 1][j], lu[i][j - 1]) + 1
    if A[i - 1][j - 1]:
        lu[i][j] = 0
    elif j < W and A[i - 1][j]:
        lu[i][j] = 1

for ii in range(H * W):
    i = H - ii // W
    j = W - ii % W
    lu[i][j] = min(lu[i + 1][j] + 1, lu[i][j + 1] + 1, lu[i][j])

dist = []
[dist.extend(l[1:-1]) for l in lu[1:-1]]
print(max(dist))

Buggy submission (verdict: Runtime Error):
import numpy as np
H, W = map(int, input().split())

A = [list(map(lambda x: x == "#", input())) for i in range(H)]
A = np.array(A)
black = np.concatenate(np.where(A)).reshape(2,-1)

here = np.concatenate(np.meshgrid(np.arange(H), np.arange(W))).reshape(2, -1)
dist = np.abs(black[:, None] - here[:, :, None])
dist = dist.sum(axis=0).min(axis=1).max()
print(dist)
Problem p02990 (python)

Fixed submission:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

import math

def fac(n, r):
    if r > n:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, K = nl()
prev_a = 0
prev_b = 0
for i in range(1, K+1):
    print(fac(N-K+1, i) * fac(K-1, i-1) % 1000000007)

Buggy submission (verdict: Runtime Error):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

import math

def fac(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, K = nl()
prev_a = 0
prev_b = 0
for i in range(1, K+1):
    print(fac(N-K+1, i) * fac(K-1, i-1) % 1000000007)
Problem p03221 (python)

Fixed submission:
from collections import defaultdict
N, M = map(int, input().split())

counts = defaultdict(int)
numbers = {}

cities = []
for i in range(M):
    p, y = map(int, input().split())
    cities.append([i, p, y])

sorted_cities = sorted(cities, key=lambda x: x[2])
for city in sorted_cities:
    i, p, y = city
    counts[p] += 1
    numbers[i] = '{:06}{:06}'.format(p, counts[p])

for city in cities:
    print(numbers[city[0]])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

counts = defaultdict(int)
numbers = {}

cities = []
for i in range(M):
    p, y = map(int, input().split())
    cities.append([i, p, y])

sorted_cities = sorted(cities, key=lambda x: x[2])
for city in sorted_cities:
    i, p, y = city
    counts[p] += 1
    numbers[i] = '{:06}{:06}'.format(p, counts[p])

for city in cities:
    print(numbers[city[0]])
Problem p03208 (python)

Fixed submission:
n, k = map(int, input().split())
h = []

for i in range(n):
    h.append(int(input()))
min = 10 ** 10
#  print(h)
h = sorted(h)
#  print(h)
for i in range(n-k+1):
    #  print(h[i:i+k-1])
    div = h[i+k-1] - h[i]
    if div < min:
        min = div
    if min == 0:
        print(min)
        exit()
print(min)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = []

for i in range(n):
    h.append(int(input()))
min = 10 ** 10
#  print(h)
h = sorted(h)
#  print(h)
for i in range(k):
    #  print(h[i:i+k-1])
    div = h[i+k-1] - h[i]
    if div < min:
        min = div
    if min == 0:
        print(min)
        exit()
print(min)
Problem p03295 (python)

Fixed submission:
n, m = map(int, input().split())
# stdin.readlines?
x = [[0, 0] for i in range(m)]
for i in range(m):
    x[i][0], x[i][1] = map(int, input().split())
x = sorted(x, key=lambda y: y[0])
ans = 1
mx = max([x[i][0] for i in range(m)])
while len(x) > 0:
    for i in range(len(x)-1, -1, -1):
        if mx < x[i][1]:
            x.pop(i)
            break
        else:
            mx = x[i][0]
            ans += 1
            break
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
# stdin.readlines?
x = [[0, 0] for i in range(m)]
for i in range(m):
    x[i][0], x[i][1] = map(int, input().split())
x = sorted(x, key = lambda y: y[0])
ans = 1
mx = max(x[0])
while len(x) > 0:
    for i in range(len(x)):
        if mx <= x[i][1]:
            x.pop(i)
        else:
            mx = x[i][0]
            ans += 1
            break
prin(ans)
Problem p03317 (python)

Fixed submission:
# グループ分けの数を最初に分かっていれば、いい
n, k = map(int, input().split())
a_tmp = input().split()
a = []
for _ in a_tmp:
    a.append(int(_))
g = 1
while n > (k + (k-1)*(g-1)):
    g += 1
print(g)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a_tmp = input().split()
a = [[] for i in range(n)]
for i in range(n):
    a[i] = int(a_tmp[i])
if n != k:
a1 = a.index(1)
sol = 0
a_left = a1
a_right = len(a)-1-a1
if a_left % (k-1) == 0:
    sol += int(a_left / (k-1))
else:
    sol += int(a_left / (k-1)) + 1
if a_right % (k-1) == 0:
    sol += int(a_right / (k-1))
else:
    sol += int(a_right / (k-1)) + 1

if sol != 0:
    print(sol)
else:
    print(1)
Problem p03221 (python)

Fixed submission:
import numpy as np


def solve(N, M, py):
    ans = np.zeros(M, dtype=object)
    rank = [1]*(N+1)

    py.sort()

    for pyi in py:
        pi = pyi[1]
        ans[pyi[2]] = str(pi).zfill(6) + str(rank[pi]).zfill(6)
        rank[pi] += 1

    return ans


if __name__ == "__main__":
    _p, _y = 0, 0
    py = []

    N, M = map(int, input().split())
    for i in range(M):
        _p, _y = map(int, input().split())
        py.append((_y, _p, i))

    ans = solve(N, M, py)
    for a in ans:
        print(a)

Buggy submission (verdict: Runtime Error):
import numpy as np


def solve(N, M):
    _p, _y = 0, 0
    py = []
    ans = np.zeros(M,dtype=object)
    rank = [1]*(M+1)

    for i in range(M):
        _p, _y = map(int, input().split())
        py.append((_y, _p, i))
    py.sort()

    for pyi in py:
        pi = pyi[1]
        ans[pyi[2]] = str(pi).zfill(6) + str(rank[pi]).zfill(6)
        rank[pi] += 1

    return ans


if __name__ == "__main__":
    N, M = map(int, input().split())
    ans = solve(N, M)
    for a in ans:
        print(a)
Problem p03426 (python)

Fixed submission:
from collections import defaultdict


def solve(row, col, d):
    x_map = defaultdict()

    for i in range(row):
        a_i = list(map(int, input().split()))
        for j in range(col):
            x_map[a_i[j]] = (i, j)

    q = int(input())

    dp = [0]*(row*col+1)
    for j in range(d+1, row*col+1):
        x_map_y = abs(x_map[j][0] - x_map[j-d][0])
        x_map_x = abs(x_map[j][1] - x_map[j-d][1])
        dp[j] = dp[j-d]+x_map_y+x_map_x
#        print("j {0} x_map_y : {1} x_map_x : {2} dp[j] : {3}".format(
#            j, x_map_y, x_map_x, dp[j]))

    for _ in range(q):
        l, r = map(int, input().split())
        print(dp[r]-dp[l])


if __name__ == '__main__':
    row, col, d = map(int, input().split())
    solve(row, col, d)

Buggy submission (verdict: Runtime Error):
def solve(row, col, d):
    x_map = [0]*(row**2)

    for i in range(row):
        a_i = list(map(int, input().split()))
        for j in range(col):
            x_map[a_i[j]-1] = (i, j)

#    for k in range(row):
#        print(x_map[k*row:(k+1)*row])
#
    q = int(input())

    mp = 0
    for _ in range(q):
        l, r = map(int, input().split())
        for current_pos in range(l+d-1, r, d):
#            print("curre_pos : {0}".format(current_pos))
#            print("cp : {0}".format(x_map[current_pos]))
#            print("pp : {0}".format(x_map[current_pos-d]))
            cp = x_map[current_pos]
            pp = x_map[current_pos-d]
            mp += abs(cp[1] - pp[1]) + abs(cp[0] - pp[0])
        print(mp)
        mp = 0


if __name__ == '__main__':
    row, col, d = map(int, input().split())
    solve(row, col, d)
Problem p02990 (python)

Fixed submission:
from math import factorial as fc

N,K = map(int,input().split())
MOD = (10 ** 9)+ 7

for i in range(1,K+1):
    if N-K+1<i:
        print(0)
        continue
    bunbo = fc(i)*fc(N-K+1-i)*fc(i-1)*fc(K-i)
    bunsi = fc(N-K+1)*fc(K-1)
    print((bunsi//bunbo)%MOD)

Buggy submission (verdict: Runtime Error):
from math import factorial as fc

N,K = map(int,input().split())

for i in range(1,K+1):
    bunbo = fc(i)*fc(N-K+1-i)*fc(i-1)*fc(K-i)
    bunsi = fc(N-K+1)*fc(K-1)
    print(bunsi//bunbo)
Problem p02989 (python)

Fixed submission:
n = int(input())
List = list(map(int, input().split()))
List.sort()
idx = n // 2
ans = List[idx]-List[idx-1]
print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
n = int(input())
List = list(map(int, input().split()))
List.sort()
idx = n // 2
ans = List[idx]-List[idx-1]
print(ans)