Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = list(map(int, input().split()))

tentosu_f = 0
tentosu_l = 0

for i in range(len(A)):
    for j in range(i+1, len(A)):
        if A[i] > A[j]:
            tentosu_f += 1
          
for i in range(len(A)):
    for j in range(len(A)):
        if A[i] > A[j]:
            tentosu_l += 1
            
ans = int(tentosu_f * k) + int(k*(k-1) / 2 * tentosu_l)
print(ans%(10**9+7))

Fixed submission:
# -*- coding: utf-8 -*-

# スペース区切りの整数の入力
m, d = map(int, input().split())
ans =0

for month in range(1, m+1):
    for i in range(22, d+1):
        d_list = list(str(i))
        d1   = int(d_list[1])
        d10 = int(d_list[0])
        if d1 < 2 or d10 < 2:
            continue
        if month == (d1 * d10):
            ans +=1

print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = input().split()

tentosu_f = 0
tentosu_l = 0

for i in range(len(n)):
    for j in range(i+1, len(n)):
        if A[i] > A[j]:
            tentosu_f += 1

for i in range(n):
    for j range(n):
        if A[i] > A[j]:
            tentosu_l += 1
            
ans = ((tentosu_f * k) + ((k* (k-1)) / 2) * tentosu_l) % (10**9 + 7)
print(ans)

Fixed submission:
mod = (10 ** 9) + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))

ten_f = 0
ten_l = 0

for i in range(N):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            ten_f += 1

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            ten_l += 1

ans = (ten_f * (K)) + ((K * ((K - 1)) // 2) * ten_l)
print(ans % mod)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = input().split()
B = A*k
tentosu = 0

for i in range(len(B)):
    for j in range(len(B)):
        if j <i:
            continue
        if B[i] > B[j]:
            tentosu += 1
            
ans = tentosu % (10**9 + 7)
print(ans)

Fixed submission:
mod = (10 ** 9) + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))

ten_f = 0
ten_l = 0

for i in range(N):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            ten_f += 1

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            ten_l += 1

ans = (ten_f * (K)) + ((K * ((K - 1)) // 2) * ten_l)
print(ans % mod)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = input().split()
B = A*k
tentosu = 0

for i in range(len(B)):
    for j in range(len(B)):
        if j <i:
            continue
        if B[i] > B[j]:
            print(i," ", j)
            tentosu += 1
print(tentosu)


Fixed submission:
mod = (10 ** 9) + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))

ten_f = 0
ten_l = 0

for i in range(N):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            ten_f += 1

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            ten_l += 1

