Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
A, B, M = map(int, input().split())
a = np.array(list(map(int, input().split())), dtype="int64")
b = np.array(list(map(int, input().split())), dtype="int64")
m = np.zeros((A, B), dtype="int64")

for i in range(M):
    x, y, c = map(int, input().split())
    if m[x-1][y-1] < c:
        m[x-1][y-1] = c

ans = 9999999999
for i in range(A):
    for j in range(B):
        price = a[i] + b[j] - m[i][j]
        if price < ans:
            ans = price
print(ans)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    price = a[x-1] + b[y-1] - c
    if ans > price:
        ans = price
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
A, B, M = map(int, input().split())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
m = np.zeros((A, B), dtype="int64")

for i in range(M):
    x, y, c = map(int, input().split())
    if m[x-1][y-1] < c:
        m[x-1][y-1] = c

ans = 9999999999
for i in range(A):
    for j in range(B):
        price = a[i] + b[j] - m[i][j]
        if price < ans:
            ans = price
print(ans)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    price = a[x-1] + b[y-1] - c
    if ans > price:
        ans = price
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
A, B, M = map(int, input().split())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
m = np.zeros((A, B), dtype="int64")

for i in range(M):
    x, y, c = map(int, input().split())
    if m[x-1][y-1] < c:
        m[x-1][y-1] = c

ans = 9999999999
for i in range(A):
    for j in range(B):
        price = a[i] + b[j] - m[i][j]
        if price < ans:
            ans = price
print(ans)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    price = a[x-1] + b[y-1] - c
    if ans > price:
        ans = price
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
Q = int(input())

reverse = False
for i in range(Q):
    q = input()
    if q == "1":
        reverse = False if reverse else True
    else:
        t, f, c = q.split(" ")
        if f == "1":
            if reverse:
                s = "%s%s" % (s, c)
            else:
                s = "%s%s" % (c, s)
        else:
            if reverse:
                s = "%s%s" % (c, s)
            else:
                s = "%s%s" % (s, c)
if reverse:
    print(s[::-1])
else:
    print(s)

Fixed submission:
from collections import deque
s = deque(input())
Q = int(input())

reverse = False
for i in range(Q):
    q = input()
    if q == "1":
        reverse = False if reverse else True
    else:
        t, f, c = q.split(" ")
        if f == "1":
            if reverse:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if reverse:
                s.appendleft(c)
            else:
                s.append(c)
ans = ''.join(s)
if reverse:
    print(ans[::-1])
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
Q = int(input())

for i in range(Q):
    q = input()
    if q == "1":
        s = s[::-1]
    else:
        t, f, c = q.split(" ")
        if f == "1":
            s = c + s
        else:
            s = s + c
print(s)

Fixed submission:
from collections import deque
s = deque(input())
Q = int(input())

reverse = False
for i in range(Q):
    q = input()
    if q == "1":
        reverse = False if reverse else True
    else:
        t, f, c = q.split(" ")
        if f == "1":
            if reverse:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if reverse:
                s.appendleft(c)
            else:
                s.append(c)
ans = ''.join(s)
if reverse:
    print(ans[::-1])
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, p = map(int, input().split(" "))
s = int(input())

