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

k = int(input())
ans = 0

for i in range(1, k+1):
    for j in range(1, k+1):
        for t in range(1, k+1):
            ans += math.gcd(math.gcd(i, j), t)
print(ans)


Fixed submission:
import math

k = int(input())
ans = 0

for i in range(1, k+1):
    for j in range(1, k+1):
        for t in range(1, k+1):
            ans += math.gcd(math.gcd(i, j), t)
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict as dict

n, p = map(int, input().split())
s = input()
a = []
for x in s:
    a.append(int(x))

def solve():
    l = [0]*p
    ans = 0
    for x in a:
        l_ = [0] * p
        for i in range(p):
            l_[(i * 10 + x) % p] += l[i]
        l, l_ = l_, l
        l[x % p] += 1
        ans += l[0]
    print(ans)
if p <= 5:
    solve()
    exit()
exit(1)
x = 0
mem = dict(int)
mem[0] = 1
ans = 0
for y in a:
    x = (x * 10 + y) % p
    ans += mem[x]
    mem[x] += 1
    # print(mem)
print(ans)

Fixed submission:
from collections import defaultdict as dict

n, p = map(int, input().split())
s = input()
a = []
for x in s:
    a.append(int(x))

def solve():
    l = [0]*p
    ans = 0
    for x in a:
        l_ = [0] * p
        for i in range(p):
            l_[(i * 10 + x) % p] += l[i]
        l, l_ = l_, l
        l[x % p] += 1
        ans += l[0]

    print(ans)
if p <= 5:
    solve()
    exit()
x = 0
mem = dict(int)
mem[0] = 1
ans = 0
a.reverse()
d = 1
for y in a:
    x += d*y
    x %= p
    d = (d * 10) % p
    ans += mem[x]
    mem[x] += 1
    # print(mem)

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict as dict

n, p = map(int, input().split())
s = input()
a = []
for x in s:
    a.append(int(x))

def solve():
    l = [0]*p
    ans = 0
    for x in a:
        l_ = [0] * p
        for i in range(p):
            l_[(i * 10 + x) % p] += l[i]
        l, l_ = l_, l
        l[x % p] += 1
        ans += l[0]
    print(ans)
if p <= 5:
    solve()
    exit()

x = 0
mem = dict(int)
mem[0] = 1from collections import defaultdict as dict

n, p = map(int, input().split())
s = input()
a = []
for x in s:
    a.append(int(x))

def solve():
    l = [0]*p
    ans = 0
    for x in a:
        l_ = [0] * p
        for i in range(p):
            l_[(i * 10 + x) % p] += l[i]
        l, l_ = l_, l
        l[x % p] += 1
        ans += l[0]
    print(ans)
if p <= 5:
    solve()
    exit()

exit(1)
x = 0
mem = dict(int)
mem[0] = 1
ans = 0
for y in a:
    x = (x * 10 + y) % p
    ans += mem[x]
    mem[x] += 1
    # print(mem)
print(ans)
ans = 0
for y in a:
    x = (x * 10 + y) % p
    ans += mem[x]
    mem[x] += 1
    # print(mem)
print(ans)

Fixed submission:
from collections import defaultdict as dict

n, p = map(int, input().split())
s = input()
a = []
for x in s:
    a.append(int(x))

def solve():
    l = [0]*p
    ans = 0
    for x in a:
        l_ = [0] * p
        for i in range(p):
            l_[(i * 10 + x) % p] += l[i]
        l, l_ = l_, l
        l[x % p] += 1
        ans += l[0]

    print(ans)
if p <= 5:
    solve()
    exit()
x = 0
mem = dict(int)
mem[0] = 1
ans = 0
a.reverse()
d = 1
for y in a:
    x += d*y
    x %= p
    d = (d * 10) % p
    ans += mem[x]
    mem[x] += 1
    # print(mem)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
s = []
for c in n:
    s.append(int(c))
s.reverse()
l = len(s)
INF = 1000000000


def get_next(c):
    ret = [
        [INF, INF],
        [INF, INF],
    ]
    for a in range(10):
        for b in range(10):
            if a - b == c:
                ret[0][0] = min(ret[0][0], a + b)
            if 10 + a - b == c:
                ret[0][1] = min(ret[0][1], a + b)
            if a - 1 - b == c:
                ret[1][0] = min(ret[1][0], a + b)
            if 10 + a - 1 - b == c:
                ret[1][1] = min(ret[1][1], a + b)
    return ret


