Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)
N, K = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
MOD = 10 ** 9 + 7

def dfs(u, par):
    color_num = K - 1 if par == -1 else K - 2

    if len(graph[u]) > K:
        return 0
    
    cnt = 1
    for v in graph[u]:
        if v == par:
            continue

        cnt *= color_num
        cnt %= MOD
        color_num -= 1

    for v in graph[u]:
        if v == par:
            continue

        cnt *= dfs(v, u)
        cnt %= MOD
        
    return cnt

graph = [[] for _ in range(N)]
for u, v in edges:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

print(dfs(0, -1) * K % MOD)



Fixed submission:
from collections import deque
N, K = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
MOD = 10 ** 9 + 7

def dfs(u, par):
    q = deque()
    q.append((u, par))
    ret = 1

    while q:
        u, par = q.pop()
        color_num = K - 1 if par == -1 else K - 2
        
        if len(graph[u]) > K:
            return 0
            
        for v in graph[u]:
            if v == par:
                continue
                
            ret *= color_num
            ret %= MOD
            color_num -= 1
            
            q.append((v, u))

    return ret

graph = [[] for _ in range(N)]
for u, v in edges:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

print(dfs(0, -1) * K % MOD)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
MOD = 10 ** 9 + 7

def dfs(u, par):
    color_num = K - 1 if par == -1 else K - 2

    if len(graph[u]) > K:
        return 0
    
    cnt = 1
    for v in graph[u]:
        if v == par:
            continue

        cnt *= color_num
        cnt %= MOD
        color_num -= 1

    for v in graph[u]:
        if v == par:
            continue

        cnt *= dfs(v, u)
        cnt %= MOD
        
    return cnt

graph = [[] for _ in range(N)]
for u, v in edges:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

print(dfs(0, -1) * K % MOD)



Fixed submission:
from collections import deque
N, K = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
MOD = 10 ** 9 + 7

def dfs(u, par):
    q = deque()
    q.append((u, par))
    ret = 1

    while q:
        u, par = q.pop()
        color_num = K - 1 if par == -1 else K - 2
        
        if len(graph[u]) > K:
            return 0
            
        for v in graph[u]:
            if v == par:
                continue
                
            ret *= color_num
            ret %= MOD
            color_num -= 1
            
            q.append((v, u))

    return ret

graph = [[] for _ in range(N)]
for u, v in edges:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

print(dfs(0, -1) * K % MOD)
Buggy python submission (verdict: Runtime Error):
from math import factorial
MOD = 10 ** 9 + 7

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

def rep_perm(n, k):
    if n == 0:
        return 1
    
    ans = factorial(n + k - 1) % MOD
    ans *= pow(factorial(n - 1), MOD - 2, MOD)
    ans %= MOD
    ans *= pow(factorial(k), MOD - 2, MOD)
    ans %= MOD
    return ans

for i in range(1, K + 1):
    ans = rep_perm(i + 1, N - K - i + 1)
    if i != 1:
        ans *= (K - i + 1)
    print(ans)





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

def comb(n, k):
    ret = 1
    for i in range(1, k + 1):
        ret = ret * (n - i + 1) % MOD        
        ret = ret * pow(i, MOD - 2, MOD) % MOD
    return ret

for i in range(1, K + 1):
    n = i - 1 + 2
    k = N - K - (i - 1)
    if k < 0:
        print(0)
    else:
        ans = comb(n + k - 1, k) * comb(K - 1, i - 1) % MOD
        print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

INF = 10 ** 9 + 7
d = [[INF] * 3 for _ in range(N + 1)]
d[S][0] = 0
for _ in range(M):
    for u, v in X:
        for i in range(3):
            if d[u][i] < INF and d[v][(i + 1) % 3] > d[u][i] + 1:
                d[v][(i + 1) % 3] = d[u][i] + 1

if d[T][2] == INF:
    print(-1)
else:
    print(d[T][2])


Fixed submission:
from collections import deque
N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

