Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
    for l, s in enumerate(S, 1):
        if int(s) % P == 0: ans += l
else:
    counter = [0] * P
    counter[0] = 1
    for i in range(N-1, -1, -1):
        num = int(S[i:]) % P
        ans += counter[num]
        counter[num] += 1
print(ans)

Fixed submission:
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
    for l, s in enumerate(S, 1):
        if int(s) % P == 0: ans += l
else:
    counter = [0] * P
    counter[0] = 1
    prev = 0
    temp = 1
    for i, s in reversed(list(enumerate(S))):
        num = (int(s) * temp + prev) % P
        ans += counter[num]
        counter[num] += 1
        prev = num
        temp = (temp * 10) % P
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
    for l, s in enumerate(S, 1):
        if int(s) % P == 0: ans += l
else:
    counter = {}
    counter[0] = 1
    for i in range(N-1, -1, -1):
        num = int(S[i:]) % P
        ans += counter.setdefault(num, 0)
        counter[num] += 1
print(ans)

Fixed submission:
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
    for l, s in enumerate(S, 1):
        if int(s) % P == 0: ans += l
else:
    counter = [0] * P
    counter[0] = 1
    prev = 0
    temp = 1
    for i, s in reversed(list(enumerate(S))):
        num = (int(s) * temp + prev) % P
        ans += counter[num]
        counter[num] += 1
        prev = num
        temp = (temp * 10) % P
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
    for l, s in enumerate(S, 1):
        if int(s) % P == 0: ans += l
else:
    counter = {i: 0 for i in range(P)}
    counter[0] = 1
    for i in reversed(range(N)):
        num = int(S[i:]) % P
        ans += counter[num]
        counter[num] += 1
print(ans)

Fixed submission:
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
    for l, s in enumerate(S, 1):
        if int(s) % P == 0: ans += l
else:
    counter = [0] * P
    counter[0] = 1
    prev = 0
    temp = 1
    for i, s in reversed(list(enumerate(S))):
        num = (int(s) * temp + prev) % P
        ans += counter[num]
        counter[num] += 1
        prev = num
        temp = (temp * 10) % P
print(ans)
Buggy python submission (verdict: Runtime Error):
N = list(input())
ans = 0
temp = [0] + [int(n) for n in N]
for i in reversed(range(1, len(N)+1)):
    if temp[i] < 5 or (temp[i] == 5 and temp[i+1] < 4):
        ans += temp[i]
    else:
        temp[i+1] += 1
        ans += (10 - temp[i])
        temp[i] = 0
ans += temp[0]
print(ans)

Fixed submission:
N = list(input())
ans = 0
temp = [0] + [int(n) for n in N]
for i in reversed(range(1, len(N)+1)):
    if temp[i] < 5 or (temp[i] == 5 and temp[i-1] < 5):
        ans += temp[i]
    else:
        temp[i-1] += 1
        ans += (10 - temp[i])
        temp[i] = 0
ans += temp[0]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline

INF = 10**12