dp = [[0 for _ in range(l+1)] for _ in range(2)]

dp[1][0] = INF

for i, c in enumerate(s):
    next_step = get_next(c)
    dp[0][i+1] = min(dp[0][i]+next_step[0][0], dp[1][i]+next_step[1][0])
    dp[1][i+1] = min(dp[0][i]+next_step[0][1], dp[1][i]+next_step[1][1])

print(min(dp[0][l], dp[1][l]+1))
# print(dp)

Fixed submission:
n = input()
s = []
for c in n:
    s.append(int(c))
s.reverse()
l = len(s)
INF = 1000000000


def get_next(c):
    ret = [
        [INF, INF],
        [INF, INF],
    ]
    # for a in range(10):
    #     for b in range(10):
    #         if a - b == c:
    #             ret[0][0] = min(ret[0][0], a + b)
    #         if 10 + a - b == c:
    #             ret[0][1] = min(ret[0][1], a + b)
    #         if a - 1 - b == c:
    #             ret[1][0] = min(ret[1][0], a + b)
    #         if 10 + a - 1 - b == c:
    #             ret[1][1] = min(ret[1][1], a + b)
    for b in range(10):
        a = c + b
        if 0 <= a < 10:
            ret[0][0] = min(ret[0][0], a+b)
        a = c + b - 10
        if 0 <= a < 10:
            ret[0][1] = min(ret[0][1], a+b)
        a = c + b + 1
        if 0 <= a < 10:
            ret[1][0] = min(ret[1][0], a + b)
        a = c + b - 10 + 1
        if 0 <= a < 10:
            ret[1][1] = min(ret[1][1], a + b)
    return ret


dp = [[0 for _ in range(l+1)] for _ in range(2)]

dp[1][0] = INF

for i, c in enumerate(s):
    next_step = get_next(c)
    dp[0][i+1] = min(dp[0][i]+next_step[0][0], dp[1][i]+next_step[1][0])
    dp[1][i+1] = min(dp[0][i]+next_step[0][1], dp[1][i]+next_step[1][1])

print(min(dp[0][l], dp[1][l]+1))
# print(dp)
Buggy python submission (verdict: Runtime Error):
import math

def lcm(a, b):
    return (a*b)//math.gcd(a,b)

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

a = list(map(int, input().split()))

x = 1

for y in a:
    x = lcm(x, y//2)

for y in a:
    if (x//(y//2)) % 2 == 0:
        print(0)
        exit()

max_n = (m-x)//(2*x)

print(max_n+1)


Fixed submission:

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

def lcm(a, b):
    return (a*b)//gcd(a,b)

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

a = list(map(int, input().split()))

x = 1

for y in a:
    x = lcm(x, y//2)

for y in a:
    if (x//(y//2)) % 2 == 0:
        print(0)
        exit()

max_n = (m-x)//(2*x)

print(max_n+1)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
return A*B

Fixed submission:
a, b = map(int, input().split())
print(a*b)

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

Fixed submission:
a, b = map(int, input().split())
print(a*b)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 1
for i in range(N):
    ans *= A[i]

if ans > 1e18:
    ans = -1

print(ans)

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

if 0 in A:
    print(0)
    exit()

ans = 1
for i in range(N):
    ans *= A[i]
    if ans > 1e18:
        ans = -1
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 1
for _ in range(N):
	ans *= int(input())
    if ans > 1e18:
    	ans = -1
        break
print(ans)

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

if 0 in A:
    print(0)
    exit()

ans = 1
for i in range(N):
    ans *= A[i]
    if ans > 1e18:
        ans = -1
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

def ave(v):
    return np.mean(np.arange(1, v + 1))

vave = np.vectorize(ave)
s = vave(p)

answer = np.sum(s[:K])
current = answer
for i in range(1, N - K + 1):
    current = current - s[i - 1] + s[i + K - 1]
    answer = max(answer, current)

print(answer)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))
s = [0] * N

for i in range(N):
    s[i] = (1 + p[i]) / 2

answer = sum(s[:K])
current = answer
for i in range(1, N - K + 1):
    current = current - s[i - 1] + s[i + K - 1]
    answer = max(answer, current)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

def ave(v):
    return np.mean(np.arange(1, v + 1))

vave = np.vectorize(ave)
s = vave(p)

answer = np.sum(s[:K])
current = answer
for i in range(1, N - K + 1):
    current = current - s[i - 1] + s[i + K - 1]
    answer = max(answer, current)

print(answer)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))
s = [0] * N