divider = pow(10, n-1)
minus = s // divider * divider
r = n*(n+1)//2
count = 0
for i in range(r):
    if (s // divider) % p == 0:
        count += 1
    divider //= 10
    if divider == 0:
        n -= 1
        divider = pow(10, n-1)
        s -= minus
        minus = s // divider * divider

print(count)

Fixed submission:
from collections import Counter

n, p = map(int, input().split(" "))
s = list(map(int, input()))

ans = 0
if 10 % p == 0: # p = 2, 5
    for i, num in enumerate(s, 1):
        if num % p == 0:
            ans += i
    print(ans)
    exit()

s = s[::-1]
power = 1
t = [0] * len(s)
t[0] = s[0] % p
for i in range(1, len(s)):
    power = power * 10 % p
    t[i] = (t[i-1] + s[i] * power) % p

counter = Counter(t)
for i in counter.values():
    ans += i * (i-1) // 2
ans += counter[0]
print(ans)

# count = [0] * p
# count[0] = 1
# for i in t:
#     ans += count[i]
#     count[i] += 1
# print(ans)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
Xi = list(map(int, input().split(" ")))

Xi_min = min(Xi)
Xi_max = max(Xi)

ans = math.inf
print("-----")
for i in range(Xi_min, Xi_max+1):
    tmp = 0
    for j in range(N):
        tmp += pow(Xi[j] - i, 2)
    if tmp < ans:
        ans = tmp

print(ans)

Fixed submission:
import math

N = int(input())
Xi = list(map(int, input().split(" ")))

Xi_min = min(Xi)
Xi_max = max(Xi)

ans = 999999999
for i in range(Xi_min, Xi_max+1):
    tmp = 0
    for j in range(N):
        tmp += pow(Xi[j] - i, 2)
    if tmp < ans:
        ans = tmp

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

data = {}
names = []
max_poll = 1

for i in range(n):
    s = input()
    if s in names:
        data[s] += 1
    else:
        data[s] = 1
        names.append(s)
    if max_poll < data[s]:
        max_poll = data[s]

winner = []
for key, value in data.items():
    if max_poll == value:
        winner.append(key)

winner.sort()
for i in winner:
    print(i)


Fixed submission:
n = int(input())

data = {}
names = []
max_poll = 1

for i in range(n):
    s = input()
    try:
        data[s] += 1
    except:
        data[s] = 1
        names.append(s)
    if max_poll < data[s]:
        max_poll = data[s]

winner = []
for key, value in data.items():
    if max_poll == value:
        winner.append(key)

winner.sort()
for i in winner:
    print(i)
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input())))
    N = N[::-1] + [0]

    ans = 0
    for i in range(len(N)-1):
        if N[i] < 5:
            ans += N[i]
        elif N[i] > 5:
            ans += 10 - N[i]
            N[i+1] += 1
        else:
            ans += 5
            if N[i+1] >= 5:
                N[i+1] += 1

    print(ans + N[len(N)-1])

main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    N = N[::-1] + [0]

    ans = 0
    for i in range(len(N)-1):
        if N[i] < 5:
            ans += N[i]
        elif N[i] > 5:
            ans += 10 - N[i]
            N[i+1] += 1
        else:
            ans += 5
            if N[i+1] >= 5:
                N[i+1] += 1

    print(ans + N[len(N)-1])

main()

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[::-1]))) + [0]

    ans = 0
    for i in range(len(N)-1):
        if N[i] < 5:
            ans += N[i]
        elif N[i] > 5:
            ans += 10 - N[i]
            N[i+1] += 1
        else:
            ans += 5
            if N[i+1] >= 5:
                N[i+1] += 1

    print(ans + N[len(N)-1])

main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    N = N[::-1] + [0]

    ans = 0
    for i in range(len(N)-1):
        if N[i] < 5:
            ans += N[i]
        elif N[i] > 5:
            ans += 10 - N[i]
            N[i+1] += 1
        else:
            ans += 5
            if N[i+1] >= 5:
                N[i+1] += 1

    print(ans + N[len(N)-1])

main()

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[::-1]))) + [0]

    ans = 0
    for i in range(len(N)-1):
        if N[i] < 5:
            ans += N[i]
        elif N[i] > 5:
            ans += 10 - N[i]
            N[i+1] += 1
        else:
            ans += 5
            if N[i+1] >= 5:
                N[i+1] += 1

    print(ans + N[len(N)-1])

main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    N = N[::-1] + [0]

    ans = 0
    for i in range(len(N)-1):
        if N[i] < 5:
            ans += N[i]
        elif N[i] > 5:
            ans += 10 - N[i]
            N[i+1] += 1
        else:
            ans += 5
            if N[i+1] >= 5:
                N[i+1] += 1

    print(ans + N[len(N)-1])

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

e = [0] * 1001
e[1] = 1.0
for i in range(2, 1001):
    e[i] = e[i-1] + 0.5

ans = 0
for i in range(n-k+1):
    tmp = 0
    for j in range(k):
        tmp += e[p[i+j]]
    ans = max(ans, tmp)
