Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
a_list = [int(x) for x in input().split()]

temp_list = [0] * (n + 1)
for i in range(1, n + 1):
    temp_list[i] = a_list[i - 1] + temp_list[i - 1]

def calc_ans(l, m, r):
    num_list = sorted([temp_list[l] - temp_list[0], temp_list[m] - temp_list[l], temp_list[r] - temp_list[m], temp_list[n] - temp_list[r]])
    return num_list[3] - num_list[0]

l, m, r = 1, 2, 3
ans = calc_ans(l, m, r)
for m in range(2, n - 2):
    print(m, a_list[:m], a_list[m:])

    gap_min = abs((temp_list[m] - temp_list[l]) - (temp_list[l] - temp_list[0]))
    while l < m:
        l += 1
        gap = abs((temp_list[m] - temp_list[l]) - (temp_list[l] - temp_list[0]))
        if gap < gap_min:
            gap_min = gap
        else:
            l -= 1
            break
    else:
        l -= 1
    
    gap_min = abs((temp_list[n] - temp_list[r]) - (temp_list[r] - temp_list[m]))
    while r < n:
        r += 1
        gap = abs((temp_list[n] - temp_list[r]) - (temp_list[r] - temp_list[m]))
        if gap < gap_min:
            gap_min = gap
        else:
            r -= 1
            break
    else:
        r -= 1
    
    ans_temp = calc_ans(l, m, r)
    if ans_temp < ans:
        ans = ans_temp
print(ans)

Fixed submission:
n = int(input())
a_list = [int(x) for x in input().split()]

temp_list = [0] * (n + 1)
for i in range(1, n + 1):
    temp_list[i] = a_list[i - 1] + temp_list[i - 1]
 
l = 1
r = 3
ans = temp_list[-1]
for m in range(2, n - 1):
    gap_min = abs((temp_list[m] - temp_list[l]) - (temp_list[l] - temp_list[0]))
    while l < m:
        l += 1
        gap = abs((temp_list[m] - temp_list[l]) - (temp_list[l] - temp_list[0]))
        if gap < gap_min:
            gap_min = gap
        else:
            l -= 1
            break
    else:
        l -= 1
    
    gap_min = abs((temp_list[n] - temp_list[r]) - (temp_list[r] - temp_list[m]))
    while r < n:
        r += 1
        gap = abs((temp_list[n] - temp_list[r]) - (temp_list[r] - temp_list[m]))
        if gap < gap_min:
            gap_min = gap
        else:
            r -= 1
            break
    else:
        r -= 1
    
    num_list = sorted([temp_list[l] - temp_list[0], temp_list[m] - temp_list[l], temp_list[r] - temp_list[m], temp_list[n] - temp_list[r]])
    ans_temp = num_list[3] - num_list[0]
    if ans_temp < ans:
        ans = ans_temp
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = [int(x) for x in input().split()]

ans = 0
for l in range(n):
    temp_xor = a_list[l]
    temp_sum = a_list[l]
    ans += 1
    for r in range(l + 1, n):
        temp_xor ^= a_list[r]
        temp_sum += a_list[r]
        if temp_xor == temp_sum:
            ans += 1
        else:
            break
print(ans)

Fixed submission:
n = int(input())
a_list = [int(x) for x in input().split()]

ans = 0
temp_xor = a_list[0]
temp_sum = a_list[0]
r = 0
for l in range(n):
    while r < n:
        if temp_xor != temp_sum:
            break
        r += 1
        if r < n:
            temp_xor ^= a_list[r]
            temp_sum += a_list[r]
    ans += r - l
    temp_xor ^= a_list[l]
    temp_sum -= a_list[l]
print(ans)
Buggy python submission (verdict: Runtime Error):
import re
a, b = [int(x) for x in input().split()]
s = input()
print("Yes" if re.search(f"\\d{{{a}}}-\\d{{{b}}}", s) is not None else "No")