graph = [[] for _ in range(N + 1)]
for u, v in edges:
    graph[u].append(v)

INF = 10 ** 9 + 7
dp = [[INF] * (N + 1) for _ in range(3)]
dp[0][S] = 0
q = deque()
q.append((S, 0))

while q:
    v, t = q.popleft()
    u = (t + 1) % 3
    d = dp[t][v]
    if t == 2:
        d += 1
    for w in graph[v]:
        if dp[u][w] != INF:
            continue
        dp[u][w] = d
        q.append((w, u))
        
print(dp[0][T] if dp[0][T] < INF else -1)
Buggy python submission (verdict: Runtime Error):

from collections import defaultdict

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

X.sort()
ctr = defaultdict(int)
for i in range(N - 1):
    for j in range(i + 1, N):
        p = X[i][0] - X[j][0]
        q = X[i][1] - X[j][1]
        ctr[(p, q)] += 1
        ctr[(-p, -q)] += 1

print(N - max(ctr.values()))


Fixed submission:
from itertools import combinations
from collections import Counter

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

if N == 1:
    print(1)
    quit()

X.sort()
diff = []
for i, j in combinations(range(N), 2):
    diff.append((X[i][0] - X[j][0], X[i][1] - X[j][1]))
print(N - Counter(diff).most_common()[0][1])

Buggy python submission (verdict: Runtime Error):
from itertools import combinations
from collections import Counter

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

X.sort()
diff = []
for i, j in combinations(range(N), 2):
    diff.append((X[i][0] - X[j][0], X[i][1] - X[j][1]))
print(N - Counter(diff).most_common()[0][1])




Fixed submission:
from itertools import combinations
from collections import Counter

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

if N == 1:
    print(1)
    quit()

X.sort()
diff = []
for i, j in combinations(range(N), 2):
    diff.append((X[i][0] - X[j][0], X[i][1] - X[j][1]))
print(N - Counter(diff).most_common()[0][1])
Buggy python submission (verdict: Runtime Error):
N, *A = map(int, open(0).read().split())

A_MAX = max(abs(A[0]), abs(A[-1]))
A.remove(A_MAX)
X = sorted(A)
x = X[0]
ans = []
for v in X[1:]:
    ans.append((x, v))
    x -= v

if x <= 0:
    print(A_MAX - x)
    ans.append((A_MAX, x))
else:
    print(x - A_MAX)
    ans.append((x, A_MAX))
for i in range(N - 1):
    print(*ans[i])

Fixed submission:
N, *A = map(int, open(0).read().split())

x = sorted([v for v in A if v >= 0])
y = sorted([v for v in A if v < 0], reverse=True)

ans = []
if len(y) == 0:
    cnt = x[0]
    for v in x[1:-1]:
        ans.append((cnt, v))
        cnt -= v
    ans.append((x[-1], cnt))
    print(x[-1] - cnt)
elif len(x) == 0:
    cnt = y[0]
    for v in y[1:]:
        ans.append((cnt, v))
        cnt -= v
    print(cnt)
else:
    for v in x[:-1]:
        ans.append((y[0], v))
        y[0] -= v
        
    cnt = x[-1]
    for v in y:
        ans.append((cnt, v))
        cnt -= v
    print(cnt)
    
for v in ans:
    print(*v)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
N, *A = map(int, open(0).read().split())

B = A[:]
A_MAX = max(B)
B.remove(A_MAX)

ans = []
while len(B) > 1:
    B.sort()
    x = B.pop()
    y = B.pop()
    if y >= 0:
        idx = bisect(B, x - y)
        B = B[:idx] + [x - y] + B[idx:]
        ans.append([x, y])
    else:
        idx = bisect(B, y - x)
        B = B[:idx] + [y - x] + B[idx:]
        ans.append([y, x])
    
if B[0] <= 0:
    print(A_MAX - B[0])
    ans.append([A_MAX, B[0]])
else:
    print(B[0] - A_MAX)
    ans.append([B[0], A_MAX])
for i in range(N - 1):
    print(*ans[i])

