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

N = int(input())
X = np.zeros([N,2], dtype=int)

for i in range(N):
    X[i] = list(map(int, input().split()))  
left = X[:,0] - X[:,1]
right = X[:,0] + X[:,1]
lr = np.concatenate([left.reshape(-1,1), right.reshape(-1,1)], 1)

r_min = np.argmin(right)
use = lr[r_min].reshape(-1,2)
while use[-1,1] <= np.max(left):
    lr = lr[np.all(lr >= use[-1,1], axis=1),:]
    r_min = np.argmin(lr[:,1])
    use = np.vstack([use, lr[r_min]])
print(len(use))

Fixed submission:
import numpy as np

N = int(input())
X = np.zeros([N,4], dtype=int)

for i in range(N):
    X[i,0], X[i,1] = map(int, input().split())
    X[i,2], X[i,3] = X[i,0] - X[i,1], X[i,0] + X[i,1]    

col_num = 3
X = X[np.argsort(X[:, col_num])]
cnt = 1
r_min = X[0,3]
for i in range(1,N):
    if X[i,2] >= r_min:
        cnt += 1
        r_min = X[i,3]
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
def prepare(n, MOD):
 
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs


MOD = 10**9 + 7
f, inv = prepare(10**5+1, MOD)

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

a.sort(reverse=True)


cnt = 0
for i in range(n-k+1):
    for j in range(i+k-1, n):
        cd = a[i] - a[j]
        cn = j - i - 1
        ck = k - 2
        if not(cn == 0 and ck > 1):
            combi = f[cn] * inv[ck] % MOD * inv[cn - ck] % MOD
            cnt += cd * combi % MOD
            cnt %= MOD
        
print(cnt)

Fixed submission:
def prepare(n, MOD):
 
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs


MOD = 10**9 + 7
f, inv = prepare(10**5+100, MOD)

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

a.sort(reverse=True)

p = 0
m = 0
for i in range(n):
    if n - i >= k:
        cn = n - i - 1
        ck = k - 1
        if cn >= ck:
            combi = f[cn] * inv[ck] % MOD * inv[cn - ck] % MOD
            if a[i] >= 0:        
                p += (a[i] * combi) % MOD
            else:
                p += (a[i] * combi) % -MOD
            if p >= 0:
                p %= MOD
            else:
                p %= -MOD
    if i >= k - 1:
        cn = i
        ck = k - 1
        if cn >= ck:
            combi = f[cn] * inv[ck] % MOD * inv[cn - ck] % MOD
            if a[i] >= 0:        
                m += (a[i] * combi) % MOD
            else:
                m += (a[i] * combi) % -MOD
            if m >= 0:
                m %= MOD
            else:
                m %= -MOD
        
print((p - m)%MOD)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
t = input()

ans = []
for i in range(n):
    a.append(s[i])
    a.append(t[i])
print(''.join(a))

Fixed submission:
n = int(input())
s, t = input().split()

a = []
for i in range(n):
    a.append(s[i])
    a.append(t[i])