print(ans)

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

e = [0] * 1001
e[1] = 1.0
for i in range(2, 1001):
    e[i] = e[i-1] + 0.5

ans = [0] * (n-k+1)
for i in range(k):
    ans[0] += e[p[i]]
for i, v in enumerate(range(k, n), start=1):
    ans[i] = ans[i-1] + e[p[v]] - e[p[v-k]]
print(max(ans))
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    K = int(input())

    if len(N) < K:
        print(0)

    if K == 1:
        print(N[0] + 9 * (len(N)-1))
    elif K == 2:
        count = 0
        for i in range(1, len(N)-1):
            count += 81 * i
        count += (N[0]-1) * 9 * (len(N)-1)

        count += 9 * (len(N)-2)

        count += N[1]
        print(count)
    else:
        count = 0
        for i in range(2, len(N)-1):
            count += 729 * i*(i-1)//2
        count += (N[0]-1) * 81 * (len(N)-1) * (len(N)-2) // 2

        count += 81 * (len(N)-2) * (len(N)-3) // 2

        count += (N[1]-1) * 9 * (len(N)-2)

        count += 9 * (len(N)-3)

        count += N[2]
        print(count)

main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    K = int(input())
    L = len(N)

    # dp[i][j][k]
    # i 桁目まで決めて
    # j 個の非0を使って
    # k = 0 : そこまでの桁はNと一致
    # k = 1 : そこまでの桁でN未満であることが確定
    dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(L + 1)]
    dp[0][0][0] = 1

    from pprint import pprint
    for i, x in enumerate(N):
        for k in range(K + 1):
            # 桁ごと数え上げ
            if x == 0:
                # x == 0
                dp[i + 1][k][0] += dp[i][k][0]
            else:
                # x == 0
                dp[i + 1][k][1] += dp[i][k][0]
                # 0 < n < x
                dp[i + 1][k + 1][1] += dp[i][k][0] * (x - 1)
                # n == x
                dp[i + 1][k + 1][0] += dp[i][k][0]
            # N未満で次の桁に1~9を入れる
            dp[i + 1][k + 1][1] += dp[i][k][1] * 9
            # N未満で次の桁に0を入れる
            dp[i + 1][k][1] += dp[i][k][1]

    print(sum(dp[L][K]))  

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
for i in range(k):
    h.pop()
print(sum(h))


Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
if n <= k:
    print(0)
    exit()
h.sort()
for i in range(k):
    h.pop()
print(sum(h))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from math import gcd
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    mod = 1000000007

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

    lcm = 1
    for i in A:
        lcm = lcm * i // gcd(lcm, i)

    ans = 0
    for i in A:
        ans += lcm // i
        ans %= mod

    print(ans)


main()

Fixed submission:
def main():
    from math import gcd
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    mod = 1000000007

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

    lcm = 1
    for i in A:
        lcm = lcm * i // gcd(lcm, i)
    lcm %= mod

    ans = 0
    for i in A:
        ans += lcm * pow(i, mod-2, mod)
        ans %= mod

    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from math import gcd
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    mod = 1000000007

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

    lcm = A[0]
    for i in range(1, N):
        lcm = lcm * A[i] // gcd(lcm, A[i])

    ans = 0
    for i in range(N):
        ans += lcm // A[i]
        ans %= mod

    print(ans)


main()

Fixed submission:
def main():
    from math import gcd
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    mod = 1000000007

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

    lcm = 1
    for i in A:
        lcm = lcm * i // gcd(lcm, i)
    lcm %= mod

    ans = 0
    for i in A:
        ans += lcm * pow(i, mod-2, mod)
        ans %= mod

    print(ans)


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

mod = 1000000007
bit = pow(2, 59)
ans = 0
while bit != 0:
    cnt = 0
    for i in range(len(a)):
        if a[i] // bit == 1:
            cnt += 1
        a[i] %= bit
    ans += (cnt * (n-cnt) * bit)
    ans %= mod
    bit //= 2

print(ans)

Fixed submission:
import numpy as np
mod = 1000000007

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

