Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
button=[]

for i in range(N):
  button.append(int(input()))

num=1
cnt=0
i=0

while True:
  num=button[num-1]
  cnt+=1
  if num==2:
    print(cnt)
    break
  if cnt>N:
    print(-1)

Fixed submission:
N=int(input())
a=[int(input()) for _ in range(N)]

btn=1
cnt=0

while True:
  btn=a[btn-1]
  cnt+=1
  if btn==2:
    print(cnt)
    break
  if cnt>N:
    print(-1)
    break

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
button=[]

for i in range(N):
  button.append(int(input()))

cnt=0
i=0

while True:
  i=button[i]-1 #←ここが理解できない。。。
  cnt+=1
  if i==1:
    print(cnt)
    break
  if cnt>N:
    print(-1)

Fixed submission:
N=int(input())
a=[int(input()) for _ in range(N)]

btn=1
cnt=0

while True:
  btn=a[btn-1]
  cnt+=1
  if btn==2:
    print(cnt)
    break
  if cnt>N:
    print(-1)
    break

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
button=[]

for i in range(N):
  button.append(int(input()))

cnt=0
i=0

while True:
  i=button[i]-1 #←ここが理解できない。。。
  cnt+=1
  if i==1:
    print(cnt)
    break
  if cnt>N:
    print(-1)

Fixed submission:
N=int(input())
a=[int(input()) for _ in range(N)]

btn=1
cnt=0

while True:
  btn=a[btn-1]
  cnt+=1
  if btn==2:
    print(cnt)
    break
  if cnt>N:
    print(-1)
    break
Buggy python submission (verdict: Runtime Error):
H,W=int(input().split())
a=[]
a.append('#'*(W+2))
for i in range(1,H+1):
  a.append('#'+input()+'#')
a.append('#'*(W+2))
for i in range(H+2):
  print(a[i])

Fixed submission:
H,W=map(int,input().split())
a=[]
a.append('#'*(W+2))
for i in range(1,H+1):
  a.append('#'+input()+'#')
a.append('#'*(W+2))
for i in range(H+2):
  print(a[i])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(len(A)):
    for j in range(i + 1, len(A)):
        ans = (ans + (A[i] * A[j]) % 1000000007) % 1000000007
print(ans)

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

sum_a  = sum(A)
ans = 0
for i in range(len(A)):
    sum_a -= A[i]
    ans = (ans + (A[i] * sum_a) % 1000000007) % 1000000007
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
sy, sx = map(lambda x: int(x) - 1, input().split())
gy, gx = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]
seen = [[-1] * W for _ in range(H)] 
from collections import deque

def bfs(maze, seen, sy, sx, gy, gx):
    queue = deque()
    queue.append([sy, sx, 0])
    while queue:
        y, x, c = queue.popleft()
        if seen[y][x] > -1:
            continue
        seen[y][x] = c
        if seen[gy][gx] > -1:
            return c
        for i in range(-2, 3):
            for j in range(-2, 3):
                if (i == -1 and j == 0) or (i == 1 and j == 0) or (i == 0 and j == -1) or (i == 0 and j == 1):   
                    dy = y + i
                    dx = x + j
                    if dy < 0 or H <= dy or dx < 0 or W <= dx or seen[dy][dx] > -1:
                        continue
                    if maze[dy][dx] == '#':
                        continue
                    queue.appendleft([dy, dx, c])
                dy = y + i
                dx = x + j
                if dy < 0 or H <= dy or dx < 0 or W <= dx or seen[dy][dx] > -1:
                    continue
                if maze[dy][dx] == '#':
                    continue
                queue.append([dy, dx, seen[y][x] + 1])
    return -1

print(bfs(maze, seen, sy, sx, gy, gx))


Fixed submission:
H, W = map(int, input().split())
sy, sx = map(lambda x: int(x) - 1, input().split())
gy, gx = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]
seen = [[-1] * W for _ in range(H)] 
from collections import deque