print(''.join(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n % 2 != 0:
    print(0)
    exit()

m = 10
a = []
b = []
while m <= n:
    a.append(n // m)
    m *= 5
    if len(a) > 1:
      b.append(a[-2] - a[-1])
b.append(a[-1])

ans = 0
for i in range(len(b)):
    ans += (i+1)*b[i]
print(ans)

Fixed submission:
n = int(input())
if n % 2 != 0:
    print(0)
    exit()

m = 10
a = []
b = []
while m <= n:
    a.append(n // m)
    m *= 5
    if len(a) > 1:
      b.append(a[-2] - a[-1])
if a:
    b.append(a[-1])

ans = 0
for i in range(len(b)):
    ans += (i+1)*b[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

cnt = 0
for i in range(1000):
    si = str(i).zfill(3)
    k = 0
    for cn in range(n):
        if s[cn] == si[k]:
            if k == 2:
                cnt += 1
                break
            else:
                k += 1
print(cnt)


Fixed submission:
n = int(input())
s = input()

cnt = 0
for i in range(1000):
    si = str(i).zfill(3)
    k = 0
    for cn in range(n):
        if s[cn] == si[k]:
            if k == 2:
                cnt += 1
                break
            else:
                k += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
if d[0] != 0:
    print(0)
    exit()

else:
    cnt = Counter(d)

ans = 1
for i in range(1 n):
    ans *= pow(cnt[i-1], cnt[i], MOD) % MOD

if cnt[0] != 1:
    ans = 0
max_c = max(cnt)
for i in range(max_c + 1):
    if i not in cnt:
        ans = 0
print(ans)


Fixed submission:
from collections import Counter


def solve(n, ddd):
    if ddd[0] != 0:
        return 0
    cnt = Counter(ddd)
    if cnt[0] != 1:
        return 0
    max_c = max(cnt)
    for i in range(max_c + 1):
        if i not in cnt:
            return 0

    MOD = 998244353
    ans = 1
    for i in range(max_c):
        prev = cnt[i]
        curr = cnt[i + 1]
        ans = ans * pow(prev, curr, MOD) % MOD
    return ans


n = int(input())
ddd = list(map(int, input().split()))

print(solve(n, ddd))

Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
d.sort()
if d[0] != 0 or d[1] == 0:
    ans = 0
else:
    cnt = [0]*n
    for i in range(1, n):
        cnt[d[i]] += 1

ans = 1
for i in range(2, n):
    ans *= cnt[i-1]**cnt[i]
print(ans)

Fixed submission:
from collections import Counter


def solve(n, ddd):
    if ddd[0] != 0:
        return 0
    cnt = Counter(ddd)
    if cnt[0] != 1:
        return 0
    max_c = max(cnt)
    for i in range(max_c + 1):
        if i not in cnt:
            return 0

    MOD = 998244353
    ans = 1
    for i in range(max_c):
        prev = cnt[i]
        curr = cnt[i + 1]
        ans = ans * pow(prev, curr, MOD) % MOD
    return ans


n = int(input())
ddd = list(map(int, input().split()))

print(solve(n, ddd))
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input().split())
print(max(0, a-2b))

Fixed submission:
a, b = map(int,input().split())
print(max(0, a-2*b))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        if j == n-1:
            continue
        x = l[i] + l[j]
        cnt += bisect.bisect_left(l[j+1:], x)
print(cnt)


Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        if j == n-1:
            continue
        x = l[i] + l[j]
        cnt += bisect.bisect_left(l[j+1:], x)
print(cnt)
Buggy python submission (verdict: Runtime Error):
import numpy as np

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

  
a, b = map(int,input().split())
ad = make_divisors(a)
bd = make_divisors(b)
ab = list(set(ad) & set(bd))
ab.sort()
# print(ab)

prime = [1]
is_p = np.array([True]*(ab[-1]+1))
is_p[0] = False
for i in range(2, ab[-1]+1):
    if is_p[i]:
        prime.append(i)
        is_p[i::i] = False
# print(prime)

ans = list(set(ab) & set(prime))
print(len(ans))

Fixed submission:
# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

  
a, b = map(int,input().split())
aa = prime_factorize(a)
bb = prime_factorize(b)
ab = list(set(aa) & set(bb))
ab.sort()
print(len(ab)+1)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import numba
from numba import jit, njit

@njit
def solve(dp, sn):
    for i in range(n-2, -1, -1):
        for j in range(n-1, i,-1):
            if i + dp[i+1][j+1] >= j:
                break
            if s[i] == s[j]:
                dp[i][j] = dp[i+1][j+1] + 1
    return dp.max()

n = int(input())
s = input() + '_'
sn = np.zeros(n+1, dtype=int)
for i in range(n+1):
    sn[i] = ord(s[i])

dp = np.zeros((n+1,n+1), dtype=int)

print(solve(dp, sn))

Fixed submission:
n = int(input())
s = input() + '_'
    
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n-2, -1, -1):
    for j in range(n-1, i,-1):
        if i + dp[i+1][j+1] >= j:
            break
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
print(max(list(map(lambda x: max(x), dp))))

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

n = int(input())
s = input() + '_'
    
dp = np.zeros((n+1,n+1),dtype=int)
for i in range(n-2, -1, -1):
    for j in range(n-1, i,-1):
        if i + dp[i+1][j+1] >= j:
            break
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
print(dp.max())

Fixed submission:
n = int(input())
s = input() + '_'
    
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n-2, -1, -1):
    for j in range(n-1, i,-1):
        if i + dp[i+1][j+1] >= j:
            break
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
print(max(list(map(lambda x: max(x), dp))))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input() + '_'
    
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n-2, -1, -1):
    for j in range(n-1, i,-1):
        if i + dp[i+1][j+1] >= j:
            break
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
print(max(list(map(lambda x: max(x), dp))))

Fixed submission:
n = int(input())
s = input() + '_'
    
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n-2, -1, -1):
    for j in range(n-1, i,-1):
        if i + dp[i+1][j+1] >= j:
            break
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
print(max(list(map(lambda x: max(x), dp))))
Buggy python submission (verdict: Time Limit Exceeded):
import copy

