Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i<j:
            ana1 = sorted(list(S[i]))
            ana2 = sorted(list(S[j]))
            if ana1 == ana2:
                count += 1
            
print(count)

Fixed submission:
import collections

# nC2を足す理由は、同一文字列からアナグラムとなっている2つの文字列を見つけないといけないから
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
# ソートした時にそれぞれの文字がリストに分割されるからjoinで文字列に直す
c = collections.Counter(s)
ans = 0
for i in set(s):
    n = c[i]
    ans += n * (n - 1) // 2
print(ans)

# set(s)によって、同じ文字列は消去される。そしてcによって、何回その文字が出ているかを数えれる。

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i<j:
            ana1 = list(S[i])
            ana2 = list(S[j])
            ana1.sort()
            ana2.sort()
            if ana1 == ana2:
                count += 1
            
print(count)

Fixed submission:
import collections

# nC2を足す理由は、同一文字列からアナグラムとなっている2つの文字列を見つけないといけないから
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
# ソートした時にそれぞれの文字がリストに分割されるからjoinで文字列に直す
c = collections.Counter(s)
ans = 0
for i in set(s):
    n = c[i]
    ans += n * (n - 1) // 2
print(ans)

# set(s)によって、同じ文字列は消去される。そしてcによって、何回その文字が出ているかを数えれる。

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i == j or i > j: #2つの文字列を選択
            continue
        else:
            ana1 = list(S[i])
            ana2 = list(S[j])
            ana1.sort()
            ana2.sort()
            if ana1 == ana2:
                count += 1
            
print(count)

Fixed submission:
import collections

# nC2を足す理由は、同一文字列からアナグラムとなっている2つの文字列を見つけないといけないから
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
# ソートした時にそれぞれの文字がリストに分割されるからjoinで文字列に直す
c = collections.Counter(s)
ans = 0
for i in set(s):
    n = c[i]
    ans += n * (n - 1) // 2
print(ans)

# set(s)によって、同じ文字列は消去される。そしてcによって、何回その文字が出ているかを数えれる。

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i == j or i > j: #2つの文字列を選択
            continue
        else:
            ana1 = []
            ana2 = []
            for k in range(10):
                ana1.append(S[i][k])
                ana2.append(S[j][k])
                ana1.sort()
                ana2.sort()
           
            if ana1 == ana2:
                count += 1
            else:
                continue
print(count)
               

Fixed submission:
import collections

# nC2を足す理由は、同一文字列からアナグラムとなっている2つの文字列を見つけないといけないから
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
# ソートした時にそれぞれの文字がリストに分割されるからjoinで文字列に直す
c = collections.Counter(s)
ans = 0
for i in set(s):
    n = c[i]
    ans += n * (n - 1) // 2
print(ans)

# set(s)によって、同じ文字列は消去される。そしてcによって、何回その文字が出ているかを数えれる。
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
set_a = set(a)
s_set_a = sorted(set(a))[-2]
for i in range(n):
    if max_a == a[i]:
        if len(set_a) == 1:
            print(max_a)
        else:
            print(s_set_a)
    else:
        print(max_a)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
set_a = set(a)
max_n = a.count(max_a)
if len(set_a) == 1:
    s_set_a = max_a
else:
    if max_n > 1:
        s_set_a = max_a
    else:
        s_set_a = sorted(set_a)[-2]

for i in range(n):
    if max_a == a[i]:
        print(s_set_a)
    else:
        print(max_a)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
a = deque([int(input()) for _ in range(n)])
for i in range(n):
    ak = a[i]
    del a[i]
    print(max(a))
    a.appendleft(ak)


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
set_a = set(a)
max_n = a.count(max_a)
if len(set_a) == 1:
    s_set_a = max_a
else:
    if max_n > 1:
        s_set_a = max_a
    else:
        s_set_a = sorted(set_a)[-2]

