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

n = int(input())
x = list(map(int, input().split()))
num = 0

from heapq import heappush
from heapq import heappop

def linked_heap_sort(lst):
    heap = []
    while lst:
        heappush(heap, lst.pop())
    while heap:
        lst.append(heappop(heap))
    return lst

y = copy.copy(x)
x = linked_heap_sort(x)

for i in range(n):
  num = x.index(y[i])
  if num >= n/2:
    print(x[int(n/2)-1])
  else:
    print(x[int(n/2)])



Fixed submission:
import copy

n = int(input())
x = list(map(int, input().split()))
num = 0

y = copy.copy(x)
x.sort()
num1 = x[n//2-1]
num2 = x[n//2]

for i in y:
  if i <= num1:
    print(num2)
  else:
    print(num1)

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

n = int(input())
x = list(map(int, input().split()))
num = 0

y = copy.copy(x)
x.sort()

for i in range(n):
  num = x.index(y[i])
  if num >= n/2:
    print(x[int(n/2)-1])
  else:
    print(x[int(n/2)])

Fixed submission:
import copy

n = int(input())
x = list(map(int, input().split()))
num = 0

y = copy.copy(x)
x.sort()
num1 = x[n//2-1]
num2 = x[n//2]

for i in y:
  if i <= num1:
    print(num2)
  else:
    print(num1)

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

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

"""
def median_cal(data):
    num = len(data)
    # データを昇順ソート
    data.sort()
    # データ数が偶数の場合
    median = int((num + 1) / 2 - 1)
    median = data[median]
    return median"""
  
for i in range(n):
  list1 = copy.copy(x)
  list1.pop(i)
  list1 = np.array(list1)
  median = np.median(list1)
  print(int(median))

Fixed submission:
import copy

n = int(input())
x = list(map(int, input().split()))
num = 0

y = copy.copy(x)
x.sort()
num1 = x[n//2-1]
num2 = x[n//2]

for i in y:
  if i <= num1:
    print(num2)
  else:
    print(num1)

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

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

def median_cal(data):
    num = len(data)
    # データを昇順ソート
    data.sort()
    # データ数が偶数の場合
    median = int((num + 1) / 2 - 1)
    median = data[median]
    return median
  
for i in range(n):
  list1 = copy.copy(x)
  list1.pop(i)
  print(median_cal(list1))

Fixed submission:
import copy

n = int(input())
x = list(map(int, input().split()))
num = 0

y = copy.copy(x)
x.sort()
num1 = x[n//2-1]
num2 = x[n//2]

for i in y:
  if i <= num1:
    print(num2)
  else:
    print(num1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = 0
B = 0
num = 0
ans = 10**10

for i in range(1, N+1):
  if N%i == 0:
    A = len(str(i))
    B = len(str(N//i))
    num = max(A, B)
    ans = min(ans, num)
print(ans)

Fixed submission:
N = int(input())
A = 0
B = 0
num = 0
ans = 10**10

for i in range(1, int((N)**(1/2)+1)):
  if N%i == 0:
    A = len(str(i))
    B = len(str(N//i))
    num = max(A, B)
    ans = min(ans, num)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
m = 1000000007
S = 0
for i in range(n):
    for j in range(i+1, n, 1):
        S += a[i] * a[j] % m
print(S % m)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
m = 1000000007
S = 0
Q = sum(a)
for i in range(n):
    Q -= a[i]
    S += a[i] * Q % m
print(S % m)
Buggy python submission (verdict: Runtime Error):
A = input().split()
B = input().split()
if A[0] == B[2] and A[1] == B[1] and A[2] == B[0]:
    print('YES')
else:
    print('NO')

Fixed submission:
A = list(input())
B = list(input())
if A[0] == B[2] and A[1] == B[1] and A[2] == B[0]:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
# N = 10**6
# A = [10**6-i for i in range(N)]

def is_pairwise_coprime():
    l = [0]*(10**6+1)
    for a in A:
        for j in range(2, int(a**(1/2))+2):
            if a % j == 0:
                if l[j]:
                    return False
                l[j] = 1
            while a % j == 0:
                a //= j
        if a != 1:
            if l[a]:
                return False
            l[a] = 1
    return True

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(a, b%a)

def is_setwise_coprime():
    A_gcd = A[0]
    for a in A[1:]:
        A_gcd = gcd(A_gcd, a)
        if A_gcd == 1:
            break
    return (A_gcd == 1)

if is_pairwise_coprime():
    print("pairwise coprime")
elif is_setwise_coprime():
    print("setwise coprime")
else:
    print("not coprime")

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
# N = 10**6
# A = [10**6-i for i in range(N)]

def is_pairwise_coprime():
    l = [0]*(10**6+1)
    for a in A:
        for j in range(2, int(a**(1/2))+2):
            if a % j == 0:
                if l[j]:
                    return False
                l[j] = 1
            while a % j == 0:
                a //= j
        if a != 1:
            if l[a]:
                return False
            l[a] = 1
    return True

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(a, b%a)

def is_setwise_coprime():
    A_gcd = A[0]
    for a in A[1:]:
        A_gcd = gcd(A_gcd, a)
        if A_gcd == 1:
            break
    return (A_gcd == 1)

if is_pairwise_coprime():
    print("pairwise coprime")
elif is_setwise_coprime():
    print("setwise coprime")
else:
    print("not coprime")
Buggy python submission (verdict: Time Limit Exceeded):
OK = 0
NG = 5000000000

mid = (OK+NG) // 2

s = 0
for i in range(mid):
    s += i

X = int(input())

print("Yes" if X >= 30 else "No")

Fixed submission:
X = int(input())

print("Yes" if 30 <= X else "No")
Buggy python submission (verdict: Runtime Error):
N, D = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range()]

print(sum(x**2 + y**2 <= D**2 for x, y in XY))

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

print(sum(x**2 + y**2 <= D**2 for x, y in XY))
Buggy python submission (verdict: Runtime Error):
A = input()

print(A+A**2+A**3)

Fixed submission:
A = int(input())

print(A+A**2+A**3)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

print(sum(s != t for s, t zip(S, T)))

Fixed submission:
S = input()
T = input()

print(sum(s != t for s, t in zip(S, T)))
Buggy python submission (verdict: Runtime Error):
A, B = input().split()
A = int(input())
B = int(B.replace(".". ""))

print(A*B//100)

Fixed submission:
A, B = input().split()
A = int(A)
B = int(B.replace(".", ""))

print(A*B//100)
Buggy python submission (verdict: Runtime Error):
K = int(input())
A, B = map(int, input().split())

for i in range(!, B+1):
    if i%K == 0:
        print("OK")
        exit()
print("NG")

Fixed submission:
K = int(input())
A, B = map(int, input().split())

for i in range(A, B+1):
    if i%K == 0:
        print("OK")
        exit()
print("NG")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

S = input()
N = len(S)

l = [0]*(N+1)
for i in range(N-1, -1, -1):
    l[i] = (l[i+1] + 10**(N-i) * int(S[i])) % 2019

r = sum(m*(m-1)//2 for m in Counter(l).values())
print(r)

Fixed submission:
from collections import Counter

S = input()
# S = "12345"*40000
N = len(S)

l = [0]*(N+1)
for i in range(N-1, -1, -1):
    l[i] = (l[i+1] + pow(10, N-i, 2019) * int(S[i])) % 2019
    # if i%10000 == 0:
    #     print(i)

# print(list(Counter(l).values()))

r = sum(m*(m-1)//2 for m in Counter(l).values())
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

S = input()
N = len(S)

l = [0]*(N+1)
for i in range(N-1, -1, -1):
    l[i] = (l[i+1] + 10**(N-i) * int(S[i])) % 2019

r = sum(m*(m-1)//2 for m in Counter(l).values())
print(r)

Fixed submission:
from collections import Counter

S = input()
# S = "12345"*40000
N = len(S)

l = [0]*(N+1)
for i in range(N-1, -1, -1):
    l[i] = (l[i+1] + pow(10, N-i, 2019) * int(S[i])) % 2019
    # if i%10000 == 0:
    #     print(i)

# print(list(Counter(l).values()))

r = sum(m*(m-1)//2 for m in Counter(l).values())
print(r)
Buggy python submission (verdict: Runtime Error):
R = int(input())

print(2*R*3.1415926535897)

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

x = N-(sum(A))

print(-1 if x < 0 else x)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

a, b, c = Counter(S).values()
r = a*b*c

for i in range(N):
    for j in range(i+1, N):
        k = 2*j-i
        # print(i, j, k)
        if k < N and len({S[i], S[j], S[k]}) == 3:
            r -= 1

print(r)

Fixed submission:
from collections import Counter

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

counter = Counter(S)

r = 1
for c in "RGB":
    r *= counter[c]


for i in range(N):
    for j in range(i+1, N):
        k = 2*j-i
        # print(i, j, k)
        if k < N and len({S[i], S[j], S[k]}) == 3:
            r -= 1

print(r)
Buggy python submission (verdict: Runtime Error):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

l = [[(a_i in B) for a_i in a] for a in A]

# print(l)

flag = 0
for y in range(3):
    flag |= all(l[y])

for x in range(3):
    flag |= all([l[x][y] for y in range(3)])

flag |= all([l[y][x] for x, y in [(0, 0), (1, 1), (2, 2)]])

flag |= all([l[y][x] for x, y in [(0, 2), (1, 1), (2, 0)]])

print("Yes" if flag else "No")

Fixed submission:
N = int(input())

print(-(-N//2))
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input())

print(min(int(str(A)*B), int(str(B)*A)))

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

print(min(str(A)*B, str(B)*A))
Buggy python submission (verdict: Time Limit Exceeded):
# from random import randint

MOD = 10**9+7

N = int(input())
A = list(map(int, input().split()))
# N = 10000
# A = [randint(1, 10**6) for _ in range(N)]

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(b%a, a)
def lcm(a, b):
    return (a * b) // gcd(a, b)

a_lcm = A[0]
for a_i in A[1:]:
    a_lcm = lcm(a_lcm, a_i)

sum_num = 0
for a_i in A:
    sum_num = (sum_num + (a_lcm//a_i)) % MOD

print(sum_num)

Fixed submission:
# from random import randint

MOD = 10**9+7

N = int(input())
A = list(map(int, input().split()))
# N = 10000
# A = [randint(1, 10**6) for _ in range(N)]

def modinv(a):
    return pow(a, MOD-2, MOD)

# a = 12345678900000
# b = 100000
# a %= MOD
# print(a * modinv(b) % MOD)

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(b%a, a)
def lcm(a, b):
    return (a * b) // gcd(a, b)

a_lcm = A[0]
for a_i in A[1:]:
    a_lcm = lcm(a_lcm, a_i)
a_lcm %= MOD

sum_num = 0
for a_i in A:
    sum_num = (sum_num + (a_lcm * modinv(a_i))) % MOD

print(sum_num)

Buggy python submission (verdict: Time Limit Exceeded):
# from random import randint

MOD = 10**9+7

N = int(input())
A = list(map(int, input().split()))
# N = 10000
# A = [randint(1, 10**6) for _ in range(N)]

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(b%a, a)
def lcm(a, b):
    return (a * b) // gcd(a, b)

a_lcm = A[0]
for a_i in A[1:]:
    a_lcm = lcm(a_lcm, a_i)

sum_num = 0
for a_i in A:
    sum_num = (sum_num + (a_lcm//a_i)) % MOD

print(sum_num)

Fixed submission:
# from random import randint

MOD = 10**9+7

N = int(input())
A = list(map(int, input().split()))
# N = 10000
# A = [randint(1, 10**6) for _ in range(N)]

def modinv(a):
    return pow(a, MOD-2, MOD)

# a = 12345678900000
# b = 100000
# a %= MOD
# print(a * modinv(b) % MOD)

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(b%a, a)
def lcm(a, b):
    return (a * b) // gcd(a, b)

a_lcm = A[0]
for a_i in A[1:]:
    a_lcm = lcm(a_lcm, a_i)
a_lcm %= MOD

sum_num = 0
for a_i in A:
    sum_num = (sum_num + (a_lcm * modinv(a_i))) % MOD

print(sum_num)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

print(6-A-B)

Fixed submission:
A = int(input())
B = int(input())

print(6-A-B)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

MOD = 10**9+7

sum_num = 0
for i in range(60):
    o = 0
    for a in A:
        o += (a>>i)%2
    z = N - o
    sum_num = (sum_num + (o*z)*(1<<i)) % MOD

print(sum_num)

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

print("bust" if sum(A) >= 22 else "win")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

MOD = 10**9+7

sum_num = 0
for i in range(60):
    o = 0
    for a in A:
        o += (a>>i)%2
    z = N - o
    sum_num = (sum_num + (o*z)*(1<<i)) % MOD

print(sum_num)

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

MOD = 10**9+7

sum_num = 0
for i in range(60):
    o = 0
    for a in A:
        o += (a>>i)%2
    z = N - o
    sum_num = (sum_num + (o*z)*(1<<i)) % MOD

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

c = 0
for i in range(1000):
    num_str = "{0:0>3}".format(i)
    j = 0
    for s in S:
        if num_str[j] == s:
            j += 1
        if j == 3:
            c += 1
            break

print(c)

Fixed submission:
N = int(input())
S = input()
 
c = 0
for i in range(1000):
    num_str = "{0:0>3}".format(i)
    j = 0
    for s in S:
        if num_str[j] == s:
            j += 1
        if j == 3:
            c += 1
            break
 
print(c)
Buggy python submission (verdict: Runtime Error):
X, Y = map(int, input().split())

points = [-1, 100000, 200000, 300000, 0]
print(400000*(X==Y==1) + points[max(4, X)] + points[max(4, Y)])

Fixed submission:
X, Y = map(int, input().split())

points = [-1, 300000, 200000, 100000, 0]
print(400000*(X==Y==1) + points[min(4, X)] + points[min(4, Y)])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
AB_C = [[list(map(int, input().split())) for _ in range(2)] for _ in range(M)]

keys = []
for i, ((a, b), c) in enumerate(AB_C):
    key_flag = 0
    for c_i in c:
        key_flag |= 1<<(c_i-1)
    keys.append((a, key_flag))

dp = [[10**18 for _ in range(1<<N)] for _ in range(M+1)]
dp[0][0] = 0

for i, (price, flag) in enumerate(keys):
    for j in range(1<<N):
        dp[i+1][j] = min(
            dp[i+1][j],
            dp[i][j]
        )
        dp[i+1][j|flag] = min(
            dp[i+1][j|flag],
            dp[i+1][j] + price
        )

r = dp[M][(1<<N)-1]
print(-1 if r == 10**18 else r)

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

keys = []
for i, ((a, b), c) in enumerate(AB_C):
    key_flag = 0
    for c_i in c:
        key_flag |= 1<<(c_i-1)
    keys.append((a, key_flag))

dp = [[10**18 for _ in range(1<<N)] for _ in range(M+1)]
dp[0][0] = 0

for i, (price, flag) in enumerate(keys):
    for j in range(1<<N):
        dp[i+1][j] = min(
            dp[i+1][j],
            dp[i][j]
        )
        dp[i+1][j|flag] = min(
            dp[i+1][j|flag],
            dp[i+1][j] + price
        )

r = dp[M][(1<<N)-1]
print(-1 if r == 10**18 else r)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import groupby

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

t = S[1:]
c = 0
for i in range(1, N):
    # print(S, t, i)
    for k, g in groupby([a == b for a, b in zip(S, t)]):
        if k == False:
            continue
        x = len(tuple(g))
        c = max(c, min(i, x))
    t = t[1:]
# print(S, t)
print(c)


Fixed submission:
N = int(input())
S = [ord(s) for s in input()]
# N = 5000
# S = "abcdefg" + "k"*4993

c = 0
for i in range(1, N):
    d = 0
    for s_j, t_j in zip(S, S[i:]):
        if s_j == t_j:
            d += 1
        else:
            c = max(c, min(d, i))
            d = 0
    c = max(c, min(d, i))

# print(S, t)
print(c)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input.split())

print(max(0, C-(A-B)))





Fixed submission:
A, B, C = map(int, input().split())

print(max(0, C-(A-B)))
Buggy python submission (verdict: Runtime Error):
N, D = int(input())

print(-(-N//(2*D+1)))

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

print(-(-N//(2*D+1)))
Buggy python submission (verdict: Runtime Error):
from math import factorial

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

l = [None]*2010
l[0] = 1
for i in range(1, N+1):
    l[i] = l[i-1]*i

for i in range(1, K+1):
    a = l[N-K+1] // l[i] // l[(N-K+1)-i]
    b = l[K-1] // l[i-1] // l[(K-1)-(i-1)]
    print(a*b % (10**9+7))
    

Fixed submission:
from math import factorial

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

l = [None]*2010
l[0] = 1
for i in range(1, 2010):
    l[i] = l[i-1]*i

for i in range(1, K+1):
    a = l[N-K+1] // l[i] // l[(N-K+1)-i]
    b = l[K-1] // l[i-1] // l[(K-1)-(i-1)]
    print(a*b % (10**9+7))
Buggy python submission (verdict: Runtime Error):
N = int(input())
XY = [list(map(int, input().split(" "))) for _ in range(N)]

d = dict()
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x1, y1 = XY[i]
        x2, y2 = XY[j]
        x3, y3 = x2-x1, y2-y1
        if x3 < 0:
            x3, y3 = -1*x3, -1*y3
        pos = (x3, y3)
        if pos not in d:
            d[pos] = 0
        d[pos] += 1

# print(d[max(d, key=lambda x: d[x])])
print(N - max(d.values())//2)

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

d = {(-1, -1): 0}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x1, y1 = XY[i]
        x2, y2 = XY[j]
        x3, y3 = x2-x1, y2-y1
        if x3 < 0 or (x3 == 0 and y3 < 0):
            x3, y3 = -1*x3, -1*y3
        pos = (x3, y3)
        if pos not in d:
            d[pos] = 0
        d[pos] += 1

# print(d.values(), d, max(d.values()))
print(N - max(d.values())//2)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split(" "))
S = [input() for _ in range(H)]

l, r, d, u = [[[0 for _ in range(W)] for _ in range(H)] for _ in range(4)]

for y in range(H):
    for x in range(W):
        if S[y][x] == "#":
            l[y][x] = -1
        elif x == 0:
            l[y][x] = 0
        else:
            l[y][x] = l[y][x-1] + 1
for y in range(H):
    for x in range(W-1, -1, -1):
        if S[y][x] == "#":
            r[y][x] = -1
        elif x == W-1:
            r[y][x] = 0
        else:
            r[y][x] = r[y][x+1] + 1
for x in range(W):
    for y in range(H):
        if S[y][x] == "#":
            u[y][x] = -1
        elif y == 0:
            u[y][x] = 0
        else:
            u[y][x] = u[y-1][x] + 1
for x in range(W):
    for y in range(H-1, -1, -1):
        if S[y][x] == "#":
            d[y][x] = -1
        elif y == H-1:
            d[y][x] = 0
        else:
            d[y][x] = d[y+1][x] + 1

max_num = 0
for y in range(H):
    for x in range(W):
        m = l[y][x] + r[y][x] + u[y][x] + d[y][x] + 1
        # if m > max_num:
        #     print(x, y, l[y][x], r[y][x], u[y][x], d[y][x], m)
        max_num = max(max_num, m)

print(max_num)

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

l, r, d, u = [[[0 for _ in range(W)] for _ in range(H)] for _ in range(4)]

for y in range(H):
    for x in range(W):
        if S[y][x] == "#":
            l[y][x] = -1
        elif x == 0:
            l[y][x] = 0
        else:
            l[y][x] = l[y][x-1] + 1
for y in range(H):
    for x in range(W-1, -1, -1):
        if S[y][x] == "#":
            r[y][x] = -1
        elif x == W-1:
            r[y][x] = 0
        else:
            r[y][x] = r[y][x+1] + 1
for x in range(W):
    for y in range(H):
        if S[y][x] == "#":
            u[y][x] = -1
        elif y == 0:
            u[y][x] = 0
        else:
            u[y][x] = u[y-1][x] + 1
for x in range(W):
    for y in range(H-1, -1, -1):
        if S[y][x] == "#":
            d[y][x] = -1
        elif y == H-1:
            d[y][x] = 0
        else:
            d[y][x] = d[y+1][x] + 1

max_num = 0
for y in range(H):
    for x in range(W):
        m = l[y][x] + r[y][x] + u[y][x] + d[y][x] + 1
        # if m > max_num:
        #     print(x, y, l[y][x], r[y][x], u[y][x], d[y][x], m)
        max_num = max(max_num, m)

print(max_num)
Buggy python submission (verdict: Time Limit Exceeded):
OK = 0
NG = 10**10

mid = (OK+NG) // 2

s = 0
for i in range(mid):
    s += i

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

print((A*3+P)//2)

Fixed submission:
A, P = map(int, input().split(" "))

print((A*3+P)//2)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
BC = [list(map(int, input().split(" "))) for _ in range(M)]

A.sort()
BC.sort(key=lambda x: x[1], reverse=True)

i = 0
for b, c in BC:
    for j in range(b):
        A[i] = max(A[i], c)
        i += 1

print(sum(A))

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

A.sort()
BC.sort(key=lambda x: x[1], reverse=True)

i = 0
for b, c in BC:
    for j in range(b):
        A[i] = max(A[i], c)
        i += 1
        if i >= N:
            print(sum(A))
            exit()

print(sum(A))
Buggy python submission (verdict: Runtime Error):
import re

N = int(input())
S = input()
K = int(input())

print(re.sub(f'[^{S[K-1]}]', '*', S))

Fixed submission:
import re

N = int(input())
S = input()
K = int(input())

print(re.sub("[^" + S[K-1] + "]", '*', S))
Buggy python submission (verdict: Runtime Error):
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[1] == "#":
    l.pop()

if len(l) == 0:
    print(0)
    exit()

min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

x = len(l)//2
for i in range(x):
    m = black[i] + (white[x] - white[i])
    min_num = min(m, min_num)

print(min_num)


Fixed submission:
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[-1] == "#":
    l.pop()

if len(l) == 0:
    print(0)
    exit()

min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

x = len(l)//2
for i in range(x+1):
    m = (black[i] - black[0]) + (white[x] - white[i])
    min_num = min(m, min_num)

print(min_num)

Buggy python submission (verdict: Runtime Error):
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[1] == "#":
    l.pop()

if len(l) == 0:
    print(0)
    exit()
    
min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

for i in range(len(l)//2):
    m = black[i] + (white[-1] - white[i])
    min_num = min(m, min_num)

print(min_num)


Fixed submission:
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[-1] == "#":
    l.pop()

if len(l) == 0:
    print(0)
    exit()

min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

x = len(l)//2
for i in range(x+1):
    m = (black[i] - black[0]) + (white[x] - white[i])
    min_num = min(m, min_num)

print(min_num)