s = input()
t = input()

a = [[] for i in range(26)]
for i in range(len(s)):
    num = ord(s[i]) - 97
    a[num].append(i)

flg = True
cnt = 0
x = -1
for i in range(len(t)):
    num = ord(t[i]) - 97
    if not a[num]:
        flg = False
        break
    for j in range(len(a[num])):
        if x < a[num][j]:
            x = copy.deepcopy(a[num][j])
            break
        if j == len(a[num])-1:
            cnt += 1
            x = copy.deepcopy(a[num][0])
            break
print(cnt*len(s) + x+1) if flg else print(-1)

Fixed submission:
import copy

s = input()
t = input()

sn = len(s)
tn = len(t)
a = [[] for i in range(26)]
for i in range(sn):
    num = ord(s[i]) - 97
    a[num].append(i)

table = [[0]*sn for i in range(26)]
for i in range(26):
    if a[i]:
        table[i][:] = [copy.deepcopy(a[i][0])]*sn
    f = 0
    for j in a[i]:
        table[i][f:j] = [copy.deepcopy(j)]*(j-f)
        f = copy.deepcopy(j)

flg = True
cnt = 0 # 今何週したか
x = -1 # 今何文字目か
for i in range(tn):
    num = ord(t[i]) - 97
    # sの中に対象の文字が存在しない
    if not a[num]:
        flg = False
        break
    # sの中に対象の文字が存在
    xx = copy.deepcopy(x)
    x = table[num][x]
    if xx >= x:
        cnt += 1
print(cnt*sn + x+1) if flg else print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)

a = [0]*n
ans = [0]*n

for i in range(n):
    x = 0
    if s[i] == 'R':
        while s[i+x] == 'R':
            x += 1
    if s[i] == 'L':
        while s[i+x] == 'L':
            x -= 1
    a[i] = x

    if a[i] == 1 or a[i] == -1:
        ans[i] += 1
    elif a[i] % 2 == 0:
        ans[i+ a[i]] += 1
    elif a[i] > 0:
        ans[i+ a[i] - 1] += 1
    elif a[i] < 0:
        ans[i+ a[i] + 1] += 1
        
ans = [str(i) for i in ans]
print(' '.join(ans))

Fixed submission:
s = input()
n = len(s)

a = [0]*n
ans = [0]*n

for i in range(n):
    x = 0
    if s[i] == 'R':
        if i > 0 and a[i-1] > 0:
            x = a[i-1] - 1
        else:
            while s[i+x] == 'R':
                x += 1
    if s[i] == 'L':
        if i > 0 and a[i-1] < 0:
            x = a[i-1] - 1
        else:
            while s[i+x] == 'L':
                x -= 1
    a[i] = x

    if a[i] == 1 or a[i] == -1:
        ans[i] += 1
    elif a[i] % 2 == 0:
        ans[i+ a[i]] += 1
    elif a[i] > 0:
        ans[i+ a[i] - 1] += 1
    elif a[i] < 0:
        ans[i+ a[i] + 1] += 1
        
ans = [str(i) for i in ans]
print(' '.join(ans))
Buggy python submission (verdict: Runtime Error):
import numpy as np

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

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

asum = sum(a)
adiv = make_divisors(asum)
adiv.reverse()

a = np.array(a)
flg = False
for i in adiv:
    a_ = np.sort(a % i)
    # print(i, a_)
    msum = a_.sum()
    msum_ = 0
    for j in range(-1, -n-1, -1):
        msum -= a_[j]
        msum_ += i - a_[j]
        if msum > k:
            break
        if msum < msum_:
            break
        if msum == msum_ :
            ans = i
            flg = True
            break
    if flg:
        break

print(ans)

Fixed submission:
import numpy as np

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

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

asum = sum(a)
adiv = make_divisors(asum)
adiv.reverse()

a = np.array(a)
ans = 1
flg = False
for i in adiv:
    a_ = np.sort(a % i)
    # print(i, a_)
    msum = a_.sum()
    msum_ = 0
    for j in range(-1, -n-1, -1):
        msum -= a_[j]
        msum_ += i - a_[j]
        if msum_ > k:
            break
        if msum < msum_:
            break
        if msum == msum_ :
            ans = i
            flg = True
            break
    if flg:
        break

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

n = int(input())
r = np.array(list(map(int,input().split())))