for i in range(N):
    s[i] = (1 + p[i]) / 2

answer = sum(s[:K])
current = answer
for i in range(1, N - K + 1):
    current = current - s[i - 1] + s[i + K - 1]
    answer = max(answer, current)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

def ave(v):
    return np.mean(np.arange(1, v + 1))

vave = np.vectorize(ave)
s = vave(p)

ans = 0
for i in range(N - K + 1):
    ans = max(ans, np.sum(s[i:i+K]))

print(ans)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))
s = [0] * N

for i in range(N):
    s[i] = (1 + p[i]) / 2

answer = sum(s[:K])
current = answer
for i in range(1, N - K + 1):
    current = current - s[i - 1] + s[i + K - 1]
    answer = max(answer, current)

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())

dp = [[0] + [1e20] * (H) for _ in range(N)]

for i in range(N):
    A, B = map(int, (input().split()))
    for j in range(1, H + 1):
        dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)

print(dp[-1][-1])

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

dp = [[0] + [1e20] * (H) for _ in range(N)]

for i in range(N):
    A, B = map(int, (input().split()))
    for j in range(1, H + 1):
        dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)

print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
A, B = [0] * N, [0] * N
for i in range(N):
    A[i], B[i] = map(int, (input().split()))

dp = [0] * (H + 1)
for i in range(1, H + 1):
    dp[i] = min([dp[i - A[n]] + B[n] if i >= A[n] else B[n] for n in range(N)])

print(dp[-1])

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

dp = [[0] + [1e20] * (H) for _ in range(N)]

for i in range(N):
    A, B = map(int, (input().split()))
    for j in range(1, H + 1):
        dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)

print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
TD = []
for _ in range(N):
    t, d = map(int, input().split())
    TD.append((t-1, d))

TD.sort(key=lambda x:-x[1])

import heapq

Tcount = [0]*N
chosen = []
heapq.heapify(chosen)

tot = 0
num_kinds = 0
ans = [0]*(N+1)

for i in range(K):
    t, d = TD[i]
    tot += d
    Tcount[t] += 1
    if Tcount[t] == 1: 
        num_kinds += 1
    if Tcount[t] > 1:
        heapq.heappush(chosen, d)

ans[num_kinds] = tot + num_kinds**2

for i in range(K, N):
    t, d = TD[i]
    if Tcount[t] > 0: continue
    Tcount[t] += 1
    num_kinds += 1
    tot = tot - heapq.heappop(chosen) + d
    ans[num_kinds] = tot + num_kinds**2
    if len(chosen) == 0:
        break

print(max(ans))

Fixed submission:
N, K = map(int, input().split())
TD = []
for _ in range(N):
    t, d = map(int, input().split())
    TD.append((t-1, d))

TD.sort(key=lambda x:-x[1])

import heapq

Tcount = [0]*N
chosen = []
heapq.heapify(chosen)

tot = 0
num_kinds = 0
ans = [0]*(N+1)

for i in range(K):
    t, d = TD[i]
    tot += d
    Tcount[t] += 1
    if Tcount[t] == 1: 
        num_kinds += 1
    if Tcount[t] > 1:
        heapq.heappush(chosen, d)

ans[num_kinds] = tot + num_kinds**2

for i in range(K, N):
    if len(chosen) == 0: break
    t, d = TD[i]
    if Tcount[t] > 0: continue
    Tcount[t] += 1
    num_kinds += 1
    tot = tot - heapq.heappop(chosen) + d
    ans[num_kinds] = tot + num_kinds**2
    
print(max(ans))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
TD = []
for _ in range(N):
    t, d = map(int, input().split())
    TD.append((t-1, d))

TD.sort(key=lambda x:-x[1])

import heapq

Tcount = [0]*N
chosen = []
heapq.heapify(chosen)