for i in range(n):
    if max_a == a[i]:
        print(s_set_a)
    else:
        print(max_a)
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
min_l = []
ij = list(set([_ % 2019 for _ in range(L, R+1)]))


for i in ij:
    for j in ij:
        if i < j:
            min_l.append((i*j) % 2019)
        else:
            continue
print(min(min_l))

Fixed submission:
l, r = map(int, input().split())
if r // 3 > (l - 1) // 3 and r // 673 > (l - 1) // 673:
    print(0)
else:
    print(min(i * j % 2019 for i in range(l, r + 1) for j in range(l, i)))

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
min_l = []
ij = [_ % 2019 for _ in range(L, R+1)]
ij_s = list(set(ij))
for i in ij_s:
    for j in ij_s:
        if i < j:
            min_l.append((i*j) % 2019)
print(min(min_l))

Fixed submission:
l, r = map(int, input().split())
if r // 3 > (l - 1) // 3 and r // 673 > (l - 1) // 673:
    print(0)
else:
    print(min(i * j % 2019 for i in range(l, r + 1) for j in range(l, i)))

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
min_l = []
ij = [_ % 2019 for _ in range(L, R+1)]
ij_s = list(set(ij))
for i in ij_s:
    for j in ij_s:
        if i < j:
            min_l.append((i*j) % 2019)
print(min(min_l))

Fixed submission:
l, r = map(int, input().split())
if r // 3 > (l - 1) // 3 and r // 673 > (l - 1) // 673:
    print(0)
else:
    print(min(i * j % 2019 for i in range(l, r + 1) for j in range(l, i)))

Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())
ij = [_ % 2019 for _ in range(L, R+1)]
ij_s = sorted(ij)
if ij_s in 3 and 673:
    print(0)
else:
    print((ij_s[0]*ij_s[1]))

Fixed submission:
l, r = map(int, input().split())
if r // 3 > (l - 1) // 3 and r // 673 > (l - 1) // 673:
    print(0)
else:
    print(min(i * j % 2019 for i in range(l, r + 1) for j in range(l, i)))

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
ij = [_ for _ in range(L, R+1)]
list_ = []
for i in ij:
    for j in ij:
        if i < j:
            list_.append((i*j) % 2019)
print(min(list_))


Fixed submission:
l, r = map(int, input().split())
if r // 3 > (l - 1) // 3 and r // 673 > (l - 1) // 673:
    print(0)
else:
    print(min(i * j % 2019 for i in range(l, r + 1) for j in range(l, i)))

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
ij = [_ for _ in range(L, R+1)]
list_ = []
for i in ij:
    for j in ij:
        if i < j:
            list_.append((i*j) % 2019)
print(min(list_))

Fixed submission:
l, r = map(int, input().split())
if r // 3 > (l - 1) // 3 and r // 673 > (l - 1) // 673:
    print(0)
else:
    print(min(i * j % 2019 for i in range(l, r + 1) for j in range(l, i)))
Buggy python submission (verdict: Runtime Error):
N,L = map(int,input().split())
azi = []
for i in range(N):
    azi.append(i+L)
if min(azi) > 0:
    k = min(azi)
elif min(azi) < 0 and max(azi) > 0:
    k = 0
elif max(azi) < 0:
    k = max(azi)
azi.remove(k)
print(sum(azi))

Fixed submission:
N,L = map(int,input().split())
azi = []
for i in range(N):
    azi.append(i+L)
if min(azi) > 0:
    k = min(azi)
elif min(azi) <= 0 and max(azi) >= 0:
    k = 0
elif max(azi) < 0:
    k = max(azi)
azi.remove(k)
print(sum(azi))

Buggy python submission (verdict: Runtime Error):
N,L = map(int,input().split())
azi = []
for i in range(N):
    azi.append(i+L)
if min(azi) > 0:
    k = min(azi)
elif min(azi) < 0 and max(azi) > 0:
    k = 0
