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

input = sys.stdin.readline

def main(): 
    N = int(input())
    A = [0] + list(map(int, input().split()))
    
    ans = [0] * (N+1)
    c = 0
    for i in range(N, 0, -1):
        t = 0
        for j in range(2*i, N+1):
            t += ans[j]
            
        if A[i] != (t%2): 
            ans[i] = 1
            c += 1
            
    print(c)
    print('1 '*c)

if __name__ == '__main__':
    main()

Fixed submission:
N = int(input())
a = [0] + list(map(int, input().split()))
b = [0] * (N+1)

for i in range(N, 0, -1):
    mod = sum(b[i::i]) % 2
    if mod == a[i]:
        pass
    else:
        b[i] = 1
    
print(b.count(1))
for idx, n in enumerate(b):
    if n:
        print(idx, '', end='')
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
find = [int(input())]

for i in range(N-1):
    A = int(input())

    if find[0] >= A:
        find.insert(0, A)
    else:
        idx = bisect.bisect_left(find, A)
        x = find.pop(idx-1)
        bisect.insort_left(find, A)

print(len(find))

Fixed submission:
from bisect import bisect_right

def main():    
    N = int(input())
    A = [int(input()) for i in range(N)]
    n = [A.pop(-1)]
    A.reverse()
    
    for a in A:
        if n[-1] <= a: n.append(a)
        else: n[bisect_right(n, a)] = a
    
    print(len(n))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
find = [int(input())]

for i in range(N-1):
    A = int(input())
    idx = bisect.bisect_left(find, A)

    if not idx:
        find.insert(0, A)
    else:
        find[idx-1] = A

print(len(find))

Fixed submission:
from bisect import bisect_right

def main():    
    N = int(input())
    A = [int(input()) for i in range(N)]
    n = [A.pop(-1)]
    A.reverse()
    
    for a in A:
        if n[-1] <= a: n.append(a)
        else: n[bisect_right(n, a)] = a
    
    print(len(n))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
dp = [[1] + [0 for i in range(K)] for j in range(N-K+2)]

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

for i in range(1, K+1):
    print((dp[N-K+1][i] * dp[K-1][i-1]) % (10**9+7))

Fixed submission:
N, K = list(map(int, input().split()))
dp = [[1] + [0 for i in range(K)] for j in range(N+1)]

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

for i in range(1, K+1):
    print((dp[N-K+1][i] * dp[K-1][i-1]) % (10**9+7))
Buggy python submission (verdict: Runtime Error):
import fractions as gcd

def lcm(x, y):
    return (x*y) // gcd(x, y)

A, B, C, D = map(int, input().split())

c = B // C - A // C + (not A % C)
d = B // D - A // D + (not A % D)

x = lcm(C, D)
x = B // x - A // x + (not A % x)

print(B-A+1-c-d+x)

Fixed submission:
#import math
import fractions as math

A, B, C, D = list(map(int, input().split()))
ans = []
x = int((C*D)/math.gcd(C,D))

for n in [A-1, B]:
    c = n // C
    d = n // D
    cd = n // x
    ans.append(n-c-d+cd)
print(ans[1]-ans[0])

Buggy python submission (verdict: Runtime Error):
from math import gcd

def lcm(x, y):
    return (x*y) // gcd(x, y)

A, B, C, D = map(int, input().split())

c = B // C - A // C + (not A % C)
d = B // D - A // D + (not A % D)

x = lcm(C, D)
x = B // x - A // x + (not A % x)

print(B-A+1-c-d+x)

Fixed submission:
#import math
import fractions as math

A, B, C, D = list(map(int, input().split()))
ans = []
x = int((C*D)/math.gcd(C,D))

for n in [A-1, B]:
    c = n // C
    d = n // D
    cd = n // x
    ans.append(n-c-d+cd)
print(ans[1]-ans[0])
Buggy python submission (verdict: Runtime Error):
def check(ans, ans_, n):
    if ans == n:
        ans_ = 1
    elif ans < n:
        ans = n
    return ans, ans_

W, H, x, y = list(map(int, input().split()))
total = W * H