Fixed submission:
N, *A = map(int, open(0).read().split())

x = sorted([v for v in A if v >= 0])
y = sorted([v for v in A if v < 0], reverse=True)

ans = []
if len(y) == 0:
    cnt = x[0]
    for v in x[1:-1]:
        ans.append((cnt, v))
        cnt -= v
    ans.append((x[-1], cnt))
    print(x[-1] - cnt)
elif len(x) == 0:
    cnt = y[0]
    for v in y[1:]:
        ans.append((cnt, v))
        cnt -= v
    print(cnt)
else:
    for v in x[:-1]:
        ans.append((y[0], v))
        y[0] -= v
        
    cnt = x[-1]
    for v in y:
        ans.append((cnt, v))
        cnt -= v
    print(cnt)
    
for v in ans:
    print(*v)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
grid = [input() for _ in range(H)]

graph_1 = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            if j != 0 and grid[i][j - 1] == '.':
                graph_1[i][j] = graph_1[i][j - 1] + 1
            else:
                graph_1[i][j] = 1

for i in range(H):
    for j in reversed(range(W - 1)):
        if grid[i][j + 1] == '.' and grid[i][j] == '.':
            graph_1[i][j] = graph_1[i][j + 1]

graph_2 = [[0] * W for _ in range(H)]
for j in range(W):
    for i in range(H):
        if grid[i][j] == '.':
            if i != 0 and grid[i - 1][j] == '.':
                graph_2[i][j] = graph_2[i - 1][j] + 1
            else:
                graph_2[i][j] = 1

for j in range(W):
    for i in reversed(range(H - 1)):
        if grid[i + 1][j] == '.' and grid[i][j] == '.':
            graph_2[i][j] = graph_2[i + 1][j]

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


Fixed submission:
H, W = map(int, input().split())
grid = [input() for _ in range(H)]

graph_1 = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            if j != 0 and grid[i][j - 1] == '.':
                graph_1[i][j] = graph_1[i][j - 1] + 1
            else:
                graph_1[i][j] = 1

for i in range(H):
    for j in reversed(range(W - 1)):
        if grid[i][j + 1] == '.' and grid[i][j] == '.':
            graph_1[i][j] = graph_1[i][j + 1]

graph_2 = [[0] * W for _ in range(H)]
for j in range(W):
    for i in range(H):
        if grid[i][j] == '.':
            if i != 0 and grid[i - 1][j] == '.':
                graph_2[i][j] = graph_2[i - 1][j] + 1
            else:
                graph_2[i][j] = 1

for j in range(W):
    for i in reversed(range(H - 1)):
        if grid[i + 1][j] == '.' and grid[i][j] == '.':
            graph_2[i][j] = graph_2[i + 1][j]

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, graph_1[i][j] + graph_2[i][j] - 1)
        
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key=lambda x: (x[0], -x[1]))
for a, b in X:
  print(a, b)

Fixed submission:
N = int(input())
X = [list(input().split()) for _ in range(N)]
for i, t in sorted(enumerate(X), key=lambda x: (x[1][0], -int(x[1][1]))):
  print(i + 1)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
d = []
for _ in range(M):
    b, c = map(int, input().split())
    d += [c] * b

ans = []
i_a = 0
i_d = 0
MAX_D = len(d)

A.sort(reverse=True)
d.sort(reverse=True)

while len(ans) < N:
    if i_d < MAX_D and A[i_a] < d[i_d]:
            ans.append(d[i_d])
            i_d += 1
    else:
            ans.append(A[i_a])
            i_a += 1

print(sum(ans))
    

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

X = [list(map(int, input().split())) for _ in range(M)]
X.sort(key=lambda x: x[1], reverse=True)
num_cnt = [x[0] for x in X]
val_cnt = [x[1] for x in X]