elif max(azi) < 0:
    k = max(azi)
azi.remove(k)
print(sum(azi))

Fixed submission:
N,L = map(int,input().split())
azi = []
for i in range(N):
    azi.append(i+L)
if min(azi) > 0:
    k = min(azi)
elif min(azi) <= 0 and max(azi) >= 0:
    k = 0
elif max(azi) < 0:
    k = max(azi)
azi.remove(k)
print(sum(azi))
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())

lcm = (c * d) // math.gcd(c, d)

total = b - (b//c + b//d - b//lcm)
total_del = a-1 -((a-1)//c + (a-1)//d - (a-1)//lcm)

print(total - total_del)

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())

lcm = (c * d) // fractions.gcd(c, d)

total = b - (b//c + b//d - b//lcm)
total_del = a-1 -((a-1)//c + (a-1)//d - (a-1)//lcm)

print(total - total_del)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
dp = [0] * (10**5)
jud = [True]*(n+1)
for k in range(m):
    a = int(input())
    jud[a] = False

dp[0] = 1
if jud[1]:
    dp[1] = 1
else:
    dp[1] = 0

for i in range(2, n+1):
    if jud[i-1]:
        dp[i] += dp[i-1]
    if jud[i-2]:
        dp[i] += dp[i-2]
print(dp[n] % 1000000007)

Fixed submission:
n, m = map(int, input().split())
dp = [0] * (10**5+10)
jud = [True]*(10**5)
for k in range(m):
    a = int(input())
    jud[a] = False

dp[0] = 1
if jud[1]:
    dp[1] = 1
else:
    dp[1] = 0

for i in range(2, n+1):
    if jud[i-1]:
        dp[i] += dp[i-1]
    if jud[i-2]:
        dp[i] += dp[i-2]
print(dp[n] % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
xy_l = []
for i in range(1 << N):
    xy = 0
    for j in range(N):
        if (i >> j) & 1:
            xy += V[j] - C[j]
    xy_l.append(xy)
print(max(xy_l))

Fixed submission:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
cnt = 0
""""
xy_l = []
for i in range(1 << N):
    xy = 0
    for j in range(N):
        if (i >> j) & 1:
            xy += V[j] - C[j]
            print(xy)
    xy_l.append(xy)
print(max(xy_l))
"""

for i in range(N):
    if V[i] > C[i]:
        cnt += V[i] - C[i]
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a2 = [0]
cnt = 0
for i in a:
    a2.append(a2[-1] + i)

info = list(set(a2))
chm = []
for k in info:
    chm.append(a2.count(k))

for j in chm:
    if j == 2:
        cnt += 1
    elif j == 1:
        continue
    else:
        cnt += j * (j - 1) // 2
print(cnt)

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
a2 = [0]
cnt = 0
tmp = 0
for i in a:
    a2.append(a2[-1] + i)

a2.sort()
for j in range(n):
    if a2[j] == a2[j+1]:
        tmp += 1
    else:
        if tmp >= 2:
            cnt += tmp*(tmp+1)//2
            tmp = 0
        else:
            cnt += tmp
            tmp = 0
if tmp != 0:
    if tmp >= 2:
        cnt += tmp*(tmp+1)//2
        tmp = 0
    else:
        cnt += tmp
        tmp = 0
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a2 = [0]
cnt = 0
for i in a:
    a2.append(a2[-1] + i)

info = list(set(a2))
for j in info:
    tmp = a2.count(j)
    if tmp == 2:
        cnt += 1
    elif tmp == 1:
        continue
    else:
        cnt += tmp * (tmp - 1) // 2
print(cnt)

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
a2 = [0]
cnt = 0
tmp = 0
for i in a:
    a2.append(a2[-1] + i)

a2.sort()
for j in range(n):
    if a2[j] == a2[j+1]:
        tmp += 1
    else:
        if tmp >= 2:
            cnt += tmp*(tmp+1)//2
            tmp = 0
        else:
            cnt += tmp
            tmp = 0
if tmp != 0:
    if tmp >= 2:
        cnt += tmp*(tmp+1)//2
        tmp = 0
    else:
        cnt += tmp
        tmp = 0
print(cnt)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if (a*b)%2 == 0:
    print("Even")
else:
    print("Odd")

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

if (a*b)%2 == 0:
    print("Even")
else:
    print("Odd")

Buggy python submission (verdict: Runtime Error):
a = input("a:")
b = input("b:")
a = int(a)
b = int(b)

if (a*b)%2 == 0:
    print("Even")
else:
    print("Odd")


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

if (a*b)%2 == 0:
    print("Even")
else:
    print("Odd")

Buggy python submission (verdict: Runtime Error):
a = int(input("a:"))
b = int(input("b:"))

if (a*b)%2 == 0:
    print("Even")
else:
    print("Odd")


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

if (a*b)%2 == 0:
    print("Even")
else:
    print("Odd")

Buggy python submission (verdict: Runtime Error):
a = int(input("a:"))
b = int(input("b:"))

AB = a*b
if AB%2 == 0:
    print("Even")
else:
    print("Odd")

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

if (a*b)%2 == 0:
    print("Even")
else:
    print("Odd")

Buggy python submission (verdict: Runtime Error):
a = int(input("a: "))
b = int(input("b: "))

AB = a*b
if AB%2 == 0:
    print("Even")
else:
    print("Odd")

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

if (a*b)%2 == 0:
    print("Even")
else:
    print("Odd")
Buggy python submission (verdict: Runtime Error):
s = list(str(input()))
if len(s) == 1:
    print("YES")
    exit()
# 1文字と2文字と3文字で場合分けしてみる
jud = len(set(s))
jud_s = list(set(s))

count_0 = s.count(jud_s[0])
count_1 = s.count(jud_s[1])
count_2 = s.count(jud_s[2])

max_c = max(count_0, count_1, count_2)
if abs(max_c -count_0) < 2 and abs(max_c - count_1) <2 and abs(max_c -count_2) < 2:
    print("YES")
else:
    print("NO")

Fixed submission:
s = list(str(input()))
count_0 = s.count("a")
count_1 = s.count("b")
count_2 = s.count("c")
max_c = max(count_0, count_1, count_2)
if abs(max_c - count_0) < 2 and abs(max_c - count_1) < 2 and abs(max_c - count_2) < 2:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
s = list(str(input()))
if len(s) == 1:
    print("YES")
    exit()


count_0 = s.count(jud_s[0])
count_1 = s.count(jud_s[1])
count_2 = s.count(jud_s[2])

max_c = max(count_0, count_1, count_2)
if abs(max_c -count_0) < 2 and abs(max_c - count_1) <2 and abs(max_c -count_2) < 2:
    print("YES")
else:
    print("NO")

Fixed submission:
s = list(str(input()))
count_0 = s.count("a")
count_1 = s.count("b")
count_2 = s.count("c")
max_c = max(count_0, count_1, count_2)
if abs(max_c - count_0) < 2 and abs(max_c - count_1) < 2 and abs(max_c - count_2) < 2:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
for i in range(N):
    if i == 0:
        memo.append(2)
    elif i == 1:
        memo.append(1)
    else:
        memo.append(memo[i-1] + memo[i-2])

if N == 1:
    print(1)
else:
    print(memo[N - 1] + memo[N - 2])

Fixed submission:
N = int(input())
memo = []
for i in range(N):
    if i == 0:
        memo.append(2)
    elif i == 1:
        memo.append(1)
    else:
        memo.append(memo[i-1] + memo[i-2])
if N == 1:
    print(1)
else:
    print(memo[N - 1] + memo[N - 2])

Buggy python submission (verdict: Runtime Error):
N = int(input())
memo = []
for i in range(N):
    if i == 0:
        memo.append(2)
    elif i == 1:
        memo.append(1)
    else:
        memo.append(memo[i-1] + memo[i-2])
if N == 0:
    print(memo[0])
elif N == 1:
    print(memo[1])
else: 
    print(memo[N-1] + memo[N - 2])

Fixed submission:
N = int(input())
memo = []
for i in range(N):
    if i == 0:
        memo.append(2)
    elif i == 1:
        memo.append(1)
    else:
        memo.append(memo[i-1] + memo[i-2])
if N == 1:
    print(1)
else:
    print(memo[N - 1] + memo[N - 2])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0
info = []

for i in range(n):
    b_p = bisect.bisect_left(a, b[i])
    info.append(b_p)

for k in range(n):
    a_p = bisect.bisect_left(b, c[k])
    cnt += sum(info[:a_p])

print(cnt)

Fixed submission:
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0
info1 = []


for i in range(n):
    b_p = bisect.bisect_left(a, b[i])
    info1.append(b_p) # bがそれぞれ何種類のaを載せれるか

info2 = [info1[0]]
for l in range(1, n):
    info2.append(info2[l-1] + info1[l])

for k in range(n):
    a_p = bisect.bisect_left(b, c[k])
    if a_p != 0:
        cnt += info2[a_p - 1]  # cがそれぞれ何種類のbを載せれるか
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ab1 = []
ab2 = []

for i in ab:
    if i[0] == 1:
        ab1.append(i[1])
    elif i[1] == n:
        ab2.append(i[0])

for i in ab1:
    for j in ab2:
        if i == j:
            print("POSSIBLE")
            exit()

print("IMPOSSIBLE")

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

ab1 = []
ab2 = []

for i in ab:
    if i[0] == 1:
        ab1.append(i[1])
    elif i[1] == n:
        ab2.append(i[0])

jud = ab1 + ab2
if len(jud) == len(set(jud)):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []


if n % 2 == 0:
    for i in range(n):
        if i % 2 != 0:  # 偶数なら前
            b.insert(0, a[i])
        else:
            b.append(a[i])
else:
    for j in range(n):
        if j % 2 == 0:  # 偶数なら後ろ
            b.insert(0, a[j])
        else:
            b.append(a[j])

for j in b:
    print("{}".format(j), end=" ")

Fixed submission:
from collections import deque

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


if n % 2 == 0:
    for i in range(n):
        if i % 2 != 0:  # 偶数なら前
            b.appendleft(a[i])
        else:
            b.append(a[i])
else:
    for j in range(n):
        if j % 2 == 0:  # 偶数なら後ろ
            b.appendleft(a[j])
        else:
            b.append(a[j])

print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []

for i in range(n):
    b.append(a[i])
    b.reverse()

for j in b:
    print("{}".format(j), end=" ")

Fixed submission:
from collections import deque

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


if n % 2 == 0:
    for i in range(n):
        if i % 2 != 0:  # 偶数なら前
            b.appendleft(a[i])
        else:
            b.append(a[i])
else:
    for j in range(n):
        if j % 2 == 0:  # 偶数なら後ろ
            b.appendleft(a[j])
        else:
            b.append(a[j])

print(*b)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ac,wa,tle,re = 0,0,0,0
for i in range(n):
    inp = input()
    if inp == 'AC':
        ac += 1
    elif inp == 'WA':
        wa += 1
    elif inp == 'TLE':
        tle += 1
    else :
        RE += 1



print('AC x {}\nWA x {}\nTLE x {}\nRE x {}'.format(ac,wa,tle,re))

Fixed submission:
n = int(input())
ac,wa,tle,re = 0,0,0,0
for i in range(n):
    inp = input()
    if inp == 'AC':
        ac += 1
    elif inp == 'WA':
        wa += 1
    elif inp == 'TLE':
        tle += 1
    else:
        re += 1



print('AC x {}\nWA x {}\nTLE x {}\nRE x {}'.format(ac,wa,tle,re))
Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())
STXlist = [list(map(int,input().split())) for _ in range(n)]
D = [(-1)*int(input()) for _ in range(q)]

time = 0
stop = 1
ans = [1j] * q
T = (sorted(STXlist, key=lambda x: x[1],reverse=True))  
Tmax = T[0][2]

while True:
    time += 1
    D = list(map(lambda x:x+1 , D))

    for STX in STXlist:
        if time >= STX[0] and time < STX[1]:
            if STX[2] in D:
                stop += 1
                ans[D.index(STX[2])] = D[D.index(STX[2])]
                D[D.index(STX[2])] = (1 + 1j)

    if stop == q:
        for i in ans:
            print(i)
        break
    
    if time > Tmax + 10:
        indexes = [i for i, x in enumerate(ans) if x == 1j]
        for i in indexes:
            ans[ans.index(1j)] = -1
        for i in ans:
            print(i)
        break


Fixed submission:
a,p = map(int, input().split())


print((a*3 + p)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())

a = list(map(int,input().split()))
bclist = [list(map(int,input().split())) for _ in range(m)]

all = a

for bc in bclist:
    for i in range(bc[0]):
        all.append(bc[1])

all.sort()

print(sum(all[(len(all)-n):]))

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

bclist=sorted(bclist, key = lambda x:x[1], reverse=True)

all = []


for i in range(m):
    all.extend([bclist[i][1]]*bclist[i][0])
    if len(all) >n:
        break

all.extend(a)
all.sort(reverse=True)

print(sum(all[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())

a = list(map(int,input().split()))
bclist = [list(map(int,input().split())) for _ in range(m)]

a.sort()

last = 0

for bc in  bclist:
    for i in range(bc[0]):
        if a[i] < bc[1]:
            a[i] = bc[1]     
    a.sort()


print(sum(a))

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

bclist=sorted(bclist, key = lambda x:x[1], reverse=True)

all = []


for i in range(m):
    all.extend([bclist[i][1]]*bclist[i][0])
    if len(all) >n:
        break

all.extend(a)
all.sort(reverse=True)

print(sum(all[:n]))

Buggy python submission (verdict: Runtime Error):
from operator import itemgetter
 


n,m = map(int, input().split())

a = list(map(int,input().split()))
bclist = [list(map(int,input().split())) for _ in range(m)]

a.sort()
bclist.sort(key=itemgetter(1))

last = 0

for bc in  reversed(bclist):
    for i in range(bc[0]):
        if bc[1] > a[last]:
            a[last] = bc[1]
            last += 1


print(sum(a))

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

bclist=sorted(bclist, key = lambda x:x[1], reverse=True)

all = []


for i in range(m):
    all.extend([bclist[i][1]]*bclist[i][0])
    if len(all) >n:
        break

all.extend(a)
all.sort(reverse=True)

print(sum(all[:n]))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

a.sort()
arrived = [a.pop()]
comfort = [arrived[0]]
score = 0

for i in range(n - 1):
    x = a.pop()
    max_index = np.argmax(comfort)
    score += comfort[max_index]

    arrived.insert(max_index + 1, x)
    comfort[max_index] = min(arrived[max_index], x)
    comfort.insert(max_index + 1, min(x, arrived[max_index + 1]))

print(score)

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

a.sort(reverse=True)

score = - a[0]
for i in range(n):
    score += a[i // 2]
print(score)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

a.sort()

arrived = []
score = 0
for i in range(n):
    x = a.pop()
    _max = [0, 0]
    for j in range(len(arrived)):
        if _max[0] < (_min := min(arrived[j - 1], arrived[j])):
            _max = [_min, j + 1]
    arrived.insert(_max[1], x)
    score += _max[0]
print(score)

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

a.sort(reverse=True)

score = - a[0]
for i in range(n):
    score += a[i // 2]
print(score)