ans = min(H*x, total-H*x)
ans_ = 0
ans, ans_ = check(ans, ans_, min(W*y, total-W*y))

for w, h, y_ in [(0, 0, H), (W, 0, H)]:
    a = (y-h) / (x-w)
    x_ = abs(y_ / a)
    if x_ < H/2:
        n = W * y_ / 2
    else:
        n = H * x_ / 2
    ans, ans_ = check(ans, ans_, min(n, total-n))

for w, h, x_ in [(0, H, W), (W, H, W)]:
    a = (y-h) / (x-w)
    y_ = x_ * a
    if y_ >= 0:
        n = (H - y_) * x_ / 2
    else:
        n = y_ * x_ / 2
    ans, ans_ = check(ans, ans_, min(n, total-n))

print(ans, ans_)

Fixed submission:
W, H, x, y = list(map(int, input().split()))
z = [0, 1]
print(W*H/2, z[x*2 == W and y*2 == H])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
gate = [True for i in range(N+1)]

for i in range(M):
    r, m = list(map(int, input().split()))
    gate[:r] = [False] * r
    gate[m+1:] = [False] * (N-m+1)

print(sum(gate))

Fixed submission:
N, M = list(map(int, input().split()))
l = 1
r = N

for i in range(M):
    L, R = list(map(int, input().split()))
    l = max(l, L)
    r = min(r, R)

print(max(0, r-l+1))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
gate = [0 for i in range(N+1)]

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

print(sum([1 for i in gate if i == M]))

Fixed submission:
N, M = list(map(int, input().split()))
l = 1
r = N

for i in range(M):
    L, R = list(map(int, input().split()))
    l = max(l, L)
    r = min(r, R)

print(max(0, r-l+1))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
from bisect import insort_left

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    A = Counter(list(map(int, input().split())))
    
    A = sorted([[a, c] for a, c in A.items()])
    
    for i in range(M):
        B, C = map(int, input().split())
        
        c = idx = 0
        for j in range(len(A)):
            if A[j][0] > C: break
        
            x = min(B, A[j][1])
            c += x
            B -= x
            A[j][1] -= x
            
            if not A[j][1]: idx += 1
            if not B: break
        
        if c: 
            for k in range(idx): A.pop(0)
                
            insort_left(A, [C, c])
    
    print(sum([a[0] * a[1] for a in A]))
    
if __name__ == '__main__':
    main() 

Fixed submission:
from collections import Counter

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = set(A)
A = Counter(A)

for i in range(M):
    B, C = list(map(int, input().split()))
    A[C] += B
    a.add(C)
a = sorted(list(a), reverse=True)

ans = 0

for i in a:
    ans += i * min(A[i], N)
    N -= A[i]
    if N <= 0:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(M):
    B, C = list(map(int, input().split()))
    A.extend([C] * B)
A.sort(reverse=True)
print(sum(A[:N]))

Fixed submission:
from collections import Counter

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = set(A)
A = Counter(A)

for i in range(M):
    B, C = list(map(int, input().split()))
    A[C] += B
    a.add(C)
a = sorted(list(a), reverse=True)

ans = 0

for i in a:
    ans += i * min(A[i], N)
    N -= A[i]
    if N <= 0:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def search(n):
    while A[n-1] != n:
        n = A[n-1]

    return n

N, M = list(map(int, input().split()))
A = [i for i in range(1, N+1)]
ans = 0

for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    X_root, Y_root = search(X), search(Y)

    if X_root != Y_root:
        A[X_root-1] = Y_root
        ans += 1

print(N-ans)

Fixed submission:
def search(n):
    idx = n
    while A[n-1] != n:
        n = A[n-1]
    A[idx-1] = n

    return n

N, M = list(map(int, input().split()))
A = [i for i in range(1, N+1)]
ans = 0

for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    X_root, Y_root = search(X), search(Y)

    if X_root != Y_root:
        A[X_root-1] = Y_root
        ans += 1

print(N-ans)