idx = 0
cnt = 0
ans = 0
cum = 0
for i in range(min(N, sum(num_cnt))):
  if val_cnt[idx] <= a[i]:
    print(sum(a[i:]) + ans)
    break
  ans += val_cnt[idx]
  cnt += 1
  cum += 1
  if num_cnt[idx] == cnt:
    idx += 1
    cnt = 0
  if cum == N:
    print(ans)
    break
else:
  print(sum(a[sum(num_cnt):] + [val_cnt[i] * num_cnt[i] for i in range(M)]))

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

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

for b, c in X:
  cnt = 0
  for i in range(N):
    if a[i] < c and cnt < b:
      a[i] = c
      cnt += 1
print(sum(a))

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

X = [list(map(int, input().split())) for _ in range(M)]
X.sort(key=lambda x: x[1], reverse=True)
num_cnt = [x[0] for x in X]
val_cnt = [x[1] for x in X]

idx = 0
cnt = 0
ans = 0
cum = 0
for i in range(min(N, sum(num_cnt))):
  if val_cnt[idx] <= a[i]:
    print(sum(a[i:]) + ans)
    break
  ans += val_cnt[idx]
  cnt += 1
  cum += 1
  if num_cnt[idx] == cnt:
    idx += 1
    cnt = 0
  if cum == N:
    print(ans)
    break
else:
  print(sum(a[sum(num_cnt):] + [val_cnt[i] * num_cnt[i] for i in range(M)]))
Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
MOD = 10 ** 9 + 7

def comb(n, k):
    ret = 1
    for i in range(1, k + 1):
        ret = ret * (n - i + 1) % MOD        
        ret = ret * pow(i, MOD - 2, MOD) % MOD
        
    return ret

ans = 0
for d in range(N):
    ans += d * comb(N * M - 2, K - 2) * (N - d) * M ** 2
    ans %= MOD
    
for d in range(M):
    ans += d * comb(N * M - 2, K - 2) * (M - d) * N ** 2
    ans %= MOD
    
print(ans)



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

def comb(n, k):
    ret = 1
    for i in range(1, k + 1):
        ret = ret * (n - i + 1) % MOD        
        ret = ret * pow(i, MOD - 2, MOD) % MOD
        
    return ret

ans = 0
for d in range(N):
    ans += d * (N - d) * M ** 2
    ans %= MOD
    
for d in range(M):
    ans += d * (M - d) * N ** 2
    ans %= MOD
    
print(ans * comb(N * M - 2, K - 2) % MOD)
Buggy python submission (verdict: Runtime Error):
from math import log2, ceil

ans = 0
max_pow = ceil(log2(K))
for n in range(1, N + 1):
    ans += 2 ** (max_pow - max(0, ceil(log2(K / n))))
    
print(ans / (N * 2 ** max_pow))

Fixed submission:
from math import log2, ceil

N, K = map(int, input().split())
ans = 0
max_pow = ceil(log2(K))
for n in range(1, N + 1):
    ans += 2 ** (max_pow - max(0, ceil(log2(K / n))))
print(ans / (N * 2 ** max_pow))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H, W = map(int, input().split())
grid = [input() for _ in range(H)]

offsets = [(1, 0), (-1, 0), (0, 1), (0, -1)]
graph = [[float('inf')] * W for _ in range(H)]
deq = deque()

for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            graph[i][j] = 0
            deq.append((i, j))

while deq:
    x, y = deq.popleft()
    for i, j in offsets:
        if (not 0 <= x + i < H) or (not 0 <= y + j < W):
            continue

        if graph[x + i][y + j] < float('inf'):
            continue

        if grid[x + i][y + j] == '#':
            continue
            
        graph[x + i][y + j] = graph[x][y] + 1
        deq.append((x + i, y + j))
        
print(max(max(v) for v in graph))

Fixed submission:
from collections import deque

H, W = map(int, input().split())
grid = [input() for _ in range(H)]

offsets = [(1, 0), (-1, 0), (0, 1), (0, -1)]
graph = [[float('inf')] * W for _ in range(H)]
deq = deque()

for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            graph[i][j] = 0
            deq.append((i, j))