def bfs(maze, seen, sy, sx, gy, gx):
    queue = deque()
    queue.append([sy, sx, 0])
    while queue:
        y, x, c = queue.popleft()
        if seen[y][x] > -1:
            continue
        seen[y][x] = c
        if seen[gy][gx] > -1:
            return c
        for i in range(-2, 3):
            for j in range(-2, 3):
                if (i == -1 and j == 0) or (i == 1 and j == 0) or (i == 0 and j == -1) or (i == 0 and j == 1):   
                    dy = y + i
                    dx = x + j
                    if dy < 0 or H <= dy or dx < 0 or W <= dx or seen[dy][dx] > -1:
                        continue
                    if maze[dy][dx] == '#':
                        continue
                    queue.appendleft([dy, dx, c])
                dy = y + i
                dx = x + j
                if dy < 0 or H <= dy or dx < 0 or W <= dx or seen[dy][dx] > -1:
                    continue
                if maze[dy][dx] == '#':
                    continue
                queue.append([dy, dx, seen[y][x] + 1])
    return -1

print(bfs(maze, seen, sy, sx, gy, gx))
Buggy python submission (verdict: Runtime Error):
a = input()

print(a+ a*a + a*a*a)

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

if s.isuppper():
    print("A")
elif s.islower():
    print("a")

Fixed submission:
s = input()

if s.isupper():
        print("A")
elif s.islower():
        print("a")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 1
for i in A:
        ans = ans * i

if ans > 1000000000000000000:
        print(-1)
else:
        print(ans)

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

if A[0] == 0:
        print(0)
        exit()

ans = 1
for i in A:
        ans = ans * i
        if ans > 1000000000000000000:
                print(-1)
                exit()

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
 
ans = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        if S[i] == S[j]:
            continue
        for k in range(j + 1, N):
            if j - i == k - j:
                continue
            if S[i] != S[k] and S[j] != S[k]:
                ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')
all = r * g * b

sub = 0
for i in range(N-1):
    for j in range(i, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            sub += 1
print(all - sub)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
 
ans = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        if S[i] == S[j]:
            continue
        for k in range(j + 1, N):
            if S[i] != S[k] and S[j] != S[k]:
                if j - i != k - j:
                    ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')
all = r * g * b

sub = 0
for i in range(N-1):
    for j in range(i, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            sub += 1
print(all - sub)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                if j - i != k - j:
                    ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')
all = r * g * b

sub = 0
for i in range(N-1):
    for j in range(i, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            sub += 1
print(all - sub)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

a = abs(N - K)
ans1 = N % a
b = abs((N % a) - a)
ans2 = N % b

print(min(ans1, ans2))



Fixed submission:
N, K = map(int, input().split())
tmp = N % K
print(min(tmp, abs(tmp - K)))

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


if K > N:
    print(N)
    exit()

a = abs(N - K)
ans1 = N % a
ans2 = abs((N % a) - a)
if K == 1:
    print(0)
else:
    print(min(ans1, ans2))



Fixed submission:
N, K = map(int, input().split())
tmp = N % K
print(min(tmp, abs(tmp - K)))

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


if K > N:
    print(N)
    exit()

a = abs(N - K)
ans = N % a

if ans == 1:
    print(0)
else:
    print(ans)

Fixed submission:
N, K = map(int, input().split())
tmp = N % K
print(min(tmp, abs(tmp - K)))

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

a = abs(N - K)
ans = N % a

if ans == 1:
    print(0)
else:
    print(ans)

Fixed submission:
N, K = map(int, input().split())
tmp = N % K
print(min(tmp, abs(tmp - K)))
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int ,input().split())

def inv(k):
    return pow(k, mod - 2, mod)

def comb(n, k):
    bunshi = 1
    bunbo = 1
    for i in range(k):
        bunshi *= (n - i) % mod
        bunbo *= (i + 1) % mod
    return bunshi * inv(bunbo) % mod

mod = 1000000007
all_num = pow(2, n, mod)

ans = all_num - 1 - comb(n, a) - comb(n, b)
print(ans)

Fixed submission:
n, a, b = map(int, input().split())
mod = 1000000007
def inv(y, mod):
    return pow(y, mod - 2, mod)

def comb(n, a, mod):
    x = 1
    y = 1
    for i in range(a):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    return (x * inv(y, mod)) % mod
    
print((pow(2, n, mod) - 1 - comb(n, a, mod) - comb(n, b, mod)) % mod)

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

def inv(k):
    return pow(k, mod - 2, mod)

def comb(n, k):
    bunshi = 1
    bunbo = 1
    for i in range(k):
        bunshi *= (n - i)
        bunbo *= (i + 1)
    return bunshi * inv(bunbo) % mod

mod = 1000000007
all_num = pow(2, n, mod)

ans = all_num - 1 - comb(n, a) - comb(n, b)
print(ans)

Fixed submission:
n, a, b = map(int, input().split())
mod = 1000000007
def inv(y, mod):
    return pow(y, mod - 2, mod)

def comb(n, a, mod):
    x = 1
    y = 1
    for i in range(a):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    return (x * inv(y, mod)) % mod
    
print((pow(2, n, mod) - 1 - comb(n, a, mod) - comb(n, b, mod)) % mod)
Buggy python submission (verdict: Runtime Error):
N = int(input())

if N % 2 == 1:
  print(0)
else:
  tmp = 2
  ans = 0
  while 5 * tmp <= N:
    tmp *= 5
    ans = ans + N // tmp
print(ans)

Fixed submission:
N = int(input())

if N % 2 == 1:
  print(0)
  exit()
else:
  tmp = 2
  ans = 0
  while 5 * tmp <= N:
    tmp *= 5
    ans = ans + N // tmp
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))