tot = 0
num_kinds = 0
ans = [0]*N

for i in range(K):
    t, d = TD[i]
    tot += d
    Tcount[t] += 1
    if Tcount[t] == 1: 
        num_kinds += 1
    if Tcount[t] > 1:
        heapq.heappush(chosen, d)

ans[num_kinds] = tot + num_kinds**2

for i in range(K, N):
    t, d = TD[i]
    if Tcount[t] > 0: continue
    Tcount[t] += 1
    num_kinds += 1
    tot = tot - heapq.heappop(chosen) + d
    ans[num_kinds] = tot + num_kinds**2
    if len(chosen) == 0:
        break

print(max(ans))

Fixed submission:
N, K = map(int, input().split())
TD = []
for _ in range(N):
    t, d = map(int, input().split())
    TD.append((t-1, d))

TD.sort(key=lambda x:-x[1])

import heapq

Tcount = [0]*N
chosen = []
heapq.heapify(chosen)

tot = 0
num_kinds = 0
ans = [0]*(N+1)

for i in range(K):
    t, d = TD[i]
    tot += d
    Tcount[t] += 1
    if Tcount[t] == 1: 
        num_kinds += 1
    if Tcount[t] > 1:
        heapq.heappush(chosen, d)

ans[num_kinds] = tot + num_kinds**2

for i in range(K, N):
    if len(chosen) == 0: break
    t, d = TD[i]
    if Tcount[t] > 0: continue
    Tcount[t] += 1
    num_kinds += 1
    tot = tot - heapq.heappop(chosen) + d
    ans[num_kinds] = tot + num_kinds**2
    
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

one, two, three = 0, 0, 0
for ai in a:
    if ai == 1: one += 1
    if ai == 2: two += 1
    if ai == 3: three += 1

u = N + 10
dp = [[[-1]* u for _ in range(u)] for _ in range(u)]

def rec(i, j, k):
    if dp[i][j][k] >= 0:
        return dp[i][j][k]
    if i == 0 and j == 0 and k == 0:
        return 0
    res = 0
    if i > 0: res += rec(i-1, j, k) * i
    if j > 0: res += rec(i+1, j-1, k) * j
    if k > 0: res += rec(i, j+1, k-1) * k
    res += N
    res /= (i + j + k)
    dp[i][j][k] = res

    return res

rec(one, two, three)
print(dp[one][two][three])

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

one, two, three = 0, 0, 0
for ai in a:
    if ai == 1: one += 1
    if ai == 2: two += 1
    if ai == 3: three += 1

u = N + 1
dp = [[[-1]* u for _ in range(u)] for _ in range(u)]
dp[0][0][0] = 0

def rec(i, j, k):
    if dp[i][j][k] >= 0:
        return dp[i][j][k]
    res = N
    if i > 0: res += rec(i-1, j, k) * i
    if j > 0: res += rec(i+1, j-1, k) * j
    if k > 0: res += rec(i, j+1, k-1) * k
    res /= (i + j + k)
    dp[i][j][k] = res
    return res

print(rec(one, two, three))
Buggy python submission (verdict: Time Limit Exceeded):
import sys 
sys.setrecursionlimit(100000) 

N = int(input())
*a, = map(int, input().split())

dp = [[-1] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

def rec(i, j):
    if dp[i][j] != -1:
        return dp[i][j]
    ans = max(a[i] - rec(i+1, j), a[j] - rec(i, j-1))
    dp[i][j] = ans
    return ans

print(rec(0, N-1))

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

dp = [[None] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

for j in range(1, N):
    for i in range(j-1, -1, -1):
        dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1])

print(dp[0][N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys 
sys.setrecursionlimit(100000) 

N = int(input())
*a, = map(int, input().split())

dp = [[-1] *  N for _ in range(N)]

def rec(i, j):
    if dp[i][j] != -1:
        return dp[i][j]
    if i == j: 
        dp[i][j] = a[i]
        return a[i]
    ans = max(a[i] - rec(i+1, j), a[j] - rec(i, j-1))
    dp[i][j] = ans
    return ans

print(rec(0, N-1))

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

dp = [[None] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

for j in range(1, N):
    for i in range(j-1, -1, -1):
        dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1])

print(dp[0][N-1])

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

dp = [[-1] *  N for _ in range(N)]

def rec(i, j):
    if dp[i][j] != -1:
        return dp[i][j]
    if i == j: 
        dp[i][j] = a[i]
        return a[i]
    ans = max(a[i] - rec(i+1, j), a[j] - rec(i, j-1))
    dp[i][j] = ans
    return ans

print(rec(0, N-1))

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

dp = [[None] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

for j in range(1, N):
    for i in range(j-1, -1, -1):
        dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1])