bit = 1
ans = 0
for i in range(60):
    a_and = a & 1
    cnt_one = np.count_nonzero(a_and)
    ans += (cnt_one * (n - cnt_one) * bit) % mod
    ans %= mod
    a >>= 1
    bit *= 2
    bit % mod

print(ans)

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

mod = 1000000007
bit = pow(2, 59)
ans = 0
while bit != 0:
    cnt = 0
    for i in range(len(a)):
        if a[i] // bit == 1:
            cnt += 1
        a[i] %= bit
    ans += ((cnt * (n-cnt)) % mod * bit) % mod
    ans %= mod
    bit //= 2

print(ans)

Fixed submission:
import numpy as np
mod = 1000000007

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

bit = 1
ans = 0
for i in range(60):
    a_and = a & 1
    cnt_one = np.count_nonzero(a_and)
    ans += (cnt_one * (n - cnt_one) * bit) % mod
    ans %= mod
    a >>= 1
    bit *= 2
    bit % mod

print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

if n == 1:
    while m > 0:
        a[0] //= 2
        m -= 1
    print(a[0])
    exit()

while m > 0:
    a.sort(reverse = True)
    mid = a[0] // 2
    i = 0
    while a[i] >= mid:
        if i == n:
            break
        if m > 0:
            a[i] //= 2
            m -= 1
            i += 1
        else:
            break
print(sum(a))


Fixed submission:
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

if n == 1:
    while m > 0:
        a[0] //= 2
        m -= 1
    print(a[0])
    exit()

while m > 0:
    a.sort(reverse = True)
    mid = a[0] // 2
    i = 0
    while a[i] >= mid:
        if m > 0:
            a[i] //= 2
            m -= 1
            i += 1
        else:
            break
        if i == len(a):
            break
print(sum(a))

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

if n == 1:
    while m > 0:
        a[0] //= 2
        m -= 1
    print(a[0])
    exit()

while m > 0:
    a[0] //= 2
    m -= 1
    if a[0] < a[1]:
        a.sort(reverse = True)
print(sum(a))


Fixed submission:
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

if n == 1:
    while m > 0:
        a[0] //= 2
        m -= 1
    print(a[0])
    exit()

while m > 0:
    a.sort(reverse = True)
    mid = a[0] // 2
    i = 0
    while a[i] >= mid:
        if m > 0:
            a[i] //= 2
            m -= 1
            i += 1
        else:
            break
        if i == len(a):
            break
print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from operator import itemgetter
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    N, M = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    AB.sort(key=itemgetter(1), reverse=True)
    
    schedule = [0] * M
    now = 0
    for a, b in AB:
        if a > M:
            continue

        tmp = M - a
        while tmp >= 0:
            if schedule[tmp] == 0:
                schedule[tmp] = b
                now += 1
                break
            tmp -= 1

        if now >= M:
            break

    print(sum(schedule))

main()

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from heapq import heappush, heappop

    N, M = map(int, input().split())
    AB = [ [] for _ in range(100000) ]

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

    ans = 0
    heap = []
    for a in range(M):
        for b in AB[a]:
            heappush(heap, b)
        if heap:
            ans -= heappop(heap)
    
    print(ans)

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    s = input()
    children = [0] * len(s)
    s += "E"
    start = 0
    now = 0
    while now < len(s)-1:
        r = 0
        l = 0
        while s[now] == "R":
            r += 1
            now += 1
        er = now - 1
        sl = now
        while s[now] == "L":
            l += 1
            now += 1
        count = now - start
        if count % 2 == 0:
            children[er] = count // 2
            children[sl] = count // 2
        else:
            if r % 2 == 1:
                children[er] = count // 2 + 1
                children[sl] = count // 2
            else:
                children[er] = count // 2
                children[sl] = count // 2 + 1
        start = now

    print(*children)

    return

main()