Fixed submission:
import re
a, b = [int(x) for x in input().split()]
s = input()
print("Yes" if re.search("\\d{{{}}}-\\d{{{}}}".format(a, b), s) is not None else "No")
Buggy python submission (verdict: Runtime Error):
n = [int(c) for c in input()]
for i in range(2 ** 3):
    os = format(i, "03b").replace("1", "+").replace("0", "-")
    temp = n[0]
    for i, c in enumerate(os):
        num = n[i + 1]
        temp += num if c == "+" else -num
    if temp == 7:
        ans = "{0}{4}{1}{5}{2}{6}{3}=7".format(*n, *os)
        break
print(ans)

Fixed submission:
n = [int(c) for c in input()]
template_list = [
    "{}+{}+{}+{}",
    "{}+{}+{}-{}",
    "{}+{}-{}+{}",
    "{}+{}-{}-{}",
    "{}-{}+{}+{}",
    "{}-{}+{}-{}",
    "{}-{}-{}+{}",
    "{}-{}-{}-{}",
]
for template in template_list:
    temp = template.format(*n)
    if eval(temp) == 7:
        ans = "{}=7".format(temp)
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
temp_list = []
for _ in range(n):
    a = input()
    if a in temp_list:
        temp_list.remove(a)
    else:
        temp_list.append(a)
print(len(temp_list))

Fixed submission:
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for _ in range(n):
    a = input()
    d[a] += 1
ans = sum([v % 2 for v in d.values()])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = [int(x) for x in input().split()]
b = []
for i, a in enumerate(a_list):
    if i % 2 == 0:
        # b = b + [a]
        b.append(a)
    else:
        # b = [a] + b
        b.insert(0, a)
if n % 2 == 1:
    b = list(reversed(b))
print(*b)

Fixed submission:
from collections import deque
n = int(input())
a_list = [int(x) for x in input().split()]
left_flag = n % 2 == 1
d = deque()
for a in a_list:
    if left_flag:
        d.appendleft(a)
    else:
        d.append(a)
    left_flag = not left_flag
print(*d)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = [int(x) for x in input().split()]
b = []
for i, a in enumerate(a_list):
    if i % 2 == 0:
        b = b + [a]
    else:
        b = [a] + b       
if n % 2 == 1:
    b = list(reversed(b))
print(*b)

Fixed submission:
from collections import deque
n = int(input())
a_list = [int(x) for x in input().split()]
left_flag = n % 2 == 1
d = deque()
for a in a_list:
    if left_flag:
        d.appendleft(a)
    else:
        d.append(a)
    left_flag = not left_flag
print(*d)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = [int(x) for x in input().split()]
b = []
for a in a_list:
    b.append(a)
    b = list(reversed(b))
print(*b)

Fixed submission:
from collections import deque
n = int(input())
a_list = [int(x) for x in input().split()]
left_flag = n % 2 == 1
d = deque()
for a in a_list:
    if left_flag:
        d.appendleft(a)
    else:
        d.append(a)
    left_flag = not left_flag
print(*d)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = sorted([int(x) for x in input().split()])
gap = m - n
if gap > 1:
    print(0)
    exit()
mod = 10 ** 9 + 7
f = 1
for i in range(1, m + 1):
    f *= i
    if i == n:
        f_n = f % mod
f_m = f % mod
ans = f_n * f_m % mod
if gap == 0:
    ans = ans * 2 % mod
print(ans)

Fixed submission:
from math import factorial
n, m = [int(x) for x in input().split()]
temp = abs(n - m)
if temp > 1:
    print(0)
    exit()
mod = 10 ** 9 + 7
f_n = factorial(n) % mod
f_m = factorial(m) % mod
ans = f_n * f_m % mod
if temp == 0:
    ans = ans * 2 % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = sorted([int(x) for x in input().split()])
gap = m - n
if gap > 1:
    print(0)
    exit()