Buggy python submission (verdict: Time Limit Exceeded):
class Union:
    def __init__(self, n):
        self.root = True
        self.parent = n
        self.size = 1

    def update(self, n, size):
        self.root = False
        self.parent = n
        self.size += size

def search(n):
    global A

    while not A[n-1].root:
        n = A[n-1].parent

    return n, A[n-1].size

N, M = list(map(int, input().split()))
A = [Union(i) for i in range(1, N+1)]
ans = 0

for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    X_root, X_size = search(X)
    Y_root, Y_size = search(Y)

    if X_root != Y_root:
        if X_size < Y_size:
            a, b, size = X_root, Y_root, Y_size
        else:
            a, b, size = Y_root, X_root, X_size

        A[a-1].update(b, size)
        ans += 1

print(N-ans)

Fixed submission:
def search(n):
    idx = n
    while A[n-1] != n:
        n = A[n-1]
    A[idx-1] = n

    return n

N, M = list(map(int, input().split()))
A = [i for i in range(1, N+1)]
ans = 0

for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    X_root, Y_root = search(X), search(Y)

    if X_root != Y_root:
        A[X_root-1] = Y_root
        ans += 1

print(N-ans)

Buggy python submission (verdict: Time Limit Exceeded):
class Union:
    def __init__(self, n):
        self.root = True
        self.parent = n

    def update(self, n):
        self.root = False
        self.parent = n

def search(n):
    global A

    while not A[n-1].root:
        n = A[n-1].parent

    return n

N, M = list(map(int, input().split()))
A = [Union(i) for i in range(1, N+1)]
nums = [i for i in range(1, N+1)]

for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    X_root = search(X)
    Y_root = search(Y)

    if X_root != Y_root:
        A[Y_root-1].update(X_root)
        nums.remove(Y_root)

print(len(nums))

Fixed submission:
def search(n):
    idx = n
    while A[n-1] != n:
        n = A[n-1]
    A[idx-1] = n

    return n

N, M = list(map(int, input().split()))
A = [i for i in range(1, N+1)]
ans = 0

for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    X_root, Y_root = search(X), search(Y)

    if X_root != Y_root:
        A[X_root-1] = Y_root
        ans += 1

print(N-ans)
Buggy python submission (verdict: Runtime Error):
import math

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

gcd_l, gcd_r = [0], [0]

for l, r in [(A[i], A[N-i-1]) for i in range(N)]:
    gcd_l.append(math.gcd(gcd_l[-1], l))
    gcd_r.append(math.gcd(gcd_r[-1], r))
gcd_r.reverse()

gcd_nums = [gcd_l[-1]] + [math.gcd(gcd_l[i], gcd_r[i+1]) for i in range(N)]
print(max(gcd_nums))


Fixed submission:
#import math
import fractions as math

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

gcd_l, gcd_r = [0], [0]

for l, r in [(A[i], A[N-i-1]) for i in range(N)]:
    gcd_l.append(math.gcd(gcd_l[-1], l))
    gcd_r.append(math.gcd(gcd_r[-1], r))
gcd_r.reverse()

gcd_nums = [gcd_l[-1]] + [math.gcd(gcd_l[i], gcd_r[i+1]) for i in range(N)]
print(max(gcd_nums))

Buggy python submission (verdict: Time Limit Exceeded):
#import math
import fractions as math

N = int(input())
A = list(map(int, input().split()))
memo = {}
x = A[1]
for a in A[2:]:
    n = math.gcd(x, a)
    memo[(x, a)] = n
    x = n
max_gcd = x

for i in range(N):
    x = A[0]
    for j in range(N):
        if i == j:
            pass
        else:
            if (x, A[j]) in memo:
                x = memo[(x, A[j])]
            else:
                n = math.gcd(x, A[j])
                memo[(x, A[j])] = n
                x = n
    max_gcd = max(max_gcd, x)
print(max_gcd)

Fixed submission:
#import math
import fractions as math

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

gcd_l, gcd_r = [0], [0]

for l, r in [(A[i], A[N-i-1]) for i in range(N)]:
    gcd_l.append(math.gcd(gcd_l[-1], l))
    gcd_r.append(math.gcd(gcd_r[-1], r))