Fixed submission:
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    s = input().rstrip()
    len_s = int(len(s))
    children = [0] * len_s
    s += "E"
    start = 0
    now = 0
    while now < len_s-1:
        r = 0
        l = 0
        while s[now] == "R":
            r += 1
            now += 1
        er = now - 1
        sl = now
        while s[now] == "L":
            l += 1
            now += 1
        count = now - start
        if count % 2 == 0:
            children[er] = count // 2
            children[sl] = count // 2
        else:
            if r % 2 == 1:
                children[er] = count // 2 + 1
                children[sl] = count // 2
            else:
                children[er] = count // 2
                children[sl] = count // 2 + 1
        start = now

    print(*children)

    return

main()
Buggy python submission (verdict: Runtime Error):
mod = 1000000007

class combination():
    def __init__(self, n):
        self.fact = [1] * (n+1)
        self.ifact = [1] * (n+1)
        for i in range(1, n+1):
            self.fact[i] = self.fact[i-1]*i % mod
        self.ifact[n] = pow(self.fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            self.ifact[i-1] = self.ifact[i]*i % mod
    def comb(self, n, k):
        if k < 0 or k > n: return 0
        comb = self.fact[n]*self.ifact[k]*self.ifact[n-k] %mod
        return comb

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

comb = combination(n-k+5)
for i in range(1, k+1):
    print(comb.comb(n-k+1, i) * comb.comb(k-1, i-1) % mod)

Fixed submission:
mod = 1000000007

class combination():
    def __init__(self, n):
        self.fact = [1] * (n+1)
        self.ifact = [1] * (n+1)
        for i in range(1, n+1):
            self.fact[i] = self.fact[i-1]*i % mod
        self.ifact[n] = pow(self.fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            self.ifact[i-1] = self.ifact[i]*i % mod
    def comb(self, n, k):
        if k < 0 or k > n: return 0
        comb = self.fact[n]*self.ifact[k]*self.ifact[n-k] %mod
        return comb

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

comb = combination(n)
for i in range(1, k+1):
    print(comb.comb(n-k+1, i) * comb.comb(k-1, i-1) % mod)

Buggy python submission (verdict: Runtime Error):
mod = 1000000007

class combination():
    def __init__(self, n):
        self.fact = [1] * (n+1)
        self.ifact = [1] * (n+1)
        for i in range(1, n+1):
            self.fact[i] = self.fact[i-1]*i % mod
        self.ifact[n] = pow(self.fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            self.ifact[i-1] = self.ifact[i]*i % mod
    def comb(self, n, k):
        if k < 0 or k > n: return 0
        comb = self.fact[n]*self.ifact[k]*self.ifact[n-k] %mod
        return comb

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

comb = combination(n-k+1)
for i in range(1, k+1):
    print(comb.comb(n-k+1, i) * comb.comb(k-1, i-1) % mod)

Fixed submission:
mod = 1000000007

class combination():
    def __init__(self, n):
        self.fact = [1] * (n+1)
        self.ifact = [1] * (n+1)
        for i in range(1, n+1):
            self.fact[i] = self.fact[i-1]*i % mod
        self.ifact[n] = pow(self.fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            self.ifact[i-1] = self.ifact[i]*i % mod
    def comb(self, n, k):
        if k < 0 or k > n: return 0
        comb = self.fact[n]*self.ifact[k]*self.ifact[n-k] %mod
        return comb

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

comb = combination(n)
for i in range(1, k+1):
    print(comb.comb(n-k+1, i) * comb.comb(k-1, i-1) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

for i in range(m):
    b, c = map(int, input().split())
    for value in sorted(list(a.keys())):
        if value >= c:
            break
        if a[value] > 0:
            if a[value] >= b:
                a[value] -= b
                a[c] += b
                b = 0
            else:
                b -= a[value]
                a[c] += a[value]
                a[value] = 0
        if a[value] == 0:
            del a[value]
        if b == 0:
            break
    
ans = 0
for i in a.keys():
    ans += i * a[i]
print(ans)

Fixed submission:
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
cb = []
for i in range(m):
    b, c = map(int, input().split())
    cb.append([c, b])
cb.sort(reverse=True)

now = 0
for i in range(n):
    if a[i] < cb[now][0] and cb[now][1] > 0:
        a[i] = cb[now][0]
        cb[now][1] -= 1
    if cb[now][1] == 0:
        now += 1
    if now >= len(cb):
        break
print(sum(a))