ans = (ten_f * (K)) + ((K * ((K - 1)) // 2) * ten_l)
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

target = readInt()
nums = [i for i in range(3,target+1)]

dp = [0] * (1+target)
for num in nums:
    if num <= target:
        dp[num] = 1
for i in range(target+1):
    for num in nums:
        if i - num > 0:
            dp[i] += dp[i-num]
print(dp[-1]%mod

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

target = readInt()
nums = [i for i in range(3,target+1)]

dp = [0] * (1+target)
for num in nums:
    if num <= target:
        dp[num] = 1
for i in range(target+1):
    for num in nums:
        if i - num > 0:
            dp[i] += dp[i-num]
print(dp[-1]%mod)
Buggy python submission (verdict: Runtime Error):
allsets = []
n,t = list(map(int,input().split()))
for _ in range(t):
    a,b = list(map(int,input().split()))
    if a < b and [a,b] not in allsets:
        allsets.append([a,b])
    elif b < a and [b,a] not in allsets:
        allsets.append([b,a])
# print(allsets)
hmap = {}
visitedNode = {}
for a,b in allsets:
    if a in visitedNode:
        if b not in hmap[visitedNode[a]]:
            hmap[visitedNode[a]].append(b)
        del visitedNode[a]
        continue
    if a in hmap:
        hmap[a].append(b)
        visitedNode[b] = a
    else:
        hmap[a] = [b]
        visitedNode[b] = a
# print(hmap)
res = 0
for k,v in hmap.items():
    res = max(res,len(v)+1)
print(res)


Fixed submission:
d,t,s = list(map(int,input().split()))
res = d/s
print("Yes" if res <= t else "No")
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

n = readInt()
text = readStringList()
import collections
c  = collections.Counter(text)
if c['W'] == 0:
    print("0")
    exit()
i,j,count = 0,len(text)-1,0

while i <= j :
    if text[i] == 'W':
        while text[j] != 'R':
            j -= 1
        if i <= j:
            text[i],text[j] = text[j],text[i]
            count += 1
    i += 1
print(count)



Fixed submission:
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

n = readInt()
text = readStringList()
import collections
c  = collections.Counter(text)
if c['W'] == 0:
    print("0")
    exit()
i,j,count = 0,len(text)-1,0

while i <= j and i < len(text):
    if text[i] == 'W':
        while text[j] != 'R' and j > 0:
            j -= 1
        if i <= j and j > 0:
            text[i],text[j] = text[j],text[i]
            count += 1
    i += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = 0
while len(a) > 0:
  lena = len(a)
  ban = a.pop(0)
  ans = ans + (ban * sum(a[0:lena]))
if ans > 10 **9:
  ans = ans % (10 **9 + 7)
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 0
Sum = sum(a)
for i in range(n):
  Sum = Sum- a[i]
  ans = ans  + a[i] * Sum
if ans > 10 ** 9:
  ans = ans % (10 **9 + 7)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k=map(int, input().split())
plist = list(map(int, input().split()))
last = 0
point = 1
ans = []
while k <= len(plist):
  for i in range(k):
    point = point * plist[i]
  if last > 0:
    if point > last:
      print("Yes")
    else:
      print("No")
  last = point
  point = 1
  del plist[0]

Fixed submission:
import numpy as np
n, k=map(int, input().split())
plist = list(map(int, input().split()))
for i in range(n - k):
  if plist[i] < plist[k+i]:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a = input()
ans = a + (a ** 2) + (a ** 3)
print(ans)

Fixed submission:
a = int(input())
ans = a + (a ** 2) + (a ** 3)
print(ans)
Buggy python submission (verdict: Runtime Error):

if S == "ABC":
  print("ARC")
else:
  print("ABC")


Fixed submission:
S = input()
if S == "ABC":
  print("ARC")
else:
  print("ABC")

Buggy python submission (verdict: Runtime Error):
S = input()
if S == "ABC":
  print "ARC"
else:
  print "ABC"

Fixed submission:
S = input()
if S == "ABC":
  print("ARC")
else:
  print("ABC")

Buggy python submission (verdict: Runtime Error):
if S == "ABC":
  return "ARC"
else:
  return "ABC"

Fixed submission:
S = input()
if S == "ABC":
  print("ARC")
else:
  print("ABC")
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
flag = [1 for i in range(n)]
for _ in range(k):
  d = int(input())
  for _ in range(d):
    for a in map(int, input().split()):
      flag[a-1] = 0
print(sum(flag))

Fixed submission:
n,k = map(int, input().split())
flag = [1 for i in range(n)]
for _ in range(k):
  d = int(input())
  for a in map(int, input().split()):
      flag[a-1] = 0
print(sum(flag))

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
for k in range(k):
	d = int(input())
	for d in range(d):
    a.append({int(x) for x in input().split()})
    n = array_diff(n,a)
print(len(n))

Fixed submission:
n,k = map(int, input().split())
flag = [1 for i in range(n)]
for _ in range(k):
  d = int(input())
  for a in map(int, input().split()):
      flag[a-1] = 0
print(sum(flag))

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
for k in range(k):
	d = int(input())
	for d in range(d):
    a.append({int(x) for x in input().split()})
    n = array_diff(n,a)
print(n)

Fixed submission:
n,k = map(int, input().split())
flag = [1 for i in range(n)]
for _ in range(k):
  d = int(input())
  for a in map(int, input().split()):
      flag[a-1] = 0
print(sum(flag))

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
for k in range(k):
	d = input()
	for d in range(d):
      a = input()
    n = array_diff(n,d)
print(n)

Fixed submission:
n,k = map(int, input().split())
flag = [1 for i in range(n)]
for _ in range(k):
  d = int(input())
  for a in map(int, input().split()):
      flag[a-1] = 0
print(sum(flag))

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
for k in range(k):
	for n in range(n):
      a = list(map(int, input().split()))
      n = array_diff(n,a)
print(n)

Fixed submission:
n,k = map(int, input().split())
flag = [1 for i in range(n)]
for _ in range(k):
  d = int(input())
  for a in map(int, input().split()):
      flag[a-1] = 0
print(sum(flag))

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
for k in range(k+1):
	for d in range(n):
      a = list(map(int, input().split()))
      n = array_diff(n,a)
print(n)

Fixed submission:
n,k = map(int, input().split())
flag = [1 for i in range(n)]
for _ in range(k):
  d = int(input())
  for a in map(int, input().split()):
      flag[a-1] = 0
print(sum(flag))
Buggy python submission (verdict: Time Limit Exceeded):
A, B = [int(x) for x in input().split()]
tmp = 0
for i in range(A, B+1):
    if i == 0:
        tmp += i
    else:
        tmp = tmp ^ i
print(tmp)



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


def xor(x):
    tmp = (x + 1) % 4
    if tmp == 0:
        return 0
    elif tmp == 1:
        return x
    elif tmp == 2:
        return 1
    else:
        return 1 ^ x


print(xor(a - 1) ^ xor(b))
Buggy python submission (verdict: Runtime Error):
a, b, k = [int(x) for x in input().split()]
al = set()
for i in range(1, a):
    if a%i == 0:
        al.add(i)
bl = set()
for i in range(1, b):
    if b%i == 0:
        bl.add(i)
kk = list(al | bl)
print(kk[k-1])

Fixed submission:
a, b, k = [int(x) for x in input().split()]
al = set()
bl = set()
for i in range(1, a+1):
    if a%i == 0:
        al.add(i)
for i in range(1, b+1):
    if b%i == 0:
        bl.add(i)
kk = list(al & bl)
kk.sort(reverse=True)
print(kk[k-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = input().split()
A = []
for i in range(N):
    A.append(int(a[i]))
b = input().split()
B = []
for i in range(N):
    B.append(int(b[i]))
if sum(A) < sum(B):
    print(-1)
else:
    num = 0
    fix = 0
    for i in range(N):
        if A[i] - B[i] <  0:
            num += 1
            fix += B[i] - A[i]
if num == 0:
    print(0)
else:
    ret = []
    for i in range(N):
        if A[i] - B[i] > 0:
            ret.append(A[i] - B[i])
        else:
            ret.append(0)
    ret.sort(reverse=True)
    su = 0
    for i in range(N):
        su += ret[i]
        num += 1
        if su >= fix:
            break
    print(num)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
if sum(A) < sum(B):
    print(-1)
else:
    num, fix = 0, 0
    for i in range(N):
        if A[i] - B[i] <  0:
            num += 1
            fix += B[i] - A[i]
    if num != 0:
        ret = []
        for i in range(N):
            if A[i] - B[i] > 0:
                ret.append(A[i] - B[i])
        ret.sort(reverse=True)
        su = 0
        for i in range(len(ret)):
            su += ret[i]
            num += 1
            if su >= fix:
                break
    print(num)
Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt
from collections import Counter

def primes(N):
    is_prime = [True]*(N+1)
    is_prime[0] = False
    is_prime[1] = False
    D = [0]*(N+1)
    for n in range(2, int(sqrt(N)+1)):
        if is_prime[n]:
            D[n] = n
            j = n+n
            while j <= N:
                is_prime[j] = False
                D[j] = n
                j+=n
    for n in range(int(sqrt(N)), N+1):
        if is_prime[n]:
            D[n] = n
                
    return is_prime, D

def solve(N):
    is_prime, D = primes(N)
    total = 0
    for c in range(1, N-1):
        if is_prime[N-c] and False:
            total += 2
            continue

        C = Counter()
        x = N-c
        while x >= 2:
            d = D[x]
            C[d] += 1
            x //= d
        a = 1
        for k, v in C.items():
            a *= (v+1)
        #print(f"{N=} {c=}, {a=}, {C=}")
        total += a
    # c = N-1
    total += 1
    return total

N = int(input())
print(solve(N))

Fixed submission:
from math import sqrt
from collections import Counter

def primes(N):
    is_prime = [True]*(N+1)
    is_prime[0] = False
    is_prime[1] = False
    D = [0]*(N+1)
    for n in range(2, int(sqrt(N)+1)):
        if is_prime[n]:
            D[n] = n
            j = n+n
            while j <= N:
                is_prime[j] = False
                D[j] = n
                j+=n
    for n in range(int(sqrt(N)), N+1):
        if is_prime[n]:
            D[n] = n
                
    return is_prime, D

def solve(N):
    is_prime, D = primes(N)
    total = 0
    for c in range(1, N-1):
        if is_prime[N-c] and False:
            total += 2
            continue

        C = Counter()
        x = N-c
        while x >= 2:
            d = D[x]
            C[d] += 1
            x //= d
        a = 1
        for k, v in C.items():
            a *= (v+1)
        #print(f"{N=} {c=}, {a=}, {C=}")
        total += a
    # c = N-1
    total += 1
    return total

N = int(input())
print(solve(N))
Buggy python submission (verdict: Runtime Error):

def solve(S):
    dp = [0]*(S+1)
    dp[0] = 1
    dp[3] = 1
    MOD = 10**9+7
    for n in range(4, S+1):
        answer = 0
        for c in range(3, n+1):
            #print(n, "c=%d"%c, dp[c])
            answer = (answer + dp[n-c]) % MOD
        dp[n] = answer % MOD
        #print(n, dp[n])
    return dp[S]
#solve(7)
print(solve(int(input())))


Fixed submission:

def solve(S):
    dp = [0]*(2000+1)
    dp[0] = 1
    dp[3] = 1
    MOD = 10**9+7
    for n in range(4, S+1):
        answer = 0
        for c in range(3, n+1):
            #print(n, "c=%d"%c, dp[c])
            answer = (answer + dp[n-c]) % MOD
        dp[n] = answer % MOD
        #print(n, dp[n])
    return dp[S]
#solve(7)
print(solve(int(input())))
Buggy python submission (verdict: Runtime Error):
import sys
N = int(input())
A = [int(x) for x in input().split()]

def solve(N, A):
    S = 0
    C = [A[0]]
    for i in range(1,N):
        if A[i] == C[-1]:
            continue
        C.append(A[i])
    A = C
    C = [(A[0], '-' if A[0] <A[1] else '+')]
    for i in range(1,len(A)-1):
        if C[-1] ==  A[i]:
            continue
        if A[i-1] > A[i] <= A[i+1]:
            C.append((A[i], "-"))
        elif A[i-1] < A[i] >= A[i+1]:
            C.append((A[i], "+"))
    if C[-1][0] != A[-1]:
        C.append((A[-1], '+' if A[-1] > C[-1][0] else '-'))

    S = 0
    m = 1000
    if C and C[0][1] == '+':
        C = C[1:]
    if C and C[-1][1] == '-':
        C = C[:-1]
    #print(C,file=sys.stderr) 

    for p, s in C:
        m_ = m
        S_ = S
        if s == '+':
            m += p * S 
            S = 0
        else:
            # buy stock
            m -= (m_ // p) * p
            S = (m_ // p)
        #print(s, p, "money(%d -> %d)"%(m_, m), "stock(%d -> %d)"% (S_, S))
    print(m)

solve(N, A)




Fixed submission:
import sys
N = int(input())
A = [int(x) for x in input().split()]

def solve(N, A):
    S = 0
    C = [A[0]]
    for i in range(1,N):
        if A[i] == C[-1]:
            continue
        C.append(A[i])
    A = C
    if len(C) == 1:
        print(1000)
        return
    C = [(A[0], '-' if A[0] <A[1] else '+')]

    for i in range(1,len(A)-1):
        if C[-1] ==  A[i]:
            continue
        if A[i-1] > A[i] <= A[i+1]:
            C.append((A[i], "-"))
        elif A[i-1] < A[i] >= A[i+1]:
            C.append((A[i], "+"))
    if C[-1][0] != A[-1]:
        C.append((A[-1], '+' if A[-1] > C[-1][0] else '-'))

    S = 0
    m = 1000
    if C and C[0][1] == '+':
        C = C[1:]
    if C and C[-1][1] == '-':
        C = C[:-1]
    #print(C,file=sys.stderr) 

    for p, s in C:
        m_ = m
        S_ = S
        if s == '+':
            m += p * S 
            S = 0
        else:
            # buy stock
            m -= (m_ // p) * p
            S = (m_ // p)
        #print(s, p, "money(%d -> %d)"%(m_, m), "stock(%d -> %d)"% (S_, S))
    print(m)

solve(N, A)
Buggy python submission (verdict: Runtime Error):
def solve():
    n = int(input())

    def num_divisors_table(n):
        table = [0] * (n + 1)
        
        for i in range(1, n + 1):
            for j in range(i, n + 1, i):
                table[j] += 1
        
        return table

    table = num_divisors_table(n)
    print(sum(i*table[i] for i in range(n + 1))
solve()


Fixed submission:
N = int(input())

a = 0
def g(x):
    y = N//x
    return y * (y+1)*x//2

print(sum(g(x) for x in range(1,N+1)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
a = 1
U = 10**18
for x in A:
    a *= x
if a > U:
    a = -1
print(a)
    


Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
U = 10**18

def main(A):
    a = 1
    for x in A:
        if x == 0:
            return 0
    for x in A:
        a *= x
        if a > U:
            return -1
    return a

print(main(A))
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
A = int(A)
B = int(float(B) * 100)
print((A * B) / 100)

Fixed submission:
A, B = input().split()
A = int(A)
B = int(B.replace(".", ""))
print(A*B//100)
Buggy python submission (verdict: Time Limit Exceeded):

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

path = [[] for i in range(N)]
indicator = [None] * N
indicator[0] = (0, 0)
for i in range(M):
    a, b = map(int, input().split())
    a-=1
    b-=1
    path[a].append(b)
    path[b].append(a)

def solve(path, indicator):
    visit = set()
    visit.add(0)
    p = 0
    l = 0

    q = [(0, 0)]

    while q:
        (p, l), q = q[0], q[1:]
        for room in path[p]:
            if room in visit:
                continue
            if indicator[room] is None:
                indicator[room] = (p, l+1)
                q.append((room, l+1))
            elif indicator[room][1] > l+1:
                return []
            visit.add(room)
L = solve(path, indicator)
if L == []:
    print("No")
else:
    print("Yes")
    for p, l in indicator[1:]:
        print(p+1)







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

path = [[] for i in range(N)]
indicator = [None] * N
indicator[0] = (0, 0)
for i in range(M):
    a, b = map(int, input().split())
    a-=1
    b-=1
    path[a].append(b)
    path[b].append(a)

def solve(N, path, indicator):
    visit = [False]*N
    visit[0] = True
    p = 0
    l = 0
    q = deque()
    q.append((0, 0))

    while q:
        (p, l) = q.popleft()
        for room in path[p]:
            if visit[room]:
                continue
            if indicator[room] is None:
                indicator[room] = (p, l+1)
                q.append((room, l+1))
                visit[room] = True
            elif indicator[room][1] > l+1:
                return []

L = solve(N, path, indicator)
if L == []:
    print("No")
else:
    print("Yes")
    for p, l in indicator[1:]:
        print(p+1)
Buggy python submission (verdict: Runtime Error):
N, M
A = sum([int(x) for x in input().split()])
if N - M < 0:
  print(-1)
else:
  print(N-M)

Fixed submission:
N, M = map(int, input().split())
A = sum([int(x) for x in input().split()])
if N - A < 0:
  print(-1)
else:
  print(N-A)
Buggy python submission (verdict: Time Limit Exceeded):
def solve(H, N, AB):
    INF = 10e10
    dp = [[INF] * (H+1) for i in range(N+1)]
    dp[0][0] = 0
    A, B = AB[0]
    for j in range(H+1):
        dp[0][j] = min(dp[0][j], dp[0][max(0, j-A)]+B)
    for i in range(1,N):
        A, B = AB[i]
        for h in range(H+1):
            dp[i][h] = min(dp[i-1][h], dp[i][max(0, h-A)]+B)
        #print(i, *dp[i], sep="\t")
    
    return(dp[N-1][H])


def main():
    H, N = map(int, input().split())
    AB = []
    for i in range(N):
        A, B = map(int, input().split())
        AB.append((A, B))
    print(solve(H, N, AB))
main()


Fixed submission:
def solve(H, N, AB):
    INF = 10e10
    dp = [[INF] * (H+1) for i in range(N+1)]
    dp[0][0] = 0
    A, B = AB[0]
    for j in range(H+1):
        dp[0][j] = min(dp[0][j], dp[0][max(0, j-A)]+B)
    for i in range(1,N):
        A, B = AB[i]
        for h in range(H+1):
            dp[i][h] = min(dp[i-1][h], dp[i][max(0, h-A)]+B)
        #print(i, *dp[i], sep="\t")
    
    return(dp[N-1][H])


def main():
    H, N = map(int, input().split())
    AB = []
    for i in range(N):
        A, B = map(int, input().split())
        AB.append((A, B))
    print(solve(H, N, AB))
main()

Buggy python submission (verdict: Runtime Error):
def solve(H, N, AB):
    INF = 10e10
    dp = [[INF] * (H+1) for i in range(N+1)]
    dp[0][0] = 0
    A, B = AB[0]
    #print(" ", *range(H+1), sep="\t")
    for j in range(H+1):
        dp[0][j] = min(dp[0][j], dp[0][j-A]+B)
    #print(0, *dp[0], sep="\t")
    for i in range(1,N):
        A, B = AB[i]
        for h in range(H+1):
            dp[i][h] = min(dp[i-1][h], dp[i][max(0, h-A)]+B)
        #print(i, *dp[i], sep="\t")
    
    return(dp[N-1][H])


def main():
    H, N = map(int, input().split())
    AB = []
    for i in range(N):
        A, B = map(int, input().split())
        AB.append((A, B))
    print(solve(H, N, AB))
main()


Fixed submission:
def solve(H, N, AB):
    INF = 10e10
    dp = [[INF] * (H+1) for i in range(N+1)]
    dp[0][0] = 0
    A, B = AB[0]
    for j in range(H+1):
        dp[0][j] = min(dp[0][j], dp[0][max(0, j-A)]+B)
    for i in range(1,N):
        A, B = AB[i]
        for h in range(H+1):
            dp[i][h] = min(dp[i-1][h], dp[i][max(0, h-A)]+B)
        #print(i, *dp[i], sep="\t")
    
    return(dp[N-1][H])


def main():
    H, N = map(int, input().split())
    AB = []
    for i in range(N):
        A, B = map(int, input().split())
        AB.append((A, B))
    print(solve(H, N, AB))
main()
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
N = int(input())

o = {}
for i, p in enumerate(permutation(range(1,N+1))):
  	o[p] = i
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())
print(abs(o[P] - o[Q]))

Fixed submission:
from itertools import permutations
N = int(input())

o = {}
for i, p in enumerate(permutations(range(1,N+1))):
  	o[p] = i
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())
print(abs(o[P] - o[Q]))