Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np

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

grid = np.array([list(input()) for _ in range(H)])

# dp[h][w] = (0,0) から (h,w) までの経路の本数
dp = np.zeros((H, W))
# 初期値
dp[0][0] = 1

# mod用
MOD_INT = 10 ** 9 + 7

for h in range(H):
    for w in range(W):
        # 右が範囲内の空マスなら現在マスの経路数を足す
        if w + 1 < W and grid[h][w + 1] == ".":
            # modを取って更新
            dp[h][w + 1] += np.mod(dp[h][w], MOD_INT)
        # 下が範囲内の空マスなら現在マスの経路数を足す
        if h + 1 < H and grid[h + 1][w] == ".":
            # modを取って更新
            dp[h + 1][w] = np.mod(dp[h][w], MOD_INT)

ans = np.mod(dp[H - 1][W - 1], MOD_INT)
print(int(ans))


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

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

grid = [list(input()) for _ in range(H)]

# dp[h][w] = (0,0) から (h,w) までの経路の本数
dp = [[0] * W for _ in range(H)]
# 初期値
dp[0][0] = 1

# mod用
MOD_INT = 10 ** 9 + 7

for h in range(H):
    for w in range(W):
        # 右が範囲内の空マスなら現在マスの経路数を足す
        if w + 1 < W and grid[h][w + 1] == ".":
            # modを取って更新
            dp[h][w + 1] += dp[h][w] % MOD_INT
        # 下が範囲内の空マスなら現在マスの経路数を足す
        if h + 1 < H and grid[h + 1][w] == ".":
            # modを取って更新
            dp[h + 1][w] += dp[h][w] % MOD_INT

ans = dp[H - 1][W - 1] % MOD_INT
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np

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

grid = np.array([list(input()) for _ in range(H)])

# dp[h][w] = (0,0) から (h,w) までの経路の本数
dp = np.zeros((H, W))
# 初期値
dp[0][0] = 1

# mod用
MOD_INT = 1000000007

for h in range(H):
    for w in range(W):
        # 右が範囲内の空マスなら現在マスの経路数を足す
        if w + 1 < W and grid[h][w + 1] == ".":
            dp[h][w + 1] += dp[h][w]
            # modを取って更新
            dp[h][w + 1] = np.mod(dp[h][w + 1], MOD_INT)
        # 下が範囲内の空マスなら現在マスの経路数を足す
        if h + 1 < H and grid[h + 1][w] == ".":
            dp[h + 1][w] += dp[h][w]
            # modを取って更新
            dp[h + 1][w] = np.mod(dp[h + 1][w], MOD_INT)

print(int(dp[H - 1][W - 1]))


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

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

grid = [list(input()) for _ in range(H)]

# dp[h][w] = (0,0) から (h,w) までの経路の本数
dp = [[0] * W for _ in range(H)]
# 初期値
dp[0][0] = 1

# mod用
MOD_INT = 10 ** 9 + 7

for h in range(H):
    for w in range(W):
        # 右が範囲内の空マスなら現在マスの経路数を足す
        if w + 1 < W and grid[h][w + 1] == ".":
            # modを取って更新
            dp[h][w + 1] += dp[h][w] % MOD_INT
        # 下が範囲内の空マスなら現在マスの経路数を足す
        if h + 1 < H and grid[h + 1][w] == ".":
            # modを取って更新
            dp[h + 1][w] += dp[h][w] % MOD_INT

ans = dp[H - 1][W - 1] % MOD_INT
print(int(ans))
Buggy python submission (verdict: Runtime Error):
strN, strT = input().split()
N = int(strN)
max_t = int(strT)

min_cost: int = 0
for i in range(1, N+1):
    str_cost, str_time = input().split()
    cost = int(str_cost)
    t = int(str_time)
    if max_t < t:
        continue
    if min_cost == 0:
        min_cost = cost
    elif min_cost > cost:
        min_cost = cost

if min_cost == 0:
    print('TLE')
else:
    print(min_cost)


Fixed submission:
strN, strT = input().split()
N = int(strN)
max_t = int(strT)