H, N = map(int, input().split())
magics = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[INF]*(H+1) for _ in range(N+1)]
dp[0][0] = 0
for i, (a, b) in enumerate(magics):
    for j in range(H+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        dp[i+1][min(H, j+a)] = min(dp[i+1][min(H, j+a)], dp[i+1][j] + b)
print(dp[N][H])

Fixed submission:
INF = 10**12

H, N = map(int, input().split())
magics = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[INF]*(H+1) for _ in range(N+1)]
dp[0][0] = 0
for i, (a, b) in enumerate(magics):
    for j in range(H+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        dp[i+1][min(H, j+a)] = min(dp[i+1][min(H, j+a)], dp[i+1][j] + b)
print(dp[N][H])
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right

def div_ceil(x, y): return (x + y - 1) // y

N, D, A = map(int, input().split())
monsters = [list(map(int, input().split())) for _ in range(N)]
monsters = sorted(monsters, key=lambda x: x[0])
position = [x for x, _ in monsters]
ans = 0
for i, m in enumerate(monsters):
    x, hp = m
    if hp <= 0: continue
    j = bisect_right(position, x + 2*D)
    attack = div_ceil(hp, A)
    ans += attack
    damage = attack * A
    for k in range(i+1, min(j, N)):
        monsters[k][1] -= damage
print(ans)

Fixed submission:
from bisect import bisect_right

def div_ceil(x, y): return (x + y - 1) // y

N, D, A = map(int, input().split())
monsters = [list(map(int, input().split())) for _ in range(N)]
monsters = sorted(monsters, key=lambda x: x[0])
position = [x for x, _ in monsters]
damage = [0] * (N+2)
ans = 0
for i, [x, hp] in enumerate(monsters, 1):
    damage[i] += damage[i-1]
    if damage[i] >= hp: continue
    hp -= damage[i]
    j = bisect_right(position, x + 2*D) + 1
    attack = div_ceil(hp, A)
    ans += attack
    dam = attack * A
    # imos's method
    damage[i] += dam
    damage[j] -= dam
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
tracks = [tuple(map(int, input().split())) for _ in range(N)]
X = input()
sleep = False
ans = 0
for s, t in tracks:
    if sleep:
        ans += t
    if s == X:
        sleep = True
print(ans)

Fixed submission:
N = int(input())
tracks = [tuple(input().split()) for _ in range(N)]
X = input()
sleep = False
ans = 0
for s, t in tracks:
    t = int(t)
    if sleep:
        ans += t
    if s == X:
        sleep = True
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import permutations

N = int(input())
*P, = map(int, input().split())
*Q, = map(int, input().split())
P = tuple(P); Q = tuple(Q)
for i, t in enumerate(permutations(range(1, N+1))):
    if t == P:
        a = i
    elif t == Q:
        b = i
print(abs(a - b))

Fixed submission:
from itertools import permutations

N = int(input())
*P, = map(int, input().split())
*Q, = map(int, input().split())
P = tuple(P); Q = tuple(Q)
for i, t in enumerate(permutations(range(1, N+1))):
    if t == P:
        a = i
    if t == Q:
        b = i
print(abs(a - b))
Buggy python submission (verdict: Runtime Error):
from math import log10

N = int(input())
if N % 2 == 1: print(0)
else:
    temp = [N // ((5**i) * 2) for i in range(1, 2 * int(log10(N)) + 1)]
    ans = sum(temp)
    print(ans)

Fixed submission:
from math import log10

N = int(input())
if N == 0 or N % 2 == 1: print(0)
else:
    temp = [N // ((5**i) * 2) for i in range(1, 2 * int(log10(N)) + 1)]
    ans = sum(temp)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
ans = 0
for i in range(60):
    bit_0, bit_1 = 0, 0
    for a in A:
        if (a >> i) & 1: 
            bit_1 += 1
        else:
            bit_0 += 1
    ans += bit_1 * bit_0 * pow(2, i, MOD)
    ans %= MOD
print(ans)


Fixed submission:
MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
ans = 0
for i in range(60):
    bit_0, bit_1 = 0, 0
    for a in A:
        if (a >> i) & 1: 
            bit_1 += 1
        else:
            bit_0 += 1
    ans += bit_1 * bit_0 * pow(2, i, MOD)
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
ans = 0
for i in range(len(format(max(A), 'b'))):
    bit_0, bit_1 = 0, 0
    for a in A:
        if (a >> i) & 1: 
            bit_1 += 1
        else:
            bit_0 += 1
    ans += bit_1 * bit_0 * pow(2, i, MOD)
    ans %= MOD
print(ans)

Fixed submission:
MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
ans = 0
for i in range(60):
    bit_0, bit_1 = 0, 0
    for a in A:
        if (a >> i) & 1: 
            bit_1 += 1
        else:
            bit_0 += 1
    ans += bit_1 * bit_0 * pow(2, i, MOD)
    ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
hats = [0] * 3
ans = 1
for a in A:
    ans = (ans * len([h for h in hats if h == a])) % MOD
    idx = hats.index(a)
    hats[idx] += 1
print(ans)

Fixed submission:
MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
hats = [0] * 3
ans = 1
for a in A:
    ans = (ans * hats.count(a)) % MOD
    for i in range(3):
        if hats[i] == a:
            hats[i] += 1
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
from collections import defaultdict

INF = float('inf')
def dijkstra(V, E, s):
    '''
    Input:
        V = list(range(N))
        E = defaultdict(dict)
        s (in V) : start vertex
    Output:
        dist: the list of the minimum cost from s to arbitrary vertex v in the given graph
    '''
    dist = {v: INF for v in V}
    heap = []
    dist[s] = 0; rem = len(V);
    heappush(heap, (0, s))
    while heap and rem:
        d, v = heappop(heap)
        # don't need to check when the stored value is greater than provisional distance
        if d > dist[v]: continue
        rem -= 1;
        for u, c in E[v].items():
            temp = d + c
            if temp < dist[u]:
                dist[u] = temp
                heappush(heap, (temp, u))
    return dist

N, M = map(int, input().split())
V = list(range(N))
E = defaultdict(dict)
for _ in range(M):
    l, r, c = map(int, input().split())
    l, r = l-1, r-1
    E[l][r] = min(c, E[l].setdefault(r, INF))
    for i in range(l, r+1):
        E[i+1][i] = 0
dist = dijkstra(V, E, 0)
print(dist[N-1] if dist[N-1] != INF else -1)

Fixed submission:
from heapq import heappush, heappop
from collections import defaultdict

INF = float('inf')
def dijkstra(V, E, s):
    '''
    Input:
        V = list(range(N))
        E = defaultdict(dict)
        s (in V) : start vertex
    Output:
        dist: the list of the minimum cost from s to arbitrary vertex v in the given graph
    '''
    dist = {v: INF for v in V}
    heap = []
    dist[s] = 0; rem = len(V);
    heappush(heap, (0, s))
    while heap and rem:
        d, v = heappop(heap)
        # don't need to check when the stored value is greater than provisional distance
        if d > dist[v]: continue
        rem -= 1;
        for u, c in E[v].items():
            temp = d + c
            if temp < dist[u]:
                dist[u] = temp
                heappush(heap, (temp, u))
    return dist

N, M = map(int, input().split())
V = list(range(N))
E = defaultdict(dict)
for i in range(N):
    E[i+1][i] = 0
for _ in range(M):
    l, r, c = map(int, input().split())
    l, r = l-1, r-1
    E[l][r] = min(c, E[l].setdefault(r, INF))
dist = dijkstra(V, E, 0)
print(dist[N-1] if dist[N-1] != INF else -1)
Buggy python submission (verdict: Runtime Error):
from numba import njit

N, K = map(int, input().split())
*A, = map(int, input().split())
*F, = map(int, input().split())
A, F = sorted(A), sorted(F, reverse=True)

@njit
def cond(x):
    k = 0
    for a, f in zip(A, F): k += max(a - (x // f), 0)
    return True if k <= K else False 

MIN = -1
MAX = 10**12 + 1
left, right = MIN, MAX # search range
while right - left > 1:
    mid = (left + right) // 2
    if cond(mid): right = mid
    else: left = mid
print(right)

Fixed submission:
N, K = map(int, input().split())
*A, = map(int, input().split())
*F, = map(int, input().split())
A, F = sorted(A), sorted(F, reverse=True)

def cond(x):
    k = 0
    for a, f in zip(A, F): k += max(a - (x // f), 0)
    return True if k <= K else False 

MIN = -1
MAX = 10**12 + 1
left, right = MIN, MAX # search range
while right - left > 1:
    mid = (left + right) // 2
    if cond(mid): right = mid
    else: left = mid
print(right)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
*A, = map(int, input().split())
*F, = map(int, input().split())
A, F = sorted(A), sorted(F, reverse=True)

def cond(x):
    k = 0
    for a, f in zip(A, F): k += max(a - (x // f), 0)
    return True if k <= K else False 

MIN = -1
MAX = 10**12 + 1
left, right = MIN, MAX # search range
while right - left > 1:
    mid = (left + right) // 2
    if cond(mid): right = mid
    else: left = mid
print(right)

Fixed submission:
N, K = map(int, input().split())
*A, = map(int, input().split())
*F, = map(int, input().split())
A, F = sorted(A), sorted(F, reverse=True)

def cond(x):
    k = 0
    for a, f in zip(A, F): k += max(a - (x // f), 0)
    return True if k <= K else False 

MIN = -1
MAX = 10**12 + 1
left, right = MIN, MAX # search range
while right - left > 1:
    mid = (left + right) // 2
    if cond(mid): right = mid
    else: left = mid
print(right)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
from bisect import bisect_right

N = int(input())
*L, = map(int, input().split())
L = sorted(L)
ans = 0
for i, j in combinations(reversed(range(N)), 2): # i > j
    cand = L[:j]
    if not cand: continue
    idx = bisect_right(cand, abs(L[i] - L[j]))
    ans += j - idx
print(ans)

Fixed submission:
from itertools import combinations
from bisect import bisect_left

N = int(input())
*L, = map(int, input().split())
L = sorted(L)
ans = 0
for i, j in combinations(range(N), 2): # i < j
    idx = bisect_left(L, L[i] + L[j])
    ans += idx - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N = int(input())
*L, = map(int, input().split())
ans = 0
while len(L) >= 3:
    c = L.pop()
    for a, b in combinations(L, 2):
        if abs(a - b) < c < a + b: ans += 1
print(ans)

Fixed submission:
from itertools import combinations
from bisect import bisect_left

N = int(input())
*L, = map(int, input().split())
L = sorted(L)
ans = 0
for i, j in combinations(range(N), 2): # i < j
    idx = bisect_left(L, L[i] + L[j])
    ans += idx - j - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**9
N, M = map(int, input().split())
dp = [INF for _ in range(2**N)]
dp[0] = 0
for i in range(M):
    a, _ = map(int, input().split())
    *C, = map(int, input().split())
    open_bit = 0
    for i in C: open_bit |= 1 << i-1
    for i in range(2**N): dp[i|open_bit] = min(dp[i|open_bit], dp[i] + a)
print(dp[-1] if dp[-1] != INF else -1)

Fixed submission:
def main():
    INF = float('inf')
    N, M = map(int, input().split())
    dp = [INF for _ in range(2**N)]
    dp[0] = 0
    for i in range(M):
        a, _ = map(int, input().split())
        *C, = map(int, input().split())
        open_bit = 0
        for i in C: open_bit |= 1 << i-1
        for i in range(2**N): dp[i|open_bit] = min(dp[i|open_bit], dp[i] + a)
    print(dp[-1] if dp[-1] != INF else -1)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
INF = float('inf')
N, M = map(int, input().split())
dp = [INF for _ in range(2**N)]
dp[0] = 0
for i in range(M):
    a, _ = map(int, input().split())
    *C, = map(int, input().split())
    open_bit = 0
    for i in C: open_bit |= 1 << i-1
    for i in range(2**N): dp[i|open_bit] = min(dp[i|open_bit], dp[i] + a)
print(dp[-1] if dp[-1] != INF else -1)

Fixed submission:
def main():
    INF = float('inf')
    N, M = map(int, input().split())
    dp = [INF for _ in range(2**N)]
    dp[0] = 0
    for i in range(M):
        a, _ = map(int, input().split())
        *C, = map(int, input().split())
        open_bit = 0
        for i in C: open_bit |= 1 << i-1
        for i in range(2**N): dp[i|open_bit] = min(dp[i|open_bit], dp[i] + a)
    print(dp[-1] if dp[-1] != INF else -1)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N, Q = map(int, input().split())
V = {v: 0 for v in range(1, N+1)}
E = {v: [] for v in V.keys()}
for _ in range(N-1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)
added = defaultdict(int)
for _ in range(Q):
    p, x = map(int, input().split())
    added[p] += x
stack = [(1, added[1])]
visited = {v: False for v in V.keys()}
while stack:
    v, value = stack.pop()
    visited[v] = True
    V[v] += value
    for u in E[v]:
        if not visited[u]:
            stack.append((u, value + added[u]))
print(*[val for val in V.values()])

Fixed submission:
N, Q = map(int, input().split())
V = {v: 0 for v in range(1, N+1)}
E = {v: [] for v in V.keys()}
for _ in range(N-1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)
added = {v: 0 for v in V.keys()}
for _ in range(Q):
    p, x = map(int, input().split())
    added[p] += x
stack = [(1, added[1])]
visited = {v: False for v in V.keys()}
while stack:
    v, value = stack.pop()
    visited[v] = True
    V[v] += value
    for u in E[v]:
        if not visited[u]:
            stack.append((u, value + added[u]))
print(*[val for val in V.values()])
Buggy python submission (verdict: Runtime Error):
from heapq import *
from collections import defaultdict

N, M = map(int, input().split())
arbeits = defaultdict(list)
for _ in range(N):
    a, b = map(int, input().split())
    arbeits[a].append(b)
heap = []
ans = 0
for i in range(1, M+1):
    for b in arbeits[i]:
        heappush(heap, -b)
    ans += - heappop(heap)
print(ans)

Fixed submission:
from heapq import *
from collections import defaultdict

N, M = map(int, input().split())
arbeits = defaultdict(list)
for _ in range(N):
    a, b = map(int, input().split())
    arbeits[a].append(b)
heap = []
ans = 0
for i in range(1, M+1):
    for b in arbeits[i]:
        heappush(heap, -b)
    if heap:
        ans += - heappop(heap)
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
print(max(C - (A - B)), 0)

Fixed submission:
A, B, C = map(int, input().split())
print(max(C - (A - B), 0))
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0
for i in range(1, len(str(N)), 2):
    ans += 10**i - 10**(i-1)
ans += (int(str(N)[1:]) + 1) * (1 if len(str(N)) % 2 == 1 else 0)
print(ans)

Fixed submission:
N = int(input())
ans = 0
n_digit = len(str(N))
for i in range(1, n_digit, 2):
    ans += 10**i - 10**(i-1)
if n_digit % 2 == 1: ans += N - 10**(n_digit - 1) + 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right, insort_right

N = int(input())
A = [int(input()) for _ in range(N)]
B = [A[-1]]
for a in reversed(A[:-1]):
    idx = bisect_right(B, a)
    if idx == len(B):
        insort_right(B, a)
    else:
        B[idx] = a
        B.sort()
print(len(B))

Fixed submission:
from bisect import bisect_right

N = int(input())
A = [int(input()) for _ in range(N)]
B = [A[-1]]
ans = 1
for a in reversed(A[:-1]):
    idx = bisect_right(B, a)
    if idx == ans:
        B.append(a)
        ans += 1
    else:
        B[idx] = a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
*A, = map(int, input().split())
X = [0]*N
X_total = sum(A)
for i in range(N):
    X[i] = X_total - 2*sum([A[j % N] for j in range(i+1, N+i, 2)])
print(*X)

Fixed submission:
N = int(input())
*A, = map(int, input().split())
X = [0]*N
X_total = sum(A)
A_odd = sum([A[i % N] for i in range(1, N, 2)])
A_even = sum([A[i % N] for i in range(2, N+1, 2)])
for i in range(N):
    X[i] = X_total - 2*(A_odd if i % 2 == 0 else A_even)
    if i % 2 == 0: A_odd += A[i] - A[(i+1) % N]
    else: A_even += A[i] - A[(i+1) % N]
print(*X)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
*A, = map(int, input().split())
X = [0]*N
X_total = sum(A)
for i in range(N):
    X[i] = X_total - 2*sum([A[j % N] for j in range(i+1, N+i, 2)])
print(*X)

Fixed submission:
N = int(input())
*A, = map(int, input().split())
X = [0]*N
X_total = sum(A)
A_odd = sum([A[i % N] for i in range(1, N, 2)])
A_even = sum([A[i % N] for i in range(2, N+1, 2)])
for i in range(N):
    X[i] = X_total - 2*(A_odd if i % 2 == 0 else A_even)
    if i % 2 == 0: A_odd += A[i] - A[(i+1) % N]
    else: A_even += A[i] - A[(i+1) % N]
print(*X)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
*A, = map(int, input().split())
A = np.array(A, dtype='int64')
C = np.diag([1 for _ in range(N)]) + np.diag([1 for _ in range(N-1)], k=1)
C[-1, 0] = 1
C = np.array(C, dtype='int64')
X = 2*np.linalg.solve(C, A)
X = list(map(int, X))
print(*X)

Fixed submission:
N = int(input())
*A, = map(int, input().split())
X = [0]*N
X_total = sum(A)
A_odd = sum([A[i % N] for i in range(1, N, 2)])
A_even = sum([A[i % N] for i in range(2, N+1, 2)])
for i in range(N):
    X[i] = X_total - 2*(A_odd if i % 2 == 0 else A_even)
    if i % 2 == 0: A_odd += A[i] - A[(i+1) % N]
    else: A_even += A[i] - A[(i+1) % N]
print(*X)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
*A, = map(int, input().split())
A = np.array(A, dtype='int64')
C = np.diag([1 for _ in range(N)]) + np.diag([1 for _ in range(N-1)], k=1)
C[-1, 0] = 1
X = np.linalg.solve(C, A)
X = list(map(int, X))
print(*X)

Fixed submission:
N = int(input())
*A, = map(int, input().split())
X = [0]*N
X_total = sum(A)
A_odd = sum([A[i % N] for i in range(1, N, 2)])
A_even = sum([A[i % N] for i in range(2, N+1, 2)])
for i in range(N):
    X[i] = X_total - 2*(A_odd if i % 2 == 0 else A_even)
    if i % 2 == 0: A_odd += A[i] - A[(i+1) % N]
    else: A_even += A[i] - A[(i+1) % N]
print(*X)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from itertools import permutations

N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]
cnt = defaultdict(int)
for b1, b2 in permutations(balls, 2):
    cnt[(b2[0] - b1[0], b2[1] - b1[1])] += 1
_, n = max(cnt.items(), key=lambda x: x[1])
cost = N - n
print(cost)

Fixed submission:
from collections import defaultdict
from itertools import permutations

N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]
if N == 1: print(1)
else:
    cnt = defaultdict(int)
    for b1, b2 in permutations(balls, 2):
        cnt[(b2[0] - b1[0], b2[1] - b1[1])] += 1
    _, n = max(cnt.items(), key=lambda x: x[1])
    cost = N - n
    print(cost)

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

N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]
cnt = defaultdict(int)
for b1, b2 in combinations(balls, 2):
    cnt[(abs(b2[0] - b1[0]), abs(b2[1] - b1[1]))] += 1
_, n = max(cnt.items(), key=lambda x: x[1])
cost = N - n
print(cost)

Fixed submission:
from collections import defaultdict
from itertools import permutations

N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]
if N == 1: print(1)
else:
    cnt = defaultdict(int)
    for b1, b2 in permutations(balls, 2):
        cnt[(b2[0] - b1[0], b2[1] - b1[1])] += 1
    _, n = max(cnt.items(), key=lambda x: x[1])
    cost = N - n
    print(cost)
Buggy python submission (verdict: Time Limit Exceeded):
L = input()
digits = len(L)
MOD = 10**9 + 7
ans = pow(2, L.count('1'), MOD)
for i, d in enumerate(L, 1):
    if d == '1': ans = (ans + (pow(3, digits - i, MOD) * pow(2, L[:i-1].count('1'), MOD)) % MOD) % MOD
print(ans)

Fixed submission:
L = input()
digits = len(L)
MOD = 10**9 + 7
ans = pow(2, L.count('1'), MOD)
counter = 0
for i, d in enumerate(L, 1):
    if d == '1':
        ans = (ans + (pow(3, digits - i, MOD) * pow(2, counter, MOD)) % MOD) % MOD
        counter += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
Ls = []
Rs = []
for _ in range(M):
    L, R = map(int, input().split())
    Ls.append(L)
    Rs.append(R+1)
L_max = max(Ls)
R_min = min(Rs)
print(max(R_min - L_max, 0)

Fixed submission:
N, M = map(int, input().split())
Ls = []
Rs = []
for _ in range(M):
    L, R = map(int, input().split())
    Ls.append(L)
    Rs.append(R+1)
L_max = max(Ls)
R_min = min(Rs)
print(max(R_min - L_max, 0))