gcd_r.reverse()

gcd_nums = [gcd_l[-1]] + [math.gcd(gcd_l[i], gcd_r[i+1]) for i in range(N)]
print(max(gcd_nums))

Buggy python submission (verdict: Runtime Error):
#import math
import fraction as math

N = int(input())
A = list(map(int, input().split()))
memo = {}
x = A[1]
for a in A[2:]:
    n = math.gcd(x, a)
    memo[(x, a)] = n
    x = n
max_gcd = x

for i in range(N):
    x = A[0]
    for j in range(N):
        if i == j:
            pass
        else:
            if (x, A[j]) in memo:
                x = memo[(x, A[j])]
            else:
                n = math.gcd(x, A[j])
                memo[(x, A[j])] = n
                x = n
    max_gcd = max(max_gcd, x)
print(max_gcd)

Fixed submission:
#import math
import fractions as math

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

gcd_l, gcd_r = [0], [0]

for l, r in [(A[i], A[N-i-1]) for i in range(N)]:
    gcd_l.append(math.gcd(gcd_l[-1], l))
    gcd_r.append(math.gcd(gcd_r[-1], r))
gcd_r.reverse()

gcd_nums = [gcd_l[-1]] + [math.gcd(gcd_l[i], gcd_r[i+1]) for i in range(N)]
print(max(gcd_nums))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
nums = []

for a in A:
    for b in B:
        for c in C:
            n = a + b + c
            idx = bisect.bisect_right(nums, n)
            if idx == 0 and len(nums) > K:
                break
            else:
                nums.insert(idx, n)
                if len(nums) > K:
                    nums.pop(0)
        if a + b + C[0] < nums[0]:
            break
    if a + B[0] + C[0] < nums[0]:
        break

for n in nums[::-1]:
    print(n)

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

E = sorted([a+b for a in A for b in B], reverse=True)

E = E[:K]
nums = sorted([e+c for e in E for c in C], reverse=True)

for n in nums[:K]:
    print(n)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
nums = []

for a in A:
    for b in B:
        for c in C:
            n = a + b + c
            idx = bisect.bisect_right(nums, n)
            if idx == 0 and len(nums) > K:
                break
            else:
                nums.insert(idx, n)
                if len(nums) > K:
                    nums.pop(0)

for n in nums[::-1]:
    print(n)

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

E = sorted([a+b for a in A for b in B], reverse=True)

E = E[:K]
nums = sorted([e+c for e in E for c in C], reverse=True)

for n in nums[:K]:
    print(n)
Buggy python submission (verdict: Runtime Error):
import itertools

s = 'ACGT'
s = [a+b+c for a,b,c in itertools.product(s,s,s)]
n = {s_:1 for s_ in s}
n['AGC'] = 0
n['GAC'] = 0
n['ACG'] = 0

N = int(input())

for i in range(N-3):
    count = {s_:0 for s_ in s}
    for _ in s:
        for a in 'ACGT':
            x = _+a
            if 'GAC' in x or 'ACG' in x or ('A' == x[0] and 'GC' == x[2:]) or ('AG' == x[:2] and 'C' == x[3]):
                pass
            else:
                count[x[1:]] += n[_]
    count['AGC'] = 0
    count['GAC'] = 0
    count['ACG'] = 0
    n = count
print(sum([value for value in count.values()])%(10**9+7))

Fixed submission:
import itertools

s = 'ACGT'
s = [a+b+c for a,b,c in itertools.product(s,s,s)]
n = {s_:1 for s_ in s}
n['AGC'] = 0
n['GAC'] = 0
n['ACG'] = 0

N = int(input())
if N == 3:
    count = n
else:
    for i in range(N-3):
        count = {s_:0 for s_ in s}
        for _ in s:
            for a in 'ACGT':
                x = _+a
                if 'GAC' in x or 'ACG' in x or ('A' == x[0] and 'GC' == x[2:]) or ('AG' == x[:2] and 'C' == x[3]):
                    pass
                else:
                    count[x[1:]] += n[_]
        count['AGC'] = 0
        count['GAC'] = 0
        count['ACG'] = 0
        n = count