count = 0
for i in range(N - 2):
        for j in range(i + 1, N - 1):
                for k in range(j + 1, N):
                        if L[i] < L[j] + L[k] and L[j] < L[i] + L[k] and L[k] < L[i] + L[j]:
                                count += 1

print(count)

Fixed submission:
import bisect

N = int(input())
L = list(map(int, input().split()))

L.sort()

count = 0
for i in range(N - 2):
        for j in range(i + 1, N - 1):
                max_c = L[i] + L[j]
                count += bisect.bisect_left(L[j+1:], max_c)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

for i in range(M):
        tmp = A.pop(-1) // 2
        index = bisect.bisect_left(A, tmp)
        A.insert(index, tmp)


print(sum(A))

Fixed submission:

import heapq
N, M = map(int, input().split())
A = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(A)

for i in range(M):
        tmp = int(heapq.heappop(A) / 2)
        heapq.heappush(A, tmp)

print(sum(A) * -1)

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

A.sort()

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

print(sum(A))

Fixed submission:

import heapq
N, M = map(int, input().split())
A = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(A)

for i in range(M):
        tmp = int(heapq.heappop(A) / 2)
        heapq.heappush(A, tmp)

print(sum(A) * -1)
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

tmp = R - L + 1
if tmp >= 2019:
    print(0)
    exit()
else:
    start = L % 2019
    end = R % 2019
    candidate = []
    for i in range(start, end + 1):
        candidate.append(i % 2019)
    candidate.sort()
    ans = []
    for i in range(len(candidate)):
        for j in range(len(candidate)):
            if i == j:
                continue
            else:
                ans.append((candidate[i] * candidate[j]) % 2019)
    ans.sort()
    print(ans[0])


Fixed submission:
L, R = map(int, input().split())

tmp = R - L + 1
if tmp >= 2019:
    print(0)
    exit()
else:
    start = L % 2019
    end = R % 2019
    candidate = []
    for i in range(start, end + 1):
        candidate.append(i % 2019)
    candidate.sort()
    ans = []
    for i in range(len(candidate)):
        if i == (len(candidate) - 1):
            continue
        for j in range(i + 1, len(candidate)):
            if i == j:
                continue
            else:
                ans.append((candidate[i] * candidate[j]) % 2019)
    ans.sort()
    print(ans[0])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

sche = [[0,0] for i in range(N)]

for i in range(N):
    tmp_a, tmp_b = map(int, input().split())
    sche[i][0] = tmp_a
    sche[i][1] = tmp_b



def search_lms(N, sche, now):
    sub_time = 10000000000
    num = 0
    for i in range(len(sche)):
        if sub_time > sche[i][1]:
            sub_time = sche[i][1]
            num = i
    return num
        #差の最小値を見つける

now = 0
tmp = 0
for i in range(N):
    tmp = search_lms(N, sche, now)
    if now + sche[tmp][0] > sche[tmp][1]:
        print("No")
        exit()
    now += sche[tmp][0]
    sche.pop(tmp)

print("Yes")

Fixed submission:
N = int(input())
work = [list(map(int, input().split())) for i in range(N)]

work = sorted(work, key = lambda x: x[1])