print(dp[0][N-1])

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

dp = [[''] *  N for _ in range(N)]

def rec(i, j):
    if dp[i][j] != '':
        return dp[i][j]
    if i == j: 
        dp[i][j] = a[i]
        return a[i]
    ans = max(a[i] - rec(i+1, j), a[j] - rec(i, j-1))
    dp[i][j] = ans
    return ans

print(rec(0, N-1))

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

dp = [[None] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

for j in range(1, N):
    for i in range(j-1, -1, -1):
        dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1])

print(dp[0][N-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = range(N)
for i in range(N):
  A[i] = int(input())
  

A2nums = [0] * N
for i in range(N):
  while True:
    A[i] /= 2
    if A[i] % 2 == 0:
      A2num[i] += 1
    else: 
      break    

print(min(A2num))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
  
 
A2nums = [0] * N
for i in range(N):
  while True:
    if A[i] % 2 == 0:
      A2nums[i] += 1
      A[i] /= 2
    else: 
      break    
 
print(min(A2nums))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

l = sorted(a[:N])
r = sorted(a[N:])

lsum = sum(l)
rsum = sum(r[:N])

import bisect

ans = lsum - rsum
for i in range(N):
    c = a[N+i]
    li = bisect.bisect_left(l, c)
    ri = bisect.bisect_left(r, c)
    if li > 0: 
        lsum = lsum + c - l[0]
        l.insert(li, c)
        del l[0]
    if ri < N:
        rsum = rsum - c + r[N]
    del r[ri]
    ans = max(ans, lsum - rsum)

print(ans)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
 
import heapq

left = [0]*(N+1)
l = a[:N]
left[0] = sum(l)

heapq.heapify(l)
for i in range(1, N+1):
    c = a[N+i-1]    
    lmin = heapq.heappop(l)
    if lmin < c:
        left[i] = left[i-1] + c - lmin
        heapq.heappush(l, c)
    else:
        left[i] = left[i-1]
        heapq.heappush(l, lmin)

a = [-x for x in a[::-1]]
right = [0]*(N+1)
r = a[:N]
right[0] = sum(r)

heapq.heapify(r)
for i in range(1, N+1):
    c = -a[N+i-1]    
    rmax = -heapq.heappop(r)
    if rmax > c:
        right[i] = right[i-1] - c + rmax
        heapq.heappush(r, -c)
    else:
        right[i] = right[i-1]
        heapq.heappush(r, -rmax)

ans = -10**20
for i in range(N+1):
    ans = max(ans, left[i] + right[N-i])

print(ans)

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

l = sorted(a[:N])
r = sorted(a[N:])

lsum = sum(l)
rsum = sum(r[:N])

import bisect

ans = lsum - rsum
for i in range(N):
    c = a[N+i]
    li = bisect.bisect_left(l, c)
    ri = bisect.bisect_left(r, c)
    if li > 0: 
        lsum = lsum + c - l[0]
        l.insert(li, c)
        del l[0]
    if ri < N:
        rsum = rsum - c + r[N]
    del r[ri]
    ans = max(ans, lsum - rsum)

print(ans)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
 
import heapq

left = [0]*(N+1)
l = a[:N]
left[0] = sum(l)

heapq.heapify(l)
for i in range(1, N+1):
    c = a[N+i-1]    
    lmin = heapq.heappop(l)
    if lmin < c:
        left[i] = left[i-1] + c - lmin
        heapq.heappush(l, c)
    else:
        left[i] = left[i-1]
        heapq.heappush(l, lmin)

a = [-x for x in a[::-1]]
right = [0]*(N+1)
r = a[:N]
right[0] = sum(r)

heapq.heapify(r)
for i in range(1, N+1):
    c = -a[N+i-1]    
    rmax = -heapq.heappop(r)
    if rmax > c:
        right[i] = right[i-1] - c + rmax
        heapq.heappush(r, -c)
    else:
        right[i] = right[i-1]
        heapq.heappush(r, -rmax)

ans = -10**20
for i in range(N+1):
    ans = max(ans, left[i] + right[N-i])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = [int(x) for x in input().split()]

dic = {}
for i in range(K + 1):
    for j in range (K + 1):
        r = S - i - j
        if r in dic.keys():
            dic[r].append((i, j))
        else:
            dic[r] = [(i, j)]

ans = 0
for k in range(K + 1):
    if k in dic.keys():
        ans += len(dic[k]) 

print(ans)

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

ans = 0
for i in range(K + 1):
    for j in range (K + 1):
        r = S - i - j
        if r <= K and r >= 0:
            ans += 1
        
print(ans)
Buggy python submission (verdict: Runtime Error):
N, A = map(int, input().split())
*X, = map(lambda x:int(x)-A, input().split())

M = 2500
dp = [[0]*(2*M+1) for _ in range(N)]
dp[0][M] += 1
dp[0][X[0]+M] += 1

for i in range(1,N):
    for v in range(-M, M+1):
        dp[i][v+M] += dp[i-1][v+M]
        if -M<=v-X[i]<=M:
            dp[i][v+M] += dp[i-1][v-X[i]+M]

print(dp[-1][M]-1)N, A = map(int, input().split())
*X, = map(lambda x:int(x)-A, input().split())

M = 2500
dp = [[0]*(2*M+1) for _ in range(N)]
dp[0][M] += 1
dp[0][X[0]+M] += 1

for i in range(1,N):
    for v in range(-M, M+1):
        dp[i][v+M] += dp[i-1][v+M]
        if -M<=v-X[i]<=M:
            dp[i][v+M] += dp[i-1][v-X[i]+M]

print(dp[-1][M]-1)

Fixed submission:
N, A = map(int, input().split())
*X, = map(lambda x:int(x)-A, input().split())

M = 2500
dp = [[0]*(2*M+1) for _ in range(N)]
dp[0][M] += 1
dp[0][X[0]+M] += 1

for i in range(1,N):
    for v in range(-M, M+1):
        dp[i][v+M] += dp[i-1][v+M]
        if -M<=v-X[i]<=M:
            dp[i][v+M] += dp[i-1][v-X[i]+M]

print(dp[-1][M]-1)
Buggy python submission (verdict: Runtime Error):
import string

n = int(input())
alphabets = string.ascii_lowercase
answer = []
while n >= 1:
	n -= 1
    answer.append(alphabets[n % 26])
    n = n//26
ans = ''.join(list(reversed(answer)))
print(ans)


Fixed submission:
import string

n = int(input())
alphabets = string.ascii_lowercase
answer = []
while n >= 1:
    n -= 1
    answer.append(alphabets[n % 26])
    n = n//26
ans = ''.join(list(reversed(answer)))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

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

s = 0
for i in range(1, K + 1):
  for j in range(1, K + 1):
    for k in range(1, K + 1):
      s += gcd(i, gcd(j, k))

print(s)


Fixed submission:
K = int(input())

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


gcds = [[0 for _ in range(K + 1)] for _ in range(K + 1)]

for i in range(1, K + 1):
  for j in range(1, K + 1):
    gcds[i][j] = gcd(i, j)

s = 0
for i in range(1, K + 1):
  for j in range(1, K + 1):
    for k in range(1, K + 1):
      s += gcds[gcds[i][j]][k]

print(s)

Buggy python submission (verdict: Runtime Error):
K = int(input())

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

s = 0
for i in range(1, K + 1):
	for j in range(1, K + 1):
      for k in range(1, K + 1):
        s += gcd(i, gcd(j, k))

print(s)

Fixed submission:
K = int(input())

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


gcds = [[0 for _ in range(K + 1)] for _ in range(K + 1)]

for i in range(1, K + 1):
  for j in range(1, K + 1):
    gcds[i][j] = gcd(i, j)

s = 0
for i in range(1, K + 1):
  for j in range(1, K + 1):
    for k in range(1, K + 1):
      s += gcds[gcds[i][j]][k]

print(s)