pm = np.array([1,-1] * (n//2) + [1])


d = []
for i in range(n):
    tmp = r * pm
    d.append(str(sum(tmp)))
    r0 = r[0]
    r = r[1:]
    r = np.append(r, r0)

print(' '.join(d))

Fixed submission:
import numpy as np


n = int(input())
r = np.array(list(map(int,input().split())))

pm = np.array([1,-1] * (n//2) + [1])


d = []
tmp = sum(r * pm)
d.append(str(tmp))
tmp -= r[0]

for i in range(n-1):
    tmp = r[i] - tmp
    d.append(str(tmp))
    tmp -= r[i+1]

print(' '.join(d))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix


def bfs(cnt, p, cn, row, col, data):
    cnt += 1
    if cnt < 3:
        for cg in graph[p]:
            d.appendleft([cnt, cg])
    if cnt == 3:
        for cg in graph[p]:
            if not cg in graph_k[cn]:
                graph_k[cn].append(cg)
                row = np.append(row, cn)
                col = np.append(col, cg)
                data = np.append(data, 1)
    return cnt, row, col, data

n, m = map(int,input().split())
edge = []
graph = [[] for i in range(n+1)]
for i in range(m):
    edge.append(list(map(int,input().split())))
    graph[edge[-1][0]].append(edge[-1][1])
s, g = map(int,input().split())

row = np.array([], dtype=int)
col = np.array([], dtype=int)
data = np.array([], dtype=int)

d = deque()
graph_k = [[] for i in range(n+1)]
for cn in range(1, n+1):
    for cg in graph[cn]:
        d.appendleft([1, cg])
    while d:
        cnt, p = d.pop()
        cnt, row, col, data = bfs(cnt, p, cn, row, col, data)
# print(graph_k)
csr = csr_matrix((data, (row, col)), shape=(n+1, n+1))
ans = shortest_path(csr, indices=s)
if np.isinf(ans[g]):
    print(-1)
else:
    print(int(ans[g]))

Fixed submission:
import copy

n, m = map(int,input().split())
edge = []
graph = [[] for i in range(n+1)]
for i in range(m):
    edge.append(list(map(int,input().split())))
    graph[edge[-1][0]].append(edge[-1][1])
s, g = map(int,input().split())

INF = 10**18
ans = [[INF, INF, INF] for i in range(n+1)]
q = [s]
d = 0
while q:
    nq = []
    d += 1
    p = d % 3
    for cf in q:
        for ct in graph[cf]:
            if ans[ct][p] == INF:
                ans[ct][p] = d
                nq.append(ct)
    q = copy.deepcopy(nq)
if ans[g][0] == INF:
    print(-1)
else:
    print(ans[g][0]//3)
Buggy python submission (verdict: Runtime Error):
n, x = map(int,input().split())
l = list(map(int,input().split()))

cnt = 0
now = 0
while now <= x:
    cnt += 1
    now += l.pop(0)
print(cnt)

Fixed submission:
n, x = map(int,input().split())
l = list(map(int,input().split()))

cnt = 1
now = 0
flg = True
while l:
    now += l.pop(0)
    if now <= x:
        cnt += 1
    else:
      break
print(cnt)
Buggy python submission (verdict: Runtime Error):
n, m  = map(int,input().split())
a = [int(input()) for _ in range(m)]

MOD = 10**9+7

dp = [0]*(n+1)
ng = [False]*(n+1)
for i in a:
    ng[a] = True
    
dp[0] = 1
if not ng[1]:
    dp[1] = 1
for i in range(2, n+1):
    if a[i]:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[n])

Fixed submission:
n, m  = map(int,input().split())
a = [int(input()) for _ in range(m)]

MOD = 10**9+7

dp = [0]*(n+1)
ng = [False]*(n+1)
for i in a:
    ng[i] = True
    
dp[0] = 1
if not ng[1]:
    dp[1] = 1
for i in range(2, n+1):
    if ng[i]:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[n])

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


MOD = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
if not 1 in a:
    dp[1] = 1
for i in range(2, n+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[n])


Fixed submission:
n, m  = map(int,input().split())
a = [int(input()) for _ in range(m)]

MOD = 10**9+7

dp = [0]*(n+1)
ng = [False]*(n+1)
for i in a:
    ng[i] = True
    
dp[0] = 1
if not ng[1]:
    dp[1] = 1
for i in range(2, n+1):
    if ng[i]:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[n])

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


MOD = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
if not 1 in a:
    dp[1] = 1
for i in range(2, n+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[n])

Fixed submission:
n, m  = map(int,input().split())
a = [int(input()) for _ in range(m)]

MOD = 10**9+7

dp = [0]*(n+1)
ng = [False]*(n+1)
for i in a:
    ng[i] = True
    
dp[0] = 1
if not ng[1]:
    dp[1] = 1
for i in range(2, n+1):
    if ng[i]:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

change = []
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
for i in range(m):
    b, c = map(int, input().split())
    change.append([c, b])

heapq.heapify(change)
heapq.heapify(a)

while change:
    b, c = heapq.heappop(change)
    while a[0] < b and c > 0:
        tmp = heapq.heappop(a)
        heapq.heappush(a, b)
        c -= 1
        
print(sum(a))


Fixed submission:
import heapq


change = []
n, m = map(int, input().split())
a = [-1 * int(i) for i in input().split()]
for i in range(m):
    b, c = map(int, input().split())
    change.append([-c, b])

l = []
heapq.heapify(change)
heapq.heapify(a)
flg = False
cnt = 0
while cnt < n:
    if change:
        atmp = -1 * a[0]
        btmp = -1 * change[0][0]
        if atmp <= btmp:
            b, c = heapq.heappop(change)
            while c > 0 and cnt < n:
                l.append(b)
                c -= 1
                cnt += 1
        else:
            aa = heapq.heappop(a)
            l.append(aa)
            cnt += 1
    else:
        aa = heapq.heappop(a)
        l.append(aa)
        cnt += 1
        
print(-1 * sum(l))

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

change = []
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
for i in range(m):
    b, c = map(int, input().split())
    change.append([c, b])

heapq.heapify(change)
heapq.heapify(a)

while change:
    b, c = heapq.heappop(change)
    while a[0] < b and c > 0:
        tmp = heapq.heappop(a)
        heapq.heappush(a, b)
        c -= 1
        
print(sum(a))

Fixed submission:
import heapq


change = []
n, m = map(int, input().split())
a = [-1 * int(i) for i in input().split()]
for i in range(m):
    b, c = map(int, input().split())
    change.append([-c, b])

l = []
heapq.heapify(change)
heapq.heapify(a)
flg = False
cnt = 0
while cnt < n:
    if change:
        atmp = -1 * a[0]
        btmp = -1 * change[0][0]
        if atmp <= btmp:
            b, c = heapq.heappop(change)
            while c > 0 and cnt < n:
                l.append(b)
                c -= 1
                cnt += 1
        else:
            aa = heapq.heappop(a)
            l.append(aa)
            cnt += 1
    else:
        aa = heapq.heappop(a)
        l.append(aa)
        cnt += 1
        
print(-1 * sum(l))
Buggy python submission (verdict: Runtime Error):
import numpy as np
import copy

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

if len(a) == 2:
    ans = max(a)
else:
    ans = 1
    a.sort()
    m = a[1]
    check = np.array([-1]*(m+1))
    
    for i in range(2, m+1):
        if check[i] == 0:
            continue
        cnt = 0
        for j in range(n):
            if a[j] % i > 0:
                cnt += 1
            if cnt >= 2:
                check[i::i] = 0
                break
            if j == n-1:
                ans = copy.deepcopy(i)

print(ans)

Fixed submission:
import math

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

ar = a[::-1]
l = [0]
r = []

tmp1 = 0
tmp2 = 0
for i in range(n-1):
    tmp1 = math.gcd(tmp1, a[i])
    l.append(tmp1)
    tmp2 = math.gcd(tmp2, ar[i])
    r.append(tmp2)

r.reverse()
r.append(0)
ans = 1
for i in range(n):
    ans = max(ans, math.gcd(l[i], r[i]))
print(ans)

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

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

if len(a) == 2:
    ans = max(a)
else:
    a.sort()
    m = a[1]
    check = np.array([-1]*(m+1))
    
    for i in range(2, m+1):
        if check[i] == 0:
            continue
        cnt = 0
        for j in range(n):
            if a[j] % i > 0:
                cnt += 1
            if cnt >= 2:
                check[i::i] = 0
                break
            if j == n-1:
                ans = copy.deepcopy(i)

print(ans)

Fixed submission:
import math

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

ar = a[::-1]
l = [0]
r = []

tmp1 = 0
tmp2 = 0
for i in range(n-1):
    tmp1 = math.gcd(tmp1, a[i])
    l.append(tmp1)
    tmp2 = math.gcd(tmp2, ar[i])
    r.append(tmp2)

r.reverse()
r.append(0)
ans = 1
for i in range(n):
    ans = max(ans, math.gcd(l[i], r[i]))
print(ans)