time = 0
for i in range(N):
    time += work[i][0]
    if time > work[i][1]:
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
maze = [input() for i in range(H)]
dp_holi = [[0] * W for i in range(H)]
dp_ver = [[0] * W for i in range(H)]


#まずは水平方向について数える
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            if j - 1 < 0 or maze[i][j -1] == "#":
                tmp = 0
                flag = False
                for k in maze[i][j:]:
                    if k == ".":
                        tmp += 1
                        flag = True
                    else:
                        dp_holi[i][j] = tmp
                        break
                if flag:
                    dp_holi[i][j] = tmp
            elif maze[i][j - 1] == ".":
                dp_holi[i][j] += dp_holi[i][j - 1]

#垂直方向にも同じことをする
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            if i - 1 < 0 or maze[i -1][j] == "#":
                tmp = 0
                flag = False
                for k in range(i, H):
                    if maze[k][j] == ".":
                        tmp += 1
                        flag = True
                    else:
                        dp_ver[i][j] += tmp
                        flag = False
                        break
                if flag:
                    dp_ver[i][j] += tmp
            elif i - 1 < 0:
                continue
            elif maze[i - 1][j] == ".":
                dp_ver[i][j] += dp_ver[i - 1][j]

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, dp_holi[i][j] + dp_ver[i][j] - 1)
print(ans)

Fixed submission:
H, W = map(int, input().split())
maze = [input() for i in range(H)]
dp_holi = [[0] * W for i in range(H)]
dp_ver = [[0] * W for i in range(H)]


#まずは水平方向について数える
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            if j - 1 < 0 or maze[i][j -1] == "#":
                tmp = 0
                flag = False
                for k in maze[i][j:]:
                    if k == ".":
                        tmp += 1
                        flag = True
                    else:
                        dp_holi[i][j] = tmp
                        break
                if flag:
                    dp_holi[i][j] = tmp
            elif maze[i][j - 1] == ".":
                dp_holi[i][j] += dp_holi[i][j - 1]

#垂直方向にも同じことをする
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            if i - 1 < 0 or maze[i -1][j] == "#":
                tmp = 0
                flag = False
                for k in range(i, H):
                    if maze[k][j] == ".":
                        tmp += 1
                        flag = True
                    else:
                        dp_ver[i][j] += tmp
                        flag = False
                        break
                if flag:
                    dp_ver[i][j] += tmp
            elif i - 1 < 0:
                continue
            elif maze[i - 1][j] == ".":
                dp_ver[i][j] += dp_ver[i - 1][j]

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, dp_holi[i][j] + dp_ver[i][j] - 1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

gate = []

for i in range(M):
    l, r = map(int, input().split())
    tmp = []
    for j in range(l, r + 1):
        tmp.append(j)
    gate.append(tmp)

gate_sum = set(gate[0])

for i in gate:
    gate_sum = gate_sum & set(i)

print(len(gate_sum))

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

gate = []

l, r = map(int, input().split())


for i in range(M-1):
    tmpl, tmpr = map(int, input().split())
    if l < tmpl:
        l = tmpl
    if tmpr < r:
        r = tmpr


if r - l < 0:
    print(0)
else:
    print(r - l + 1)

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

gate = []

for i in range(M):
    l, r = map(int, input().split())
    tmp = []
    for j in range(l, r + 1):
        tmp.append(j)
    gate.append(tmp)

gate_sum = set(gate[0])

for i in gate:
    gate_sum = gate_sum & set(i)

print(len(gate_sum))

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

gate = []

l, r = map(int, input().split())


for i in range(M-1):
    tmpl, tmpr = map(int, input().split())
    if l < tmpl:
        l = tmpl
    if tmpr < r:
        r = tmpr


if r - l < 0:
    print(0)
else:
    print(r - l + 1)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

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

A_dict = {}

#Aをhash
for i in A:
    if i in A_dict:
        A_dict[i] += 1
    else:
        A_dict[i] = 1


for i in range(M):
    b, c = map(int, input().split())
    for j in range(b):
        #最小値がc以上なら何もしない
        if min(A_dict.keys()) >= c:
            break
        else:
            if A_dict[min(A_dict.keys())] == 1:
                del A_dict[min(A_dict.keys())]
                if c in A_dict:
                    A_dict[c] += 1
                else:
                    A_dict[c] = 1
            else:
                A_dict[min(A_dict.keys())] -= 1
                if c in A_dict:
                    A_dict[c] += 1
                else:
                    A_dict[c] = 1

