Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline

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

A.sort()

is_ok = [False] * (10 ** 5 + 1)
is_exist = [False] * (10 ** 5 + 1)

for a in A:
    if is_exist[a]:
        is_ok[a] = False
    else:
        is_exist[a] = True
        is_ok[a] = True
        for i in range(1, 10 ** 5 // a + 1):
            if a * i <= 10 ** 5:
                is_exist[a * i] = True

print(is_ok.count(True))


Fixed submission:
from sys import stdin
input = stdin.readline

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

A.sort()

is_ok = [False] * (10 ** 6 + 1)
is_exist = [False] * (10 ** 6 + 1)

for a in A:
    if is_exist[a]:
        is_ok[a] = False
    else:
        is_exist[a] = True
        is_ok[a] = True
        for i in range(1, 10 ** 6 // a + 1):
            if a * i <= 10 ** 6:
                is_exist[a * i] = True

print(is_ok.count(True))

Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt
from sys import stdin
input = stdin.readline

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

A.sort()
ans = 0

div_set = set([])


def div(x):
    for i in range(1, int(sqrt(x)) + 1):
        if x % i == 0:
            if i in div_set or (x // i) in div_set:
                div_set.add(x)
                return False
    div_set.add(x)
    return True


for i in range(n - 1):
    if A[i] in div_set:
        continue
    elif A[i] == A[i + 1]:
        div_set.add(A[i])
        continue
    elif div(A[i]):
        ans += 1

if div(A[n - 1]):
    ans += 1


print(ans)


Fixed submission:
from sys import stdin
input = stdin.readline

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

A.sort()

is_ok = [False] * (10 ** 6 + 1)
is_exist = [False] * (10 ** 6 + 1)

for a in A:
    if is_exist[a]:
        is_ok[a] = False
    else:
        is_exist[a] = True
        is_ok[a] = True
        for i in range(1, 10 ** 6 // a + 1):
            if a * i <= 10 ** 6:
                is_exist[a * i] = True

print(is_ok.count(True))

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
input = stdin.readline

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

is_continue = [False] * n

A.sort()
ans = 0

for i in range(0, n - 1):
    if is_continue[i]:
        continue
    else:
        ans += 1
        if A[i] == A[i + 1]:
            ans -= 1
        for j in range(i + 1, n):
            if A[j] % A[i] == 0:
                is_continue[j] = True

if not is_continue[n - 1]:
    ans += 1

print(ans)
# print(A)
# print(is_prime)
# print(is_continue)


Fixed submission:
from sys import stdin
input = stdin.readline

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

A.sort()

is_ok = [False] * (10 ** 6 + 1)
is_exist = [False] * (10 ** 6 + 1)

for a in A:
    if is_exist[a]:
        is_ok[a] = False
    else:
        is_exist[a] = True
        is_ok[a] = True
        for i in range(1, 10 ** 6 // a + 1):
            if a * i <= 10 ** 6:
                is_exist[a * i] = True

print(is_ok.count(True))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
input = stdin.readline

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

for _ in range(K):
    B = [0 for _ in range(N)]
    end = True

    for i in range(N):
        left = max(0, i - A[i])
        right = min(N - 1, i + A[i])

        B[left] += 1
        if right + 1 < N:
            B[right + 1] -= 1

    for i in range(N):
        if i > 0:
            B[i] += B[i - 1]
        if B[i] != N:
            end = False

    A = B

    if end:
        break

for a in A:
    print(a, end=" ")

print()


Fixed submission:
from sys import stdin
input = stdin.readline

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

for _ in range(K):
    B = [0 for _ in range(N)]
    end = True

    for i in range(N):
        left = max(0, i - A[i])
        right = min(N - 1, i + A[i])

        B[left] += 1
        if right + 1 < N:
            B[right + 1] -= 1

    for i in range(N):
        if i > 0:
            B[i] += B[i - 1]
        if B[i] != N:
            end = False

    A = B

    if end:
        break

for a in A:
    print(a, end=" ")

print()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
input = stdin.readline

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

ans = 1

for a in A:
    ans *= a

if ans > pow(10, 18):
    print(-1)
else:
    print(ans)


Fixed submission:
from sys import stdin
input = stdin.readline

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

ans = 1

if 0 in A:
    print(0)
    exit()

for a in A:
    ans *= a
    if a > pow(10, 18) or ans > pow(10, 18):
        print(-1)
        exit()


print(ans)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
from math import sqrt
input = stdin.readline

N = int(input())

ans = 0

seen = [0] * 10 ** 7

for i in range(2, int(sqrt(N)) + 1):
    tmp = i

    while N % tmp == 0:

        if seen[tmp] == 1:
            tmp *= i
            continue
        else:
            N //= tmp
            seen[tmp] = 1
            ans += 1
            tmp *= i

if N != 1 and (ans == 0 or seen[N] == 0):
    ans += 1

print(ans)


Fixed submission:
from sys import stdin
from math import sqrt
input = stdin.readline
N = int(input())

s = [0] * (int(sqrt(N)) + 1)

ans = 0

for i in range(2, int(sqrt(N)) + 1):
    tmp = i

    while N % tmp == 0:
        N //= tmp
        s[tmp] += 1

for i in s:
    for j in range(10 ** 5):
        if (j * (j + 1)) // 2 > i:
            k = j
            break

    ans += k - 1

for i in range(2, int(sqrt(N)) + 1):
    if N % i == 0:
        print(ans)
        exit()

if N != 1:
    ans += 1


print(ans)

Buggy python submission (verdict: Runtime Error):
from sys import stdin
from math import sqrt
input = stdin.readline

N = int(input())

ans = 0

seen = [0] * 10 ** 6

for i in range(2, int(sqrt(N)) + 1):
    tmp = i

    while N % tmp == 0:

        if seen[tmp] == 1:
            tmp *= i
            continue
        else:
            N //= tmp
            seen[tmp] = 1
            ans += 1
            tmp *= i

if N != 1 and (ans == 0 or seen[N] == 0):
    ans += 1

print(ans)


Fixed submission:
from sys import stdin
from math import sqrt
input = stdin.readline
N = int(input())

s = [0] * (int(sqrt(N)) + 1)

ans = 0

for i in range(2, int(sqrt(N)) + 1):
    tmp = i

    while N % tmp == 0:
        N //= tmp
        s[tmp] += 1

for i in s:
    for j in range(10 ** 5):
        if (j * (j + 1)) // 2 > i:
            k = j
            break

    ans += k - 1

for i in range(2, int(sqrt(N)) + 1):
    if N % i == 0:
        print(ans)
        exit()

if N != 1:
    ans += 1


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
input = stdin.readline

N, M, K = map(int, input().split())
mod = 998244353


C = [-1] * (N + 1)


def comb(N, r):
    r = min(r, N - r)

    if C[r] != -1:
        return C[r]
    else:
        ue = 1
        shita = 1

        for i in range(r):
            ue *= (N - i)
            ue %= mod
            shita *= (i + 1)
            shita %= mod

        C[r] = ue * pow(shita, mod - 2, mod)
        C[r] %= mod
        return C[r]


ans = M * pow(M - 1, N - 1 - K, mod) * comb(N - 1, K)
tmp = M * pow(M - 1, N - 1 - K, mod)

for i in range(K - 1, -1, -1):
    tmp *= (M - 1)
    tmp %= mod
    ans += tmp * comb(N - 1, i)
    ans %= mod

print(ans % mod)
# print(C)


Fixed submission:
from sys import stdin
input = stdin.readline

N, M, K = map(int, input().split())
mod = 998244353


C = [-1] * (N + 1)


def comb(n, r):
    if r > n - r:
        C[r] = C[n - r]

    if r == 0:
        C[0] = 1

    if C[r] != -1:
        return C[r]
    else:
        C[r] = comb(n, r - 1) * (n + 1 - r) * pow(r, mod - 2, mod)
        C[r] %= mod
        return C[r]


ans = 0

for i in range(K + 1):
    ans += M * pow(M - 1, N - 1 - i, mod) * comb(N - 1, i)
    ans %= mod

print(ans)
# print(C)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
input = stdin.readline

N, M, K = map(int, input().split())
mod = 998244353


C = [-1] * (N + 1)


def comb(N, r):
    r = min(r, N - r)

    if C[r] != -1:
        return C[r]
    else:
        ue = 1
        shita = 1

        for i in range(r):
            ue *= (N - i)
            ue %= mod
            shita *= (i + 1)
            shita %= mod

        C[r] = ue * pow(shita, mod - 2, mod)
        C[r] %= mod
        return C[r]


ans = 0

for i in range(K + 1):
    ans += M * pow(M - 1, N - 1 - i, mod) * comb(N - 1, i)
    ans %= mod

print(ans)
# print(C)


Fixed submission:
from sys import stdin
input = stdin.readline

N, M, K = map(int, input().split())
mod = 998244353


C = [-1] * (N + 1)


def comb(n, r):
    if r > n - r:
        C[r] = C[n - r]

    if r == 0:
        C[0] = 1

    if C[r] != -1:
        return C[r]
    else:
        C[r] = comb(n, r - 1) * (n + 1 - r) * pow(r, mod - 2, mod)
        C[r] %= mod
        return C[r]


ans = 0

for i in range(K + 1):
    ans += M * pow(M - 1, N - 1 - i, mod) * comb(N - 1, i)
    ans %= mod

print(ans)
# print(C)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from sys import setrecursionlimit
input = stdin.readline

setrecursionlimit(10 ** 9)

N, M, Q = map(int, input().split())

abcd = [list(map(int, input().split())) for _ in range(Q)]

A = []


def make(tmp):
    if len(tmp) >= 2 * N:
        A.append(list(map(int, tmp.split())))
        return
    else:
        for j in range(int(tmp[len(tmp) - 2]), M + 1):
            make(tmp + str(j) + " ")


for i in range(1, M + 1):
    tmp = ""
    tmp += str(i)
    tmp += " "
    make(tmp)

ans = 0

for s in A:
    num = 0
    for q in range(Q):
        a, b, c, d = abcd[q]
        if s[b - 1] - s[a - 1] == c:
            num += d
    ans = max(ans, num)

print(ans)


Fixed submission:
from sys import stdin
from itertools import combinations_with_replacement
input = stdin.readline

N, M, Q = map(int, input().split())

abcd = [list(map(int, input().split())) for _ in range(Q)]

s = list(range(1, M + 1))
ans = 0


for s in combinations_with_replacement(s, N):
    num = 0
    for q in range(Q):
        a, b, c, d = abcd[q]
        if s[b - 1] - s[a - 1] == c:
            num += d
    ans = max(ans, num)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from sys import setrecursionlimit
input = stdin.readline

setrecursionlimit(10 ** 9)

N, M, Q = map(int, input().split())

abcd = [list(map(int, input().split())) for _ in range(Q)]

A = []


def make(tmp):
    if len(tmp) >= 2 * N:
        A.append(list(map(int, tmp.split())))
        return
    else:
        for j in range(int(tmp[len(tmp) - 2]), M + 1):
            make(tmp + str(j) + " ")


for i in range(1, M + 1):
    tmp = ""
    tmp += str(i)
    tmp += " "
    make(tmp)

ans = 0

for s in A:
    num = 0
    for q in range(Q):
        a, b, c, d = abcd[q]
        if s[b - 1] - s[a - 1] == c:
            num += d
    ans = max(ans, num)

print(ans)


Fixed submission:
from sys import stdin
from itertools import combinations_with_replacement
input = stdin.readline

N, M, Q = map(int, input().split())

abcd = [list(map(int, input().split())) for _ in range(Q)]

s = list(range(1, M + 1))
ans = 0


for s in combinations_with_replacement(s, N):
    num = 0
    for q in range(Q):
        a, b, c, d = abcd[q]
        if s[b - 1] - s[a - 1] == c:
            num += d
    ans = max(ans, num)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, X, Y = map(int, input().split())

graph = [[] for _ in range(N)]

for i in range(N - 1):
    graph[i].append(i + 1)
    graph[i + 1].append(i)

graph[X - 1].append(Y - 1)
graph[Y - 1].append(X - 1)

# print(graph)


def bfs(s):
    q = deque([])
    q.append(s)
    dist[s][s] = 0

    while q:
        x = q.popleft()

        for nx in graph[x]:
            if dist[s][nx] != 0:
                continue
            else:
                dist[s][nx] = dist[s][x] + 1
                q.append(nx)


inf = 10 ** 9

dist = [[0] * N for _ in range(N)]

dist_lis = [0] * N

for i in range(N):
    bfs(i)

for i in range(N):
    for j in range(i + 1, N):
        dist_lis[dist[i][j]] += 1

# print(dist)
# print(dist_lis)

for i in range(1, N):
    print(dist_lis[i])


Fixed submission:
from collections import deque

N, X, Y = map(int, input().split())

graph = [[] for _ in range(N)]

for i in range(N - 1):
    graph[i].append(i + 1)
    graph[i + 1].append(i)

graph[X - 1].append(Y - 1)
graph[Y - 1].append(X - 1)

# print(graph)


def bfs(s):
    q = deque([])
    q.append(s)
    dist[s][s] = 0

    while q:
        x = q.popleft()

        for nx in graph[x]:
            if dist[s][nx] != 0:
                continue
            else:
                dist[s][nx] = dist[s][x] + 1
                q.append(nx)


inf = 10 ** 9

dist = [[0] * N for _ in range(N)]

dist_lis = [0] * N

for i in range(N):
    bfs(i)

for i in range(N):
    for j in range(i + 1, N):
        dist_lis[dist[i][j]] += 1

# print(dist)
# print(dist_lis)

for i in range(1, N):
    print(dist_lis[i])
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit
from collections import deque

setrecursionlimit(10 ** 9)

H, W = map(int, stdin.readline().split())
field = [list(stdin.readline().rstrip()) for _ in range(H)]

inf = 10 ** 9

flip_cnt = [[inf] * W for _ in range(H)]
direction = [[0, 1], [1, 0]]

q = deque([])


def bfs(h, w):
    q.append([h, w])

    while q:

        h, w = q.popleft()

        for dh, dw in direction:
            nh = h + dh
            nw = w + dw

            if nh >= H or nw >= W:
                continue

            q.append([nh, nw])

            if field[nh][nw] == field[h][w]:
                flip_cnt[nh][nw] = min(flip_cnt[nh][nw], flip_cnt[h][w])
            else:
                flip_cnt[nh][nw] = min(flip_cnt[nh][nw], flip_cnt[h][w] + 1)


flip_cnt[0][0] = 0
bfs(0, 0)

if field[0][0] == field[H - 1][W - 1] == "#":
    flip_cnt[H - 1][W - 1] += 1

print((flip_cnt[H - 1][W - 1] + 1) // 2)

# for f in flip_cnt:
#     print(f)


Fixed submission:
from sys import stdin, setrecursionlimit
from collections import deque

setrecursionlimit(10 ** 9)

H, W = map(int, stdin.readline().split())
field = [list(stdin.readline().rstrip()) for _ in range(H)]

inf = 10 ** 9

flip_cnt = [[inf] * W for _ in range(H)]
direction = [[0, 1], [1, 0]]

q = deque([])


def bfs(h, w):
    q.append([h, w])

    while q:

        h, w = q.popleft()

        for dh, dw in direction:
            nh = h + dh
            nw = w + dw

            if nh >= H or nw >= W:
                continue

            if field[nh][nw] == field[h][w]:
                if flip_cnt[nh][nw] <= flip_cnt[h][w]:
                    continue
                else:
                    flip_cnt[nh][nw] = flip_cnt[h][w]
                    q.append([nh, nw])
            else:
                if flip_cnt[nh][nw] <= flip_cnt[h][w] + 1:
                    continue
                else:
                    flip_cnt[nh][nw] = flip_cnt[h][w] + 1
                    q.append([nh, nw])


flip_cnt[0][0] = 0
bfs(0, 0)

if field[0][0] == field[H - 1][W - 1] == "#":
    flip_cnt[H - 1][W - 1] += 1

print((flip_cnt[H - 1][W - 1] + 1) // 2)

# for f in flip_cnt:
#     print(f)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

Query = [list(input()) for i in range(Q)]

for i in range(Q):
    if Query[i][0] == "1":
        S.reverse()
    else:
        if Query[i][2] == "1":
            S.insert(0, Query[i][4])
        else:
            S.append(Query[i][4])

print("".join(S))


Fixed submission:
from collections import deque

S = list(input())
Q = int(input())

S = deque(S)

Query = [list(input()) for i in range(Q)]

rev_cnt = 0

for i in range(Q):
    if Query[i][0] == "1":
        rev_cnt += 1
    else:
        if Query[i][2] == "1":
            if rev_cnt % 2 == 1:
                S.append(Query[i][4])
            else:
                S.appendleft(Query[i][4])
        else:
            if rev_cnt % 2 == 1:
                S.appendleft(Query[i][4])
            else:
                S.append(Query[i][4])

if rev_cnt % 2 == 1:
    while len(S) != 0:
        print(S.pop(), end="")
else:
    while len(S) != 0:
        print(S.popleft(), end="")


print()
Buggy python submission (verdict: Time Limit Exceeded):
import math

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

ans = 0

p = 2


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


for i in range(int(math.sqrt(n))):
    p *= p % mod

if n % 2 == 1:
    p *= 2

ans = p % mod - 1
ans -= cmb(n, a)
ans -= cmb(n, b)


print(int(ans % mod))


Fixed submission:
from sys import setrecursionlimit

setrecursionlimit(2 * 10 ** 9)

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

ans = pow(2, n, mod) - 1


def cmb(n, r):
    p, q = 1, 1
    for i in range(1, r + 1):
        p *= (n - i + 1)
        p %= mod
        q *= i
        q %= mod
    return p * pow(q, mod - 2, mod)


ans -= cmb(n, a)
ans -= cmb(n, b)


print(int(ans % mod))
Buggy python submission (verdict: Runtime Error):
from sys import stdin
from collections import deque
input = stdin.readline

N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

tree = [[] for _ in range(N)]
count = [0] * N

for a, b in ab:
    tree[a - 1].append(b - 1)

for p, x in px:
    count[p - 1] += x

d: deque = deque([])


def dfs(p):
    d.append(p)

    while d:
        p = d.pop()

        for np in tree[p]:
            count[np] += count[p]
            d.append(np)


dfs(0)

for c in count:
    print(c, end=" ")

print()


Fixed submission:
from sys import stdin
from collections import deque
input = stdin.readline

N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

tree = [[] for _ in range(N)]
count = [0] * N
seen = [0] * N

for a, b in ab:
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

for p, x in px:
    count[p - 1] += x

d = deque([])


def dfs(p):
    d.append(p)
    seen[p] = 1

    while d:
        p = d.pop()

        for np in tree[p]:
            if seen[np] == 0:
                seen[np] = 1
                count[np] += count[p]
                d.append(np)


dfs(0)

for c in count:
    print(c, end=" ")

print()

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

tree = [[] for _ in range(N)]
count = [0] * N

for a, b in ab:
    tree[a - 1].append(b - 1)


def dfs(p, x):
    count[p] += x

    for np in tree[p]:
        dfs(np, x)


for p, x in px:
    dfs(p - 1, x)

for c in count:
    print(c, end=" ")

print()


Fixed submission:
from sys import stdin
from collections import deque
input = stdin.readline

N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

tree = [[] for _ in range(N)]
count = [0] * N
seen = [0] * N

for a, b in ab:
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

for p, x in px:
    count[p - 1] += x

d = deque([])


def dfs(p):
    d.append(p)
    seen[p] = 1

    while d:
        p = d.pop()

        for np in tree[p]:
            if seen[np] == 0:
                seen[np] = 1
                count[np] += count[p]
                d.append(np)


dfs(0)

for c in count:
    print(c, end=" ")

print()
Buggy python submission (verdict: Runtime Error):
from collections import Counter as ct

N = int(input())
k = []
a = 0

for i in range(N):
    s = list(input().split())

for i in range(N - 1):
    for j in range(i + 1, N):
        if ct(s[i]) == ct(s[j]):
            a += 1

print(a)


Fixed submission:
N = int(input())
S = [list(input()) for i in range(N)]

for s in S:
    s.sort()

S.sort()

cnt = 1
ans = 0
tmp = []

for s in S:
    if s == tmp:
        cnt += 1
    else:
        tmp = s
        ans += cnt * (cnt - 1) // 2
        cnt = 1

ans += cnt * (cnt - 1) // 2

print(ans)

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

N = int(input())
s = []
k = []
a = 0

for i in range(N):
    str = input()
    s.append(ct(str))

for i in range(N - 1):
    for j in range(i + 1, N):
        if s[i] == s[j]:
            a += 1

print(a)


Fixed submission:
N = int(input())
S = [list(input()) for i in range(N)]

for s in S:
    s.sort()

S.sort()

cnt = 1
ans = 0
tmp = []

for s in S:
    if s == tmp:
        cnt += 1
    else:
        tmp = s
        ans += cnt * (cnt - 1) // 2
        cnt = 1

ans += cnt * (cnt - 1) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq as hq

N, M = map(int, input().split())
A = []

for i in range(N):
    a, b = map(int, input().split())
    A.append([b * (-1), a * (-1)])


# print(A)
ans = 0
Q = []
hq.heapify(Q)

for i in range(1, M + 1):
    for j in (A):
        if j[1] * (-1) <= i:
            hq.heappush(Q, j)
            A.remove([j[0], j[1]])
            # print(Q)
    if Q:
        ans += hq.heappop(Q)[0] * (-1)


print(ans)


Fixed submission:
import heapq as hq

N, M = map(int, input().split())
A = []

for i in range(N):
    a, b = map(int, input().split())
    A.append([a, b * (-1)])

A.sort()
# print(A)

ans = 0
j = 0
Q = []
hq.heapify(Q)

for i in range(1, M + 1):
    while j < len(A):
        if A[j][0] <= i:
            hq.heappush(Q, A[j][1])
            # print(Q)
        else:
            break
        j += 1
    if Q:
        ans += hq.heappop(Q) * (-1)


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = []

for i in range(N):
    a, b = map(int, input().split())
    A.append([a, b])


A.sort(reverse=True, key=lambda x: x[1])
# print(A)
ans = 0

for i in range(1, M + 1):
    for j in (A):
        if j[0] <= i:
            ans += j[1]
            A.remove([j[0], j[1]])
            # print(i, A)
            break


print(ans)


Fixed submission:
import heapq as hq

N, M = map(int, input().split())
A = []

for i in range(N):
    a, b = map(int, input().split())
    A.append([a, b * (-1)])

A.sort()
# print(A)

ans = 0
j = 0
Q = []
hq.heapify(Q)

for i in range(1, M + 1):
    while j < len(A):
        if A[j][0] <= i:
            hq.heappush(Q, A[j][1])
            # print(Q)
        else:
            break
        j += 1
    if Q:
        ans += hq.heappop(Q) * (-1)


print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
if A - B >= C:
　　print(0)
else:
　　print(C - A + B)

Fixed submission:
A, B, C = map(int, input().split())
if A - B >= C:
    print(0)
else:
    print(C - A + B)
Buggy python submission (verdict: Runtime Error):
A, B = map(int,input().split())
if (A + B) % 2 == 1:
  print(IMPOSSIBLE)
else:
  print((A + B) / 2)

Fixed submission:
A, B = map(int, input().split())
if (A + B) % 2 == 1:
    print("IMPOSSIBLE")
else:
    print(int((A + B) / 2))