while deq:
    x, y = deq.popleft()
        
    for i, j in offsets:
        if (not 0 <= x + i < H) or (not 0 <= y + j < W):
            continue

        if graph[x + i][y + j] < float('inf'):
            continue

        if grid[x + i][y + j] == '#':
            continue
            
        graph[x + i][y + j] = graph[x][y] + 1
        deq.append((x + i, y + j))
        
print(max(max(v) for v in graph))
Buggy python submission (verdict: Runtime Error):
N, *x = map(int, input(0))
print(5 + (N // min(x)))

Fixed submission:
N, *x = map(int, open(0))
print(4 - (-N // min(x)))

Buggy python submission (verdict: Runtime Error):
N = int(input())
x = [int(input()) for _ in range(N)]
print(len(x) + (N // min(x)))


Fixed submission:
N, *x = map(int, open(0))
print(4 - (-N // min(x)))

Buggy python submission (verdict: Runtime Error):
N = int(input())
x = [int(i) for i in input()]
print(len(x) + (N // min(x)))

Fixed submission:
N, *x = map(int, open(0))
print(4 - (-N // min(x)))
Buggy python submission (verdict: Time Limit Exceeded):

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

res = []
for a in A:
    for b in B:
        for c in C:
            res.append(a + b + c)

res.sort(reverse=True)
for i in range(K):
    print(res[i])


Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans1 = []
for i in range(X):
    for j in range(Y):
        ans1.append(A[i] + B[j])
        
ans1 = sorted(ans1, reverse=True)[:K]

ans = []
for i in range(len(ans1)):
    for j in range(Z):
        ans.append(ans1[i] + C[j])
        
print(*sorted(ans, reverse=True)[:K], sep='\n')
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input())
X = [list(map(int, input().split())) for _ in range(N)]

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(res)

Fixed submission:
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)

while True:
  if '01' in s or '10' in s:
    s = s.replace('01', '')
    s = s.replace('10', '')
  else:
    break

print(l - len(s))
    

Fixed submission:
s = input()
print(2 * min([sum([v == '1' for v in s]), sum([v == '0' for v in s])]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)

def df(s):
  while True:
    if '01' in s or '10' in s:
      s = s.replace('01', '')
      s = s.replace('10', '')
    else:
      break
  return s

if len(s) < 1000:
  print(l - len(df(s)))
else:
  i = l // 4
  sx = df(s[:i]) + df(s[i:i * 2]) \
         + df(s[i * 2:i * 3]) + df(s[i * 3:])
  print(l - len(df(sx)))

Fixed submission:
s = input()
print(2 * min([sum([v == '1' for v in s]), sum([v == '0' for v in s])]))

Buggy python submission (verdict: Runtime Error):
s = input()
l = len(s)

def df(s):
  while True:
    if '01' in s or '10' in s:
      s = s.replace('01', '')
      s = s.replace('10', '')
    else:
      break
  return s

if len(s) < 1000:
  print(l - len(df(s)))
else:
  i = l // 4
  sx = df(s[:i]) + df[i:i * 2] + df[i * 2:i * 3] + df[i * 3:]
  print(l - len(df(sx)))

Fixed submission:
s = input()
print(2 * min([sum([v == '1' for v in s]), sum([v == '0' for v in s])]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)

while True:
  if '01' in s or '10' in s:
    s = s.replace('01', '')
    s = s.replace('10', '')
  else:
    break

print(l - len(s))

Fixed submission:
s = input()
print(2 * min([sum([v == '1' for v in s]), sum([v == '0' for v in s])]))
Buggy python submission (verdict: Runtime Error):
from math import gcd

N, *A = map(int, open(0).read().split())

ans = A[0]
for v in A[1:]:
    ans = gcd(ans, v)
    
print(ans)

Fixed submission:
def gcd(x, y):
  if x < y:
    a = y
    y = x
    x = a
  
  while y > 0:
    r = x % y
    x = y
    y = r
  
  return x

def main():
  N = int(input())
  a = list(map(int, input().split()))
  r = a[0]
  
  for i in range(1, len(a)):
    r = gcd(r, a[i])
    if r == 1:
      break

  print(r)
    

if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = [a[i] - b[i] for i in range(n)]
c.sort()

neg = [v for v in c if c < 0]
total = abs(sum(neg))
num = len(neg)
for i, v in enumerate(reversed(pos(c[num:]))):
    total += v
    if total >= 0:
        break

print(num + i)

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

c = [a[i] - b[i] for i in range(n)]
c.sort()

neg = [v for v in c if v < 0]
total = sum(neg)
num = len(neg)

if sum(c) < 0:
    print(-1)
elif num == 0:
    print(0)
else:
    for v in reversed(c[num:]):
        total += v
        num += 1
        if total >= 0:
            break
    print(num)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = [a[i] - b[i] for i in range(n)]
c.sort()

neg = [v for v in c if c < 0]
total = abs(sum(neg))
num = len(neg)
for i, v in enumerate(reversed(pos(c[num:]))):
    total += v
    if total >= 0:
        break

print(num + i)

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

c = [a[i] - b[i] for i in range(n)]
c.sort()

neg = [v for v in c if v < 0]
total = sum(neg)
num = len(neg)

if sum(c) < 0:
    print(-1)
elif num == 0:
    print(0)
else:
    for v in reversed(c[num:]):
        total += v
        num += 1
        if total >= 0:
            break
    print(num)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = [a[i] - b[i] for i in range(12)]
c.sort()

if sum(c) < 0:
    print(-1)

neg = [v for v in c if c < 0]
pos = [v for v in c if c > 0]
total = abs(sum(neg))

k = 0
for i, v in enumerate(reversed(pos)):
    k += v
    if k >= total:
        break

print(len(neg) + i + 1)

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

c = [a[i] - b[i] for i in range(n)]
c.sort()

neg = [v for v in c if v < 0]
total = sum(neg)
num = len(neg)

if sum(c) < 0:
    print(-1)
elif num == 0:
    print(0)
else:
    for v in reversed(c[num:]):
        total += v
        num += 1
        if total >= 0:
            break
    print(num)
Buggy python submission (verdict: Runtime Error):

N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

res = [""] * M
ctr = [0] * (M + 1)
for i, (p, y) in sorted(enumerate(X), key=lambda x: (x[1][0], x[1][1])):
    ctr[p] += 1
    res[i] = "{:0>6}{:0>6}".format(p, ctr[p])

print(*res, sep="\n")


Fixed submission:
N, M = map(int, input().split())
P, Y = zip(*(map(int, input().split()) for _ in range(M)))
ans = ['' for _ in range(M)]
c = [1 for _ in range(N + 1)]

for i, t in sorted(enumerate(zip(P, Y)), key=lambda x: x[1][1]):
  ans[i] = '{:06}{:06}'.format(t[0], c[t[0]])
  c[t[0]] += 1
  
print('\n'.join(ans))
Buggy python submission (verdict: Time Limit Exceeded):

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

ans = 1
for n in range(1, M // N + 1):
    res = M - n * N
    if res % n == 0:
        ans = n

print(ans)


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

divisor = []
for i in range(1, int(M ** 0.5) + 1):
    if M % i == 0:
        divisor.append(i)
        if i != M // i:
            divisor.append(M // i)

print(max(v for v in divisor if v <= M // N))
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n, *v = map(int, open(0).read().split())
if v[::2] == v[1::2]:
        print(n // 2)
    else:
        print(n - Counter(v[::2]).most_common()[0][1] - Counter(v[1::2]).most_common()[0][1])


Fixed submission:
from collections import Counter

n, *v = map(int, open(0).read().split())
c1 = Counter(v[::2]).most_common()
c2 = Counter(v[1::2]).most_common()

c1.append([0, 0])
c2.append([0, 0])

if c1[0][0] != c2[0][0]:
  print(n - c1[0][1] - c2[0][1])
else:
  print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))