ans = 0
for k, v in A_dict.items():
    ans += k * v
print(ans)

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

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

A_dict = {}

#Aをhash
for i in A:
    if i in A_dict:
        A_dict[i] += 1
    else:
        A_dict[i] = 1


for i in range(M):
    b, c = map(int, input().split())
    if c in A_dict:
        A_dict[c] += b
    else:
        A_dict[c] = b

A_dict = sorted(A_dict.items(), key=lambda x: -x[0])


card = 0
ans = 0
for i in A_dict:
    if card == N:
        break
    elif card + i[1] > N:
        ans += (N - card) * i[0]
        break
    else:
        ans += i[0] * i[1]
        card += i[1]
print(ans)

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

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

#Aをソート
A.sort()

for i in range(M):
    b, c = map(int, input().split())
    for j in range(b):
        if min(A) < c:
            A[0] = c
            A.sort()

print(sum(A))

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

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

A_dict = {}

#Aをhash
for i in A:
    if i in A_dict:
        A_dict[i] += 1
    else:
        A_dict[i] = 1


for i in range(M):
    b, c = map(int, input().split())
    if c in A_dict:
        A_dict[c] += b
    else:
        A_dict[c] = b

A_dict = sorted(A_dict.items(), key=lambda x: -x[0])


card = 0
ans = 0
for i in A_dict:
    if card == N:
        break
    elif card + i[1] > N:
        ans += (N - card) * i[0]
        break
    else:
        ans += i[0] * i[1]
        card += i[1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int,input().split())

ans = 0
for i in range(N+1):
    for j in range(N+1):
        if (R * i + G * j) > N:
            break
        if (N - R * i - G * j) % B == 0:
            ans += 1
print(ans)

Fixed submission:
R, G, B, N = map(int,input().split())

ans = 0
for i in range(N+1):
    for j in range(N+1):
        if (R * i + G * j) > N:
            break
        if (N - R * i - G * j) % B == 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):

test = {}

V = list(map(int,input().split()))
C = list(map(int,input().split()))

new_n = 0
for i in range(N):
    if V[i] <=  C[i]:
        continue
    else:
        test[i] = [V[i],C[i]]
        new_n += 1

N = new_n

def calc_cost(com,test,i):
    x = 0
    y = 0
    for j in com:
        x += test[j][0]
        y += test[j][1]
    return x - y

ans = 0




for i in range(N):
    c = itertools.combinations(test.keys(), i+1)
    for j in c:
        ans = max(ans,calc_cost(j,test,i))


print(ans)
        
    

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

test = {}

V = list(map(int,input().split()))
C = list(map(int,input().split()))
new_n = 0
for i in range(N):
    if V[i] <=  C[i]:
        continue
    else:
        test[i] = [V[i],C[i]]
        new_n += 1

N = new_n

def calc_cost(com,test,i):
    x = 0
    y = 0
    for j in com:
        x += test[j][0]
        y += test[j][1]
    return x - y

ans = 0

for i in range(N):
    c = itertools.combinations(test.keys(), i+1)
    for j in c:
        ans = max(ans,calc_cost(j,test,i))


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())

test = {}

V = list(map(int,input().split()))
C = list(map(int,input().split()))

for i in range(N):
    test[i] = [V[i],C[i]]


def calc_cost(com,test,i):
    x = 0
    y = 0
    for j in com:
        x += test[j][0]
        y += test[j][1]
    return x - y

ans = 0
for i in range(N):
    c = itertools.combinations(list(range(N)), i+1)
    for j in c:
        ans = max(ans,calc_cost(j,test,i))


print(ans)
        
    

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

test = {}

V = list(map(int,input().split()))
C = list(map(int,input().split()))
new_n = 0
for i in range(N):
    if V[i] <=  C[i]:
        continue
    else:
        test[i] = [V[i],C[i]]
        new_n += 1

N = new_n

def calc_cost(com,test,i):
    x = 0
    y = 0
    for j in com:
        x += test[j][0]
        y += test[j][1]
    return x - y

ans = 0

for i in range(N):
    c = itertools.combinations(test.keys(), i+1)
    for j in c:
        ans = max(ans,calc_cost(j,test,i))


print(ans)