min_cost = 0
for i in range(1, N+1):
    str_cost, str_time = input().split()
    cost = int(str_cost)
    t = int(str_time)
    if max_t < t:
        continue
    if min_cost == 0:
        min_cost = cost
    elif min_cost > cost:
        min_cost = cost

if min_cost == 0:
    print('TLE')
else:
    print(min_cost)
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def main():
    n = int(input())
    a = [int(i) for i in sys.stdin.readline().split()]
    ans = []
    ans_append = ans.append
    for i in range(n):
        ans_append(a.index(i + 1) + 1)
    print(*ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def main():
    n = int(input())
    a = [int(i) for i in sys.stdin.readline().split()]
    ans = [0] * n
    for i in range(n):
        ans[a[i] - 1] = i + 1
    print(*ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = []
    ans_append = ans.append
    for i in range(n):
        ans_append(a.index(i + 1) + 1)
    print(*ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def main():
    n = int(input())
    a = [int(i) for i in sys.stdin.readline().split()]
    ans = [0] * n
    for i in range(n):
        ans[a[i] - 1] = i + 1
    print(*ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = []
    for i in range(n):
        ans.append(a.index(i + 1) + 1)
    print(*ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def main():
    n = int(input())
    a = [int(i) for i in sys.stdin.readline().split()]
    ans = [0] * n
    for i in range(n):
        ans[a[i] - 1] = i + 1
    print(*ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
ans = []
for i in range(n):
    ans.append(a.index(i + 1) + 1)
print(*ans)


Fixed submission:
import sys


def main():
    n = int(input())
    a = [int(i) for i in sys.stdin.readline().split()]
    ans = [0] * n
    for i in range(n):
        ans[a[i] - 1] = i + 1
    print(*ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
ans = []
for i in range(n):
    ans.append(a.index(i + 1) + 1)
print(*ans)


Fixed submission:
import sys


def main():
    n = int(input())
    a = [int(i) for i in sys.stdin.readline().split()]
    ans = [0] * n
    for i in range(n):
        ans[a[i] - 1] = i + 1
    print(*ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
if len(c) == 1:
    print(sum(b) + sum(c))
else:
    print(sum(b) + sum(c) - c[a[n - 1] - 1])


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = b[a[0] - 1]
for i in range(1, n):
    ans += b[a[i] - 1]
    if a[i] == a[i - 1] + 1:
        ans += c[a[i - 1] - 1]
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = [int(i) for i in input().split()]
v.sort()
ans = v[0]
for i in range(2, len(v)):
    ans = (ans + v[i]) / 2
print(ans)


Fixed submission:
a = int(input())
s = input()
if a >= 3200:
    print(s)
else:
    print("red")

Buggy python submission (verdict: Runtime Error):
n = int(input())
v = [int(i) for i in input().split()]
v.sort()
ans = v[0]
for i in range(1, len(v)):
    ans = (ans + v[i]) / 2
print(ans)


Fixed submission:
a = int(input())
s = input()
if a >= 3200:
    print(s)
else:
    print("red")
Buggy python submission (verdict: Runtime Error):
num = input().split()
k = int(num[0])
x = int(num[1])
ans = []
for i in range(x - k + 1, x + k):
    ans.append(i)
print(ans)
s

Fixed submission:
num = input().split()
k = int(num[0])
x = int(num[1])
ans = []
for i in range(x - k + 1, x + k):
    print(i)
Buggy python submission (verdict: Runtime Error):
n = int(input())
odd = []
for i in range(1, n + 1):
    if len(str(i)) % 2 == 1:
        odd.append(i)
print(len(odd))


Fixed submission:
num = input().split()
a = int(num[0])
b = int(num[1])
c = int(num[2])
ans = b + c - a
if ans > 0:
    print(ans)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
num = input().split()
a = num[0]
b = num[1]
c = num[2]
ans = b + c - a
if ans > 0:
    print(ans)
else:
    print(0)


Fixed submission:
num = input().split()
a = int(num[0])
b = int(num[1])
c = int(num[2])
ans = b + c - a
if ans > 0:
    print(ans)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = [int(i) for i in input().split()]
if h[0] != 1:
    h[0] -= 1
if len(h) == 1:
    print('Yes')
else:
    for i in range(1, n):
        if h[i] > h[i - 1]:
            h[i] -= 1
        elif h[i] < h[h - 1]:
            print('No')
            exit()
    print('Yes')


Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]
h[0] -= 1
flag = [True]
if len(h) == 1:
    print('Yes')
else:
    for i in range(1, n):
        if h[i] > h[i - 1]:
            h[i] -= 1
        elif h[i] < h[i - 1]:
            print('No')
            exit()
    print('Yes')

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = [int(i) for i in input().split()]
if h[0] != 1:
    h[0] -= 1
if len(h) == 1:
    print('Yes')
else:
    for i in range(1, n):
        if h[i - 1] < h[i]:
            h[i] -= 1
        elif h[i] < h[h - 1]:
            print('No')
            exit()
    print('Yes')


Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]
h[0] -= 1
flag = [True]
if len(h) == 1:
    print('Yes')
else:
    for i in range(1, n):
        if h[i] > h[i - 1]:
            h[i] -= 1
        elif h[i] < h[i - 1]:
            print('No')
            exit()
    print('Yes')
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print((a*3 + b) // 2)


Fixed submission:
a, b = map(int, input().split())
print((a*3 + b) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(a) for a in input().split()]

for m in range(M):
    index = A.index(max(A))
    A[index] //= 2

ans = 0
for i in range(N):
    ans += A[i]

print(ans)


Fixed submission:
import heapq

N, M = map(int, input().split())
A = [-int(x) for x in input().split()]

# 優先度付きキューに変換
heapq.heapify(A)

# 最小値（最大値）の値を半分にしていく
for i in range(M):
    tmp = -heapq.heappop(A) // 2
    heapq.heappush(A, -tmp)

print(-sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(a) for a in input().split()]

A.sort()
A.reverse()
for _ in range(M):
    A[0] = A[0] // 2
    A.sort()
    A.reverse()

ans = 0
for i in range(N):
    ans += A[i]

print(ans)


Fixed submission:
import heapq

N, M = map(int, input().split())
A = [-int(x) for x in input().split()]

# 優先度付きキューに変換
heapq.heapify(A)

# 最小値（最大値）の値を半分にしていく
for i in range(M):
    tmp = -heapq.heappop(A) // 2
    heapq.heappush(A, -tmp)

print(-sum(A))
Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
cnt = 0
for i in input().split();
	if m <= int(i):
    	cnt += 1
print(cnt)

Fixed submission:
n, m = [int(i) for i in input().split()]
cnt = 0
for i in input().split():
  if m <= int(i):
    cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
2
100 1 1
1 100

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
cnt = 0
for i in range(N):
  cnt += min(A[i]+A[i+1], B[i])
  if A[i] < B[i]:
    A[i+1] = max(A[i+1]+A[i]-B[i], 0)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
arr = []
temp = D
if D == 1:
  pass
else:
  for i in range(2, D+1):
    if temp%i == 0:
      while temp%i == 0:
        temp //= i
      arr.append(i)
  if len(arr) == 0:
    arr.append(D)
print(len(arr)+1)

Fixed submission:
import fractions

A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
arr = []
temp = D
if D == 1:
  pass
else:
  for i in range(2, int(-(-D**0.5//1)+1)):
    if temp%i == 0:
      while temp%i == 0:
        temp //= i
      arr.append(i)
  if temp != 1:
    arr.append(D)
print(len(arr)+1)

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

A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
arr = []
temp = D
if D != 1:
  for i in range(2, int(-(-D**0.5//1)+2)):
    if temp%i == 0:
      while temp%i == 0:
        temp //= i
      arr.append(i)
    if len(arr) == 0:
      append.arr(D)
print(len(arr)+1)

Fixed submission:
import fractions

A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
arr = []
temp = D
if D == 1:
  pass
else:
  for i in range(2, int(-(-D**0.5//1)+1)):
    if temp%i == 0:
      while temp%i == 0:
        temp //= i
      arr.append(i)
  if temp != 1:
    arr.append(D)
print(len(arr)+1)

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

A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
arr = []
temp = D
if D != 1:
  for i in range(2, int(-(-D**0.5//1)+2)):
    if temp%i == 0:
      while temp%i == 0:
        temp //= i
      arr.append(i)
    if len(arr) == 0:
      append.arr(D)
else:
  pass
print(len(arr)+1)

Fixed submission:
import fractions

A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
arr = []
temp = D
if D == 1:
  pass
else:
  for i in range(2, int(-(-D**0.5//1)+1)):
    if temp%i == 0:
      while temp%i == 0:
        temp //= i
      arr.append(i)
  if temp != 1:
    arr.append(D)
print(len(arr)+1)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions

data = [i for i in range(2, 10**12)]
for d in data:
	data = [x for x in data if (x == d or x % d != 0)]
A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
x = 1
for d in data:
  if D%d == 0:
    x = x+1
  else:
    pass
print(x)

Fixed submission:
import fractions

A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
arr = []
temp = D
if D == 1:
  pass
else:
  for i in range(2, int(-(-D**0.5//1)+1)):
    if temp%i == 0:
      while temp%i == 0:
        temp //= i
      arr.append(i)
  if temp != 1:
    arr.append(D)
print(len(arr)+1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
t = [0] * (N+1)
x = [0] * (N+1)
y = [0] * (N+1)
D = [0] * N
T = [0] * N
for i in range(N):
  t[i+1], x[i+1], y[i+1] = map(int, input().split())
for i in range(N-1):
  D[i] = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
  T[i] = t[i+1] - t[i]
ans = 'Yes'
for i in range (N-1):
  if D[i] <= T[i] and (D[i] - T[i])%2 == 0:
    ans = 'Yes'
  else:
    ans = 'No'
print(ans)

Fixed submission:
a , b = map(int, input().split())
c = a*b
if c%2 == 1:
  print("Odd")
else:
  print("Even")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
t = 0
def exist_odd(A):
  for i in A:
    if i % 2 == 1:
      break
    return 1
  else:
    return 0
while exist_odd(A) ==1:
  A = list(map(lambda x: x / 2, A))
  t = t+1
print(t)

Fixed submission:
s = input()
print(int(s[0])+int(s[1])+int(s[2]))
Buggy python submission (verdict: Runtime Error):
n = input()
a = list(map(int, input().split()))

while True:
    idx = 0
    m = a[0]
    for i in range(len(a)):
        aa = a[i]
        if aa > 0 and aa < m:
            idx = i
            m = a[idx]
    count = 1
    for i in range(len(a)):
        if i != idx:
            a[i] = a[i] % m
            if a[i] == 0:
                count += 1
    if count == len(a):
        break
for aa in a:
    if aa > 0:
        print(aa)
        break

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

while len(a) > 1:
    idx = 0
    m = a[0]
    for i in range(len(a)):
        aa = a[i]
        if aa > 0 and aa < m:
            idx = i
            m = a[idx]
    for i in range(len(a)):
        if i != idx:
            a[i] = a[i] % m
    a = [aa for aa in a if aa > 0]
print(a[0])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

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

def fill(t):
    s = str(t)
    while len(s) < 6:
        s = "0" + s
    return s

Pi.sort(key=lambda x: x[1])
counts = [1] * (M + 1)
for p in Pi:
    city = p[0]
    num = counts[city]
    counts[city] += 1
    p.append(fill(city) + fill(num))

Pi.sort(key=lambda x: x[2])
for p in Pi:
    print(p[3])


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

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

def fill(t):
    s = str(t)
    while len(s) < 6:
        s = "0" + s
    return s

Pi.sort(key=lambda x: x[1])
counts = [1] * (N + 1)
for p in Pi:
    city = p[0]
    num = counts[city]
    counts[city] += 1
    p.append(fill(city) + fill(num))

Pi.sort(key=lambda x: x[2])
for p in Pi:
    print(p[3])
Buggy python submission (verdict: Time Limit Exceeded):
# a1 + a2 + a3 ... + an = M
# ai の 最大公約数をDとする
# ai = xi * D　のはず。 D * x0 + D * x1 ... + D * xn = M
# まとめて D(x1 + x2 + .... + xn) = M
# 変形し、D = M / (x1 + x2 + .... + xn)
# (x1 + ... xn) = K とすると、Kを最小化するとDが最大化する
# M / K が割り切れる必要があるので、KはMの約数のいずれか
# K >= N。なぜなら xi >= 1 なので、Kは最低でも数字の個数 N になる
# つまり、約数のうちで N 以上の最初の値が K になる
# ex: 3 14
# 14 の約数 {1, 2, 7}
# K >= N なので、　K >= 3
# K = 7 で確定。つまり D = M/K = 2 でAnswer

N, M = map(int, input().split())
for i in range(1, M + 1):
    if M % i == 0 and i >= N:
        print(M // i)
        break


Fixed submission:
# a1 + a2 + a3 ... + an = M
# ai の 最大公約数をDとする
# ai = xi * D　のはず。 D * x0 + D * x1 ... + D * xn = M
# まとめて D(x1 + x2 + .... + xn) = M
# 変形し、D = M / (x1 + x2 + .... + xn)
# (x1 + ... xn) = K とすると、Kを最小化するとDが最大化する
# M / K が割り切れる必要があるので、KはMの約数のいずれか
# K >= N。なぜなら xi >= 1 なので、Kは最低でも数字の個数 N になる
# つまり、約数のうちで N 以上の最初の値が K になる
# ex: 3 14
# 14 の約数 {1, 2, 7}
# K >= N なので、　K >= 3
# K = 7 で確定。つまり D = M/K = 2 でAnswer

N, M = map(int, input().split())
M_ROOT = int(M ** 0.5)
k = M
for i in range(1, M_ROOT + 1):
    if M % i == 0:
        if i >= N:
            print(M // i)
            exit()
        d = M // i
        if d < k and d >= N:
            k = d
print(M // k)
Buggy python submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())

Xi = list(map(int, input().split()))
Xi.sort()
Di = []
found = False
for i in range(N - 1):
    if not found and Xi[i] < X and Xi[i + 1] >= X:
        Di.append(X - Xi[i])
        Di.append(Xi[i  + 1] - X)
        found = True
    elif Xi[i] != Xi[i + 1]:
        Di.append(Xi[i + 1] - Xi[i])
if not found:
    Di.append(X - Xi[-1])
Dl = len(Di)
if Dl == 0:
    print(abs(X - Xi[0]))
else:
    gcd = Di[0]
    for i in range(1, Dl):
        gcd = math.gcd(gcd, Di[i])
    print(gcd)

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

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

Xi = list(map(int, input().split()))
Xi.sort()
Di = []
for i in range(N):
    Di.append(abs(X - Xi[i]))
DLen = len(Di)
g = Di[0]
for i in range(1, DLen):
    if Di[i] != 0:
        g = gcd(g, Di[i])
print(g)

Buggy python submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())

Xi = list(map(int, input().split()))
Xi.sort()
Di = []
found = False
for i in range(N - 1):
    if not found and Xi[i] >= X and Xi[i + 1] < X:
        Di.append(X - Xi[i])
        Di.append(Xi[i  + 1] - X)
        found = True
    else:
        Di.append(Xi[i + 1] - Xi[i])

if len(Di) == 0:
    print(abs(X - Xi[0]))
else:
    gcd = Di[0]
    for i in range(1, N - 1):
        gcd = math.gcd(gcd, Di[i])
    print(gcd)


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

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

Xi = list(map(int, input().split()))
Xi.sort()
Di = []
for i in range(N):
    Di.append(abs(X - Xi[i]))
DLen = len(Di)
g = Di[0]
for i in range(1, DLen):
    if Di[i] != 0:
        g = gcd(g, Di[i])
print(g)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, M, Q = map(int, input().split())
N_Map = np.zeros((N + 1, N + 1))
for _ in range(M):
    a = list(map(int, input().split()))
    N_Map[:a[0] + 1, a[1]:] += 1

result = []
for _ in range(Q):
    a = list(map(int, input().split()))
    result.append(N_Map[a[0], a[1]])
for r in result:
    print(int(r))

Fixed submission:
N, M, Q = map(int, input().split())
N_Map = [[0 for _ in range(N + 1)] for _ in range(N + 1)]

for _ in range(M):
    a = list(map(int, input().split()))
    N_Map[a[0]][a[1]] += 1

for i in range(N, 0, -1):
    count = 0
    for j in range(1, N  + 1):
        count += N_Map[i][j]
        if i < N:
            N_Map[i][j] = N_Map[i + 1][j] + count
        else:
            N_Map[i][j] = count

Pi = []
for _ in range(Q):
    a = list(map(int, input().split()))
    Pi.append(a)

for p in Pi:
    print(N_Map[p[0]][p[1]])

Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())

N_Map = [[0 for _ in range(N + 1)] for _ in range(N + 1)]

Li = []
for _ in range(M):
    a = list(map(int, input().split()))
    Li.append(a)
    N_Map[a[0]][a[1]] += 1

Pi = []
for _ in range(Q):
    a = list(map(int, input().split()))
    Pi.append(a)

for p in Pi:
    ans = 0
    for i in range(p[0], p[1] + 1):
        for j in range(p[0], p[1] + 1):
            ans += N_Map[i][j]
    print(ans)


Fixed submission:
N, M, Q = map(int, input().split())
N_Map = [[0 for _ in range(N + 1)] for _ in range(N + 1)]

for _ in range(M):
    a = list(map(int, input().split()))
    N_Map[a[0]][a[1]] += 1

for i in range(N, 0, -1):
    count = 0
    for j in range(1, N  + 1):
        count += N_Map[i][j]
        if i < N:
            N_Map[i][j] = N_Map[i + 1][j] + count
        else:
            N_Map[i][j] = count

Pi = []
for _ in range(Q):
    a = list(map(int, input().split()))
    Pi.append(a)

for p in Pi:
    print(N_Map[p[0]][p[1]])
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
Ai = list(map(int, input().split()))

#-----------------
fact = [0 for _ in range(N + 1)]
fact[0] = 1
for i in range(1, N + 1):
    fact[i] = fact[i - 1] * i

def comb(n, m):
    return fact[n] // (fact[m] * fact[n - m])

#---------------
d = defaultdict(int)
total = Ai[0] % M
d[0] = 1
d[total] += 1
for i in range(1, N):
    total = (total + Ai[i]) % M
    d[total] += 1
#-----------------
ans = 0
for k in d.keys():
    c = d[k]
    if c > 1:
        ans += comb(c, 2)
print(ans)

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

#---------------
d = defaultdict(int)
d[0] = 1
total = 0
for i in range(N):
    total = (total + Ai[i]) % M
    d[total] += 1
#-----------------
ans = 0
for k, c in d.items():
    if c > 1:
        ans += c * (c - 1) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
Ai = list(map(int, input().split()))

for i in range(N):
    for j in range(i, N):
        t = 0
        for k in range(i, j + 1):
            t += Ai[k]

#-----------------
fact = [0 for _ in range(N + 1)]
fact[0] = 1
for i in range(1, N + 1):
    fact[i] = fact[i - 1] * i

def comb(n, m):
    return fact[n] // (fact[m] * fact[n - m])

#---------------
d = defaultdict(int)
total = Ai[0] % M
d[0] = 1
d[total] += 1
for i in range(1, N):
    total = (total + Ai[i]) % M
    d[total] += 1
#-----------------
ans = 0
for k in d.keys():
    c = d[k]
    if c >= 1:
        ans += comb(c, 2)
print(ans)

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

#---------------
d = defaultdict(int)
d[0] = 1
total = 0
for i in range(N):
    total = (total + Ai[i]) % M
    d[total] += 1
#-----------------
ans = 0
for k, c in d.items():
    if c > 1:
        ans += c * (c - 1) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

limit = pow(10, 18)

ans = 0
unfair = False
for v in range(k):
    if a == b and b == c:
        break
    na = b + c
    nb = a + c
    nc = a + b
    a = na
    b = nb
    c = nc
ans = a - b
if abs(ans) > limit:
    print("Unfair")
else:
    print(ans)


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

if k % 2 == 0:
    print(a - b)
else:
    print(b - a)