print(sum([value for value in count.values()])%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

tmp = [S[0], '']

for s in S[1:]:

    length = len(tmp)

    for i in range(length):
        if len(tmp[i]) < 26 and s not in tmp[i]:
            tmp.append(tmp[i]+s)

print((len(tmp)-1)%(10**9+7))

Fixed submission:
from collections import Counter

N = int(input())
S = Counter(input())

ans = 1

for value in S.values():
    if value == 1:
        ans *= 2
    else:
        ans *= (value+1)
print((ans-1)%(10**9+7))

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

tmp = [S[0], '']

for s in S[1:]:

    length = len(tmp)

    for i in range(length):
        if s not in tmp[i]:
            tmp.append(tmp[i]+s)

print(len(tmp)-1)

Fixed submission:
from collections import Counter

N = int(input())
S = Counter(input())

ans = 1

for value in S.values():
    if value == 1:
        ans *= 2
    else:
        ans *= (value+1)
print((ans-1)%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
count = 0

while True:
    change = False
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            change = True
            count += 2
            break
    if not change:
        break

print(count)

Fixed submission:
from collections import Counter

S = Counter(input()).most_common()[::-1]

if len(S) == 1:
    print(0)
else:
    print(S[0][1] * 2)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
AB.reverse()
island = [[i+1] for i in range(N)]
ans = []
for m in range(M):
    count = 0
    for i in range(len(island)):
        for j in range(i+1, len(island)):
            count += len(island[i]) * len(island[j])
    ans.append(count)

    A, B = AB.pop(0)
    idxs = [None, None] # A, B
    for idx in range(len(island)):
        if A in island[idx]:
            idxs[0] = idx
        if B in island[idx]:
            idxs[1] = idx
        if None not in idxs:
            break
    if idxs[0] != idxs[1]:
        island[idxs[0]].extend(island[idxs[1]])
        del island[idxs[1]]

ans.reverse()
[print(ans[i]) for i in range(M)]

Fixed submission:
def find(idx):
    global tree
    while True:
        if tree[idx].root == True:
            return tree[idx].prev, tree[idx].size
        else:
            idx = tree[idx].prev

class Union_Find:
    def __init__(self, prev):
        self.root = True
        self.size = 1
        self.prev = prev

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
AB.reverse()
ans = [(N*(N-1))//2]
tree = {i:Union_Find(i) for i in range(1, N+1)}

for A, B in AB[:-1]:
    root_A, size_A = find(A)
    root_B, size_B = find(B)

    if root_A == root_B:
        ans.append(ans[-1])
    else:
        if size_A > size_B:
            x, y = root_B, root_A
        else:
            x, y = root_A, root_B

        tree[x].root = False
        tree[x].prev = y
        tree[y].size += tree[x].size

        ans.append(ans[-1] - size_A * size_B)

[print(max(0, i)) for i in ans[::-1]]
Buggy python submission (verdict: Time Limit Exceeded):
import copy

N, A, B, C = list(map(int, input().split()))
ls = [int(input()) for i in range(N)]

nums = [[[], [], []],
        [[], [], []],
        [[], [], []]] 
    
for l in ls:
    tmpA = []
    for num in nums:
        for i in range(3):
            tmpB = copy.deepcopy(num)
            tmpB[i].append(l)
            tmpA.append(tmpB)
    nums.extend(tmpA)   

ans = 10**20

for num in nums:
    n = abs(A-sum(num[0])) + abs(B-sum(num[1])) + abs(C-sum(num[2])) + 10*(max(0, len(num[0])-1)) + 10*(max(0, len(num[1])-1)) + 10*(max(0, len(num[2])-1))
    
    ans = min(ans, n)
print(ans)


Fixed submission:
def search(idx, a, b, c):
    if idx == N:
        if min(a, b, c) > 0:
            return abs(A-a) + abs(B-b) + abs(C-c) - 30
        else:
            return 10**20
            
    n0 = search(idx+1, a, b, c)
    n1 = search(idx+1, a+l[idx], b, c) + 10
    n2 = search(idx+1, a, b+l[idx], c) + 10
    n3 = search(idx+1, a, b, c+l[idx]) + 10
    
    return min(n0, n1, n2, n3)
    
N, A, B, C = list(map(int, input().split()))
l = [int(input()) for i in range(N)]

print(search(0, 0, 0, 0))

Buggy python submission (verdict: Runtime Error):
import bisect

ans = 10**20

N, K = list(map(int, input().split()))
x = [-10**20] + list(map(int, input().split())) + [10**20]

zero = bisect.bisect_left(x, 0)

left = x[:zero] + [0] 
right = [0] + x[zero:]
left.reverse()
l = len(left)
r = len(right)

idxs = [[K-i, i] for i in range(K+1) if K-i < l and i < r]

for l, r in idxs:
    n = abs(left[l]) + right[r] + min(abs(left[l]), right[r])
    ans = min(ans, n)
print(ans)

Fixed submission:
def search(idx, a, b, c):
    if idx == N:
        if min(a, b, c) > 0:
            return abs(A-a) + abs(B-b) + abs(C-c) - 30
        else:
            return 10**20
            
    n0 = search(idx+1, a, b, c)
    n1 = search(idx+1, a+l[idx], b, c) + 10
    n2 = search(idx+1, a, b+l[idx], c) + 10
    n3 = search(idx+1, a, b, c+l[idx]) + 10
    
    return min(n0, n1, n2, n3)
    
N, A, B, C = list(map(int, input().split()))
l = [int(input()) for i in range(N)]

print(search(0, 0, 0, 0))
Buggy python submission (verdict: Time Limit Exceeded):
import queue
from collections import Counter
from operator import itemgetter

N, K = list(map(int, input().split()))
td = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(1), reverse=True)
group = queue.PriorityQueue()
count = Counter()
ans = 0

for t, d in td[:K]:
    group.put([d, t])
    count[t] += 1
    ans += d
ans += len(count) ** 2

s = queue.PriorityQueue()
s_count = Counter()
for t, d in td[K:]:
    if not count[t] and not s_count[t]:
        s.put([-d, t])
        s_count[t] += 1

n = ans
x = len(count)
while group.qsize():
    d, t = group.get()
    if count[t] != 1:
        count[t] -= 1
        n -= (d + x**2)

        d_, t_ = s.get()
        count[t_] += 1
        x += 1
        n += (-d_ + x**2)
        ans = max(ans, n)
print(ans)

Fixed submission:
import heapq

N, K = list(map(int, input().split()))
td = []
td_ = []
group = set()
total = 0

for i in range(N):
    t, d = list(map(int, input().split()))
    heapq.heappush(td, (-d, t))

for i in range(K):
    d, t = heapq.heappop(td)
    total -= d
    if t not in group:
        group.add(t)
    else:
        heapq.heappush(td_, -d)

ans = len(group)**2 + total

while td and td_:
    d, t = heapq.heappop(td)

    if t not in group:
        group.add(t)
        d_ = heapq.heappop(td_)
        total = total - d_ - d
        ans = max(ans, len(group)**2 + total)
print(ans)
Buggy python submission (verdict: Runtime Error):
s = np.array(list(map(int, input())))
     
idx = np.array([[i, i+1, i+2] for i in range(len(s)-2)])

total = np.sum(np.abs(s[idx] - [7,5,3])*[100,10,1], axis=1)
        
print(np.min(total))

Fixed submission:
s = input()

min_num = 753

for i in range(len(s)-2):
    num = abs(int(s[i:i+3]) - 753)
    if num < min_num:
        min_num = num
print(min_num)
Buggy python submission (verdict: Runtime Error):
N = int(input())
T, A = list(map(int, input().split()))
H = np.array(list(map(int, input().split())))

num = np.abs(A - (T - H * 0.006))
print(np.argmin(num) + 1)


Fixed submission:
import numpy as np

N = int(input())
T, A = list(map(int, input().split()))
H = np.array(list(map(int, input().split())))

num = np.abs(A - (T - H * 0.006))
print(np.argmin(num) + 1)