mod = 10 ** 9 + 7
f = f_n = 1
for i in range(2, m + 1):
    f *= i
    if i == n:
        f_n = f % mod
f_m = f % mod
ans = f_n * f_m % mod
if gap == 0:
    ans = ans * 2 % mod
print(ans)

Fixed submission:
from math import factorial
n, m = [int(x) for x in input().split()]
temp = abs(n - m)
if temp > 1:
    print(0)
    exit()
mod = 10 ** 9 + 7
f_n = factorial(n) % mod
f_m = factorial(m) % mod
ans = f_n * f_m % mod
if temp == 0:
    ans = ans * 2 % mod
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = sorted([int(x) for x in input().split()])
gap = m - n
if gap > 1:
    print(0)
    exit()
mod = 10 ** 9 + 7
f = 1
for i in range(2, m + 1):
    f *= i
    if i == n:
        f_n = f % mod
f_m = f % mod
ans = f_n * f_m % mod
if gap == 0:
    ans = ans * 2 % mod
print(ans)

Fixed submission:
from math import factorial
n, m = [int(x) for x in input().split()]
temp = abs(n - m)
if temp > 1:
    print(0)
    exit()
mod = 10 ** 9 + 7
f_n = factorial(n) % mod
f_m = factorial(m) % mod
ans = f_n * f_m % mod
if temp == 0:
    ans = ans * 2 % mod
print(ans)
Buggy python submission (verdict: Runtime Error):
mod = 10**9+7
N = int(input())
ans = (pow(a,N,mod) - 2*pow(b, N, mod) + pow(c, N, mod))%mod
if ans < 0:
    ans += mod
print(ans)


Fixed submission:
mod = 10**9+7
N = int(input())
ans = (pow(10,N,mod) - 2*pow(9, N, mod) + pow(8, N, mod))%mod
if ans < 0:
    ans += mod
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = [0,0,0,0]
for _ in range(N):
    a = input()
    if a == 'AC':
        ans[0] += 1
    elif a == 'WA':
        ans[1] += 1
    elif a == 'TLE':
        ans[2] += 1
    elif a == 'RE':
        a[3] += 1
print('AC ×',ans[0])
print('WA ×',ans[1])
print('TLE ×',ans[2])
print('RE ×',ans[3])


Fixed submission:
N = int(input())
ans = [0,0,0,0]
for _ in range(N):
    a = input()
    if a == 'AC':
        ans[0] += 1
    elif a == 'WA':
        ans[1] += 1
    elif a == 'TLE':
        ans[2] += 1
    elif a == 'RE':
        ans[3] += 1
print('AC x',ans[0])
print('WA x',ans[1])
print('TLE x',ans[2])
print('RE x',ans[3])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.sort()
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

B = []
for i in range(N-1):
    a = A[i]
    if a != A[i+1]:
        B.append(a)
if A[-1] != A[-2]:
    B.append(A[-1])
if len(B) == 0:
    print(0)
    quit()
b = B[-1]
X = set(primes(b))
A = set(B)
B = list(A&X)
A = list(A-X)
A.sort()
B.sort()
ans = []
while len(A) > 1:
    a = A[0]
    C = []
    if a != A[1]:
        ans.append(a)
    for aa in A:
        if aa % a != 0:
            C.append(aa)
    A = C
ans1 = []
for gen in ans:
    for b in B:
        if gen % b == 0:
            break
        if b > gen:
            ans1.append(gen)
            break
print(len(ans1)+len(B))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = set()
C = set()
for a in A:
    if a in B:
        C.add(a)
    else:
        B.add(a)
M = max(B)
bool = [1]*(M+1)
for c in C:
    bool[c] = 0
for b in B:
    for i in range(b*2, M+1, b):
        bool[i] = 0
ans = 0
for a in A:
    if bool[a] == 1:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = []
while len(A) > 1:
    a = A[0]
    B = []
    if a != A[1]:
        ans.append(a)
    for aa in A:
        if aa % a != 0:
            B.append(aa)
    A = B
if len(A) == 1:
    print(len(ans)+1)
else:
    print(len(ans))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = set()
C = set()
for a in A:
    if a in B:
        C.add(a)
    else:
        B.add(a)
M = max(B)
bool = [1]*(M+1)
for c in C:
    bool[c] = 0
for b in B:
    for i in range(b*2, M+1, b):
        bool[i] = 0
ans = 0
for a in A:
    if bool[a] == 1:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
if A in 0:
    ans = 0
else:
    ans = 1
    check = 10 **18
    for i in range(N):
        ans *= A[i]
        print(ans)
        if ans > check:
            ans = -1
            break
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
    ans = 0
else:
    ans = 1
    check = 10 **18
    for i in range(N):
        ans *= A[i]
        if ans > check:
            ans = -1
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = map(str, input().split())
A = int(A)
B1, B2, B3 = int(B[0]), int(B[2]), int(B[3])
ans = A*B1*100 + A*B2*10 + A*B3
ans = str(ans)
print(int(ans[:-2]))


Fixed submission:
A, B = map(str, input().split())
A = int(A)
B1, B2, B3 = int(B[0]), int(B[2]), int(B[3])
ans = A*B1*100 + A*B2*10 + A*B3
ans = str(ans)
if len(ans)>2:
    print(int(ans[:-2]))
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
if T[0:len(T)-1] = S:
    print("Yes")

else:
    print("No")


Fixed submission:
S = input()
T = input()
if T[0:len(T)-1] == S:
    print("Yes")

else:
    print("No")

Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
if T[0:len(T)-1)] = S:
    print("Yes")

else:
    print("No")


Fixed submission:
S = input()
T = input()
if T[0:len(T)-1] == S:
    print("Yes")

else:
    print("No")
Buggy python submission (verdict: Runtime Error):
A, B, C, K = map(int, input().spliit())
if K <= A :
    print(K)

elif K <= A + B:
    print(A)

else:
    print(A - (K - (A + B)))


Fixed submission:
A, B, C, K = map(int, input().split())
if K <= A :
    print(K)

elif K <= A + B:
    print(A)

else:
    print(A - (K - (A + B)))

Buggy python submission (verdict: Runtime Error):
A, B, C, K = map(int, input().spliit())
if K <= A :
    return K

elif K <= A + B:
    return A

else:
    return A - (K - (A + B))


Fixed submission:
A, B, C, K = map(int, input().split())
if K <= A :
    print(K)

elif K <= A + B:
    print(A)

else:
    print(A - (K - (A + B)))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
X = list(map(int, input().split()))
town = []
dic = {}
i = 0
j = 0
while i not in dic and j < K:
    dic[i] = j
    town.append(i)
    i = X[i] - 1
    j += 1

if j == K:
    print(town[K] + 1)

else:
    num = dic[i]
    loop = j - num
    print(town[((K - num) % loop) + num] + 1)


Fixed submission:
N, K = map(int, input().split())
X = list(map(int, input().split()))
town = []
dic = {}
i = 0
j = 0
while i not in dic and j < K:
    dic[i] = j
    town.append(i)
    i = X[i] - 1
    j += 1

if j == K:
    print(i + 1)

else:
    num = dic[i]
    loop = j - num
    print(town[((K - num) % loop) + num] + 1)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
X = list(map(int, input().split()))
town = []
dic = {}
i = 0
j = 0
while i not in dic and j < K:
    dic[i] = j
    town.append(i)
    i = X[i] - 1
    j += 1

if j == K:
    print(town[K] + 1)

else:
    num = town.index(i)
    loop = j - num
    print(town[(K - num) % loop + num]+1)


Fixed submission:
N, K = map(int, input().split())
X = list(map(int, input().split()))
town = []
dic = {}
i = 0
j = 0
while i not in dic and j < K:
    dic[i] = j
    town.append(i)
    i = X[i] - 1
    j += 1

if j == K:
    print(i + 1)

else:
    num = dic[i]
    loop = j - num
    print(town[((K - num) % loop) + num] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
X = list(map(int, input().split()))
list = []
i = 0
j = 0
while i not in list and j < K:
    list.append(i)
    i = X[i] - 1
    j += 1

if K == j:
    print(i+1)

else:    
    loop = j - list.index(i)
    print(list[(K - list.index(i)) % loop + list.index(i)]+1)


Fixed submission:
N, K = map(int, input().split())
X = list(map(int, input().split()))
town = []
dic = {}
i = 0
j = 0
while i not in dic and j < K:
    dic[i] = j
    town.append(i)
    i = X[i] - 1
    j += 1

if j == K:
    print(i + 1)

else:
    num = dic[i]
    loop = j - num
    print(town[((K - num) % loop) + num] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
X = list(map(int, input().split()))
list = []
i = 0
j = 0
while i not in list and j < K:
    list.append(i)
    i = X[i] - 1
    j += 1

if K == j:
    print(i+1)

else:    
    loop = j - list.index(i)
    print(list[(K - list.index(i)) % loop + list.index(i)]+1)


Fixed submission:
N, K = map(int, input().split())
X = list(map(int, input().split()))
town = []
dic = {}
i = 0
j = 0
while i not in dic and j < K:
    dic[i] = j
    town.append(i)
    i = X[i] - 1
    j += 1

if j == K:
    print(i + 1)

else:
    num = dic[i]
    loop = j - num
    print(town[((K - num) % loop) + num] + 1)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
H = list(map(int, input().split()))
H_val = [H[i] for i in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    if H[A] > H[B]:
        H_val[B] = 0
        
    elif H[B] > H[A]:
        H_val[A] = 0
        
    else:
        H_val[A], H_val[B] = 0, 0

    print(H, H_val)

count = 0
for i in range(N):
    if H_val[i] != 0:
        count+= 1

print(count)


Fixed submission:
N, M = map(int, input().split())
H = list(map(int, input().split()))
H_val = [H[i] for i in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    if H[A] > H[B]:
        H_val[B] = 0
        
    elif H[B] > H[A]:
        H_val[A] = 0
        
    else:
        H_val[A], H_val[B] = 0, 0

count = 0
for i in range(N):
    if H_val[i] != 0:
        count+= 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
for i in range(1000):
    pas = format(i).zfill(3)
    a, b = 0, 0
    for j in range(N-2):
        if S[j] == pas[0]:
            a = j
            for k in range(a+1, N-1):
                if S[k] == pas[1]:
                    b = k
                    for l in range(b+1, N):
                        if S[l] == pas[2]:
                            count += 1
                            break
                    break
            break
print(count)


Fixed submission:
N = int(input())
S = input()
count = 0
for i in range(1000):
    pas = format(i).zfill(3)
    a = S[:-2].find(pas[0])
    if a >= 0:
        b = S[a+1:-1].find(pas[1])
        if b >= 0:
            if pas[2] in S[a+b+2:]:
                count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
while(n != 0 or x != 0):
    count = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            if x - i - j > j and x - i - j <= n:
                count += 1
    print(count)
    n, x = map(int, input().split())


Fixed submission:
N = int(input())
ans = 0
for i in range(1, N+1, 2):
    count = 0
    for j in range(1, int(i ** 0.5) + 1):
        if i % j == 0:
            count += 2
    if int(i ** 0.5) ** 2 == i:
        count -= 1
    if count == 8:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
N = len(s)
if N == 2:
    if s[0] == s[1]:
        print('1 2')
        quit()
    else:
        print('-1,-1')
        quit()
for i in range(N-2):
    if s[i] == s[i+1] or s[i] == s[i+2]:
        print(i+1, i+3)
        quit()
if s[-1] == s[-2]:
    print(N-1, N
    quit()
print('-1 -1')


Fixed submission:
s = input()
N = len(s)
if N == 2:
    if s[0] == s[1]:
        print('1 2')
        quit()
    else:
        print('-1 -1')
        quit()
for i in range(N-2):
    if s[i] == s[i+1] or s[i] == s[i+2]:
        print(i+1, i+3)
        quit()
if s[-1] == s[-2]:
    print(N-2, N)
    quit()
print('-1 -1')
Buggy python submission (verdict: Runtime Error):
if x = 0:
  print(1)
else:
  print(0)

Fixed submission:
x = int(input())
if x == 0:
  print(1)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
a=A[0]
for i in range(1,n):
    a = a*A[i]
if(a>10**18):
    a=-1
print(a)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
if(0 in A):
    print(0)
else:
    a=A[0]
    for i in range(1,n):
        a = a*A[i]
        if(a>10**18):
            a=-1
            break
    print(a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n == 0 {
	print(1)
} else n == 1 {
	print(0)
} 
  

Fixed submission:
n = int(input())
if n == 0:
	print(1)
elif n == 1:
	print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [list(str(input())) for k in range(n)]
s_sorted = list(map(lambda x: sorted(x), s))
ans = 0
for i in range(n):
    counter = s_sorted[:i+1].count(s_sorted[i])
    ans += counter - 1
print(ans)


Fixed submission:
from collections import Counter
n = int(input())
s_sorted = []
for _ in range(n):
    s_sorted.append(''.join(sorted(input())))
s_count = Counter(s_sorted)
ans = 0
for i in s_count:
    ans += (s_count[i] * (s_count[i] - 1)) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [list(str(input())) for k in range(n)]
s_sorted = list(map(lambda x: sorted(x), s))
ans = 0
for i in range(n):
    for j in range(n):
        if i < j:
            if s_sorted[i] == s_sorted[j]:
                ans += 1
            else:
                pass
        else:
            pass
print(ans)

Fixed submission:
from collections import Counter
n = int(input())
s_sorted = []
for _ in range(n):
    s_sorted.append(''.join(sorted(input())))
s_count = Counter(s_sorted)
ans = 0
for i in s_count:
    ans += (s_count[i] * (s_count[i] - 1)) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
work_list = [list(map(int, input().split())) for _ in range(n)]
work_cand = []
salary = 0
for j in range(1, m + 1):
    for i in range(n):
        if work_list[i][0] == j:
            work_cand.append(work_list[i])
            del work_list[i]
        else:
            pass
    if work_cand != []:
         work_cand.sort(key = lambda x: x[1], reverse = True)
         salary += work_cand[0][1]
         del work_cand[0]
    else:
        pass
print(salary)
            pass



Fixed submission:
from operator import itemgetter
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key = itemgetter(0))
q = []
idx = 0
ans = 0
for i in range(1, m+1):
    while idx < n:
        a, b = ab[idx]
        if a <= i:
            heapq.heappush(q, -b)
            idx += 1
        else:
            break
    if len(q) > 0:
        b = heapq.heappop(q)
        ans -= b
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
work_list = [list(map(int, input().split())) for _ in range(n)]
work_cand = []
salary = 0
for j in range(1, m + 1):
    for i in range(n):
        if work_list[i][0] == j:
            work_cand.append(work_list[i])
        else:
            pass
    if work_cand != []:
         work_cand.sort(key = lambda x: x[1], reverse = True)
         salary += work_cand[0][1]
         del work_cand[0]
    else:
        pass
print(salary)



Fixed submission:
from operator import itemgetter
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key = itemgetter(0))
q = []
idx = 0
ans = 0
for i in range(1, m+1):
    while idx < n:
        a, b = ab[idx]
        if a <= i:
            heapq.heappush(q, -b)
            idx += 1
        else:
            break
    if len(q) > 0:
        b = heapq.heappop(q)
        ans -= b
print(ans)