Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02726 (python)

Fixed submission:
N,X,Y = map(int,input().split())
from itertools import combinations
counter = [0]*(N+1)

for com in combinations(range(N),2):
    i,j = com
    min_path = min(j-i,abs(X-1-i)+abs(Y-1-j)+1)
    counter[min_path]+=1

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

Buggy submission (verdict: Runtime Error):
from collections import deque
N,X,Y = map(int,input().split())

concat = [[i,i+2] if not (i==0 or i==N-1) else [] for i in range(N)]
concat[0].append(2)
concat[N-1].append(N-1)
concat[X-1].append(Y)
concat[Y-1].append(X)


def bfs():
    #global que
    if len(que)==0:
        return
    out = que.popleft()
    for out_element in concat[out-1]:
        if check[out_element-1]==-1:
            check[out_element-1] = check[out-1]+1
            que.append(out_element)
    bfs()


li_=[0 for i in range(N)]
for i in range(1,N+1):
    check = [-1 for k in range(N)]
    check[i-1]=0
    que = deque([i])
    bfs()
    for i in range(N):
        li_[i] += check.count(i)


    
for i in range(1,N):
    print(li_[i]//2)
Problem p02757 (python)

Fixed submission:
N,P = map(int,input().split())
S = map(int,input())
S_li = [0]*(N+1)
S_rev = reversed(tuple(S))

tmp = 0
count= 0
from  collections import Counter

if 10%P==0:
    counter = 0
    for i,num in enumerate(S_rev):
        if num%P==0:
            counter += N-i
    print(counter)

else:
    ctr = [0] * P
    ctr[0] = 1
    ret = 0
    t = 0
    c = 1
    for x in S_rev:
        t = (t + c * x) % P
        ret += ctr[t]
        ctr[t] += 1
        c = c * 10 % P
 
    print(ret)

Buggy submission (verdict: Runtime Error):
N,P = map(int,input().split())
S = input()
S_li = [0]*(N+1)
S_rev = reversed(S)
counter = 0
tmp = 0
count= 0
from  collections import Counter

if 10%P==0:
    for i,num in enumerate(S_rev):
        if num==str(P) or num=="0":
            counter += N-i
    print(counter)

else:
    ctr = [0] * P
    ctr[0] = 1
 
    ret = 0
    t = 0
    c = 1
    for x in S_rev:
        t = (t + c * x) % P
        ret += ctr[t]
        ctr[t] += 1
        c = c * 10 % P
 
    print(ret)
Problem p02769 (python)

Fixed submission:
n,k = map(int,input().split())
p = pow(10,9)+7
li = [1]*(n+2)

counter = 0
k = min(k,n-1)

for a in range(1,n+1):
    li[a] = a*li[a-1]%p

def comb(a,b):
    if b<1:
        return 1
    return li[a]*pow(li[b],p-2,p)*pow(li[a-b],p-2,p)


for i in range(k+1):
    counter += comb(n,i)*comb(n-1,i)%p
    #nCi*  (n-1)Cn-i-1


    #n人をn-iのぐるーぷに分ける

print(counter%p)

Buggy submission (verdict: Runtime Error):
from functools import reduce

def comb(n,k,p):
    if k==0:
        return 1
    A = reduce(lambda x,y:x*y%p ,[n-k+1+i for i in range(k)])
    B = reduce(lambda x,y:x*y%p ,[i+1 for i in range(k)])
    return A*pow(B,p-2,p)%p

n,K = map(int,input().split())
p = pow(10,9)+7
counter = 0

for k in range(K+1):
    counter += comb(n-1,n-k-1,p)*comb(n,k,p)

print(counter)
Problem p02771 (python)

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

if len(A)==2:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
A = set(int,input().split())

if len(A)==2:
    print("Yes")
else:
    print("No")
Problem p02781 (python)

Fixed submission:
N = int(input())
K = int(input())


def func(num,counter):
    remain = num%10
    quotient = num//10
    
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))

Buggy submission (verdict: Runtime Error):
import functools
N = int(input())
K = int(input())

@functools.lru_cache(user_function)
def func(num,counter):
    remain = num%10
    quotient = num//10
    
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))

Buggy submission (verdict: Runtime Error):
import functiontool
N = int(input())
K = int(input())

@functools.lru_cache(user_function)
def func(num,counter):
    remain = num%10
    quotient = num//10
    
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))

Buggy submission (verdict: Runtime Error):
import functiontool
N = int(input())
K = int(input())

@functools.lru_cache(user_function)
def func(num,counter):
    remain = num%10
    quotient = num//10
    
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))

Buggy submission (verdict: Runtime Error):

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

@lru_cache
def func(num,counter):
    remain = num%10
    quotient = num//10
    
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))
Problem p02862 (python)

Fixed submission:
#n回,m回　　X =n + 2*m  Y = 2*n + m
X,Y = map(int,input().split())
import numpy as np
from functools import reduce
import math 
a = [[1, 2], [2, 1]]
#次に逆行列を求めます。
mod = pow(10,9)+7

b = np.linalg.inv(a)


Z = np.array([[X],[Y]])

n,m=np.dot(b,Z)
p,q = *n,*m


def comb(n,k,p):
    if k==0:
        return 1
    A = reduce(lambda x,y:x*y%p ,[n-k+1+i for i in range(k)])
    B = reduce(lambda x,y:x*y%p ,[i+1 for i in range(k)])
    return A*pow(B,p-2,p)%p


if p<0 or q<0:
    print(0)
elif not abs(p-round(p))<pow(10,-3) or not abs(q-round(q))<pow(10,-3):
    print(0)
elif p==0 and q==0:
    print(0)
elif p==0:
    print(1)
elif q==0:
    print(1)
else:
    n = int(round(p))
    m = int(round(q))
    ans = comb(n+m,m,mod)

    print(ans%mod)

Buggy submission (verdict: Runtime Error):
#n回,m回　　X =n + 2*m  Y = 2*n + m
X,Y = map(int,input().split())
import numpy as np
a = [[1, 2], [2, 1]]
#次に逆行列を求めます。
mod = pow(10,9)+7

b = np.linalg.inv(a)


Z = np.array([[X],[Y]])

n,m=np.dot(b,Z)
p,q = *n,*m

def comb(n,k,p):
    if k==0:
        return 1
    A = reduce(lambda x,y:x*y%p ,[n-k+1+i for i in range(k)])
    B = reduce(lambda x,y:x*y%p ,[i+1 for i in range(k)])
    return A*pow(B,p-2,p)%p

if p<0 or q<0:
    print(0)
elif not p == int(p) or not q==int(q):
    print(0)
elif p==0 and q==0:
    print(0)
elif p==0:
    print(1)
elif q==0:
    print(1)
else:
    n = int(p)
    m = int(q)
    ans = comb(n,m,mod)

    print(ans%mod)

Buggy submission (verdict: Runtime Error):
#n回,m回　　X =n + 2*m  Y = 2*n + m
X,Y = map(int,input().split())
import numpy as np
a = [[1, 2], [2, 1]]
#次に逆行列を求めます。
mod = pow(10,9)+7

b = np.linalg.inv(a)


Z = np.array([[X],[Y]])

n,m=np.dot(b,Z)
p,q = *n,*m



if p<0 or q<0:
    print(0)
elif not p == int(p) or not q==int(q):
    print(0)
else:
    n = int(p)+int(q)
    
    fac = [1]*(n+1)
    for i in range(1,n+1):
        fac[i] = (fac[i-1]*i) % mod 
    print(fac[n])
Problem p02881 (python)

Fixed submission:
N = int(input())
import math 

start = int(math.sqrt(N))+1
for i in range(start,0,-1):
    if N%i==0:
        print(i+N//i-2)
        break

Buggy submission (verdict: Runtime Error):
import sympy
N = int(input())
al = sympy.divisors(N)
L = len(al)
if L%2==1:
    a = al[L//2]
    print((a-1)*(a-1))
else :
    a = al[L//2-1]
    b = al[L//2]
    print(a+b-2)
Problem p02879 (python)

Fixed submission:
a,b=map(int,input().split())
if(a<10 and b<10):
  print(a*b)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
n=int(input())
if(n>81):
    print("No")
else:
    c2=0
    c3=0
    c5=0
    c7=0
    while(n%2==0):
        c2+=1
        n=n/2
    while(n%3==0):
        c3+=1
        n=n/3
    while(n%5==0):
        c5+=1
        n=n/5
    while(n%7==0):
        c7+=1
        n=n/7
    if(n!=1):
        print("No")
    else:
        if(c5==2 and c2==0 and c3==0 and c7==0):
            print("Yes")
        elif(c5==1 and c7==1 and c2==1):
            print("No")
        elif(c5<2):
            print("Yes")
        else:
            print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
if(n>81):
    print("No")
else:
    c2=0
    c3=0
    c5=0
    c7=0
    while(n%2==0):
        c2+=1
        n=n/2
    while(n%3==0):
        c3+=1
        n=n/3
    while(n%5==0):
        c5+=1
        n=n/5
    while(n%7==0):
        c7+=1
        n=n/7
    if(n!=1):
        print("No")
    else:
        if(c5==2 and c2==0 and c3==0 and c7==0):
            print("Yes")
        elif(c5<2):
            print("Yes")
        else:
            print("No")
Problem p03033 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
from bisect import bisect_left, bisect_right
import heapq

INF = float("inf")


class ErasableHeap(object):
    # https://qiita.com/Salmonize/items/638da118cd621d2628d1
    def __init__(self):
        self.data = []
        self.event = []

    def push(self, x):
        return heapq.heappush(self.data, x)

    def erase(self, x):
        return heapq.heappush(self.event, x)

    def _check(self):
        while self.event and\
                self.data[0] == self.event[0]:
            heapq.heappop(self.data)
            heapq.heappop(self.event)

    def front(self):
        self._check()
        return self.data[0]

    def pop(self):
        self.check()
        return heapq.heappop(self.data)

    def __len__(self):
        self._check()
        return len(self.data)


def main():
    N, Q = map(int, input().split())
    XST = [0]*N
    for i in range(N):
        s, t, x = map(int, input().split())
        XST[i] = (x, s-x, t-x)
    D = [0]*Q
    for i in range(Q):
        D[i] = int(input())
    event = []
    for x, s, t in XST:
        event.append((s, 1, x))
        event.append((t, -1, x))

    event.sort()

    head = 0
    stack = ErasableHeap()
    for t, p, x in event:
        while D[head] < t:
            if len(stack) == 0:
                print(-1)
            else:
                print(stack.front())
            head += 1
            if head >= Q:
                return
        if p == 1:
            stack.push(x)
        else:
            stack.erase(x)

    while head < len(D):
        if len(stack) == 0:
            print(-1)
        else:
            print(stack.front())
        head += 1
        if head >= Q:
            return


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from bisect import bisect_left


def main():
    N, Q = map(int, input().split())
    XST = []
    for i in range(N):
        s, t, x = map(int, input().split())
        XST.append((x, s-x, t-x))
    XST.sort(reverse=True)
    D = [0]*Q
    for i in range(Q):
        D[i] = int(input())
    start = [set() for _ in range(Q)]
    end = [set() for _ in range(Q)]
    # Dはソートされている。
    for x, s, t in XST:
        # こっから！
        frm = bisect_left(D, s)
        to = bisect_left(D, t, lo=frm)
        # 数列の範囲を代入で更新して、値を取得する
        start[frm].add(x)
        end[to].add(x)
        # print(*stop, sep="\n")
        # for j in range(frm, to):
        #     stop[j] = x
    curr = set()
    for i in range(Q):
        curr |= start[i] - (start[i] & end[i])
        curr -= (end[i]-start[i])
        if len(curr) == 0:
            print(-1)
        else:
            print(min(curr))


if __name__ == '__main__':
    main()
Problem p02595 (python)

Fixed submission:
n,d = map(int,input().split())
ans = 0
for i in range(n):
    x,y = map(int,input().split())
    if x*x+y*y <= d*d: ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n,d = map(int,input().split())
ans = 0
for i in range(n):
    if x*x+y*y <= d*d: ans+=1
print(ans)
Problem p02725 (python)

Fixed submission:
k,n = map(int,input().split())
a = list(map(int,input().split()))
m = a[0]+k-a[n-1]
for i in range(n-1):
    m = max(m,a[i+1]-a[i])
print(k-m)

Buggy submission (verdict: Runtime Error):
#include <stdio.h>
int main(void){
    long k,n,i,max=-1,a[200000];
    scanf("%ld%ld",&k,&n);
    for(i=0;i<n;i++) scanf("%ld",&a[i]);
    for(i=0;i<n-1;i++){
        int tmp=a[i+1]-a[i];
        if(tmp>max) max=tmp;
    }
    printf("%ld",k-max);
    return 0;
}
Problem p02831 (python)

Fixed submission:
# coding: utf-8
# Your code here!

import math
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a,b = map(int,input().split())
print(lcm(a, b))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math
import fractions
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a,b = map(int,input().split())
print(lcm(a, b))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a,b = map(int,input().split())
print(lcm(a, b))
Problem p02835 (python)

Fixed submission:
a,b,c = map(int,input().split())
if a+b+c<=21:
  print("win")
else:
  print("bust")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if a+b+c<=21:
  print("win")
else:
  prnt("bust")
Problem p02897 (python)

Fixed submission:
import math

n=int(input())
print(math.ceil(n/2)/n)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
  b[a[i]-1]+=i+1
print(*b)
Problem p02933 (python)

Fixed submission:
n = int(input())
s = input()
if n>=3200:
    print(s)
else:
    print("red")

Buggy submission (verdict: Runtime Error):
a=int(input())
s=input()
if a>=3200: print(s)
else print("red")
Problem p03038 (python)

Fixed submission:
n,m = map(int,input().split())
t = False
a = list(map(int,input().split()))
a.sort()
b = []
for i in range(m):
    b.append(list(map(int,input().split())))
b = sorted(b, key=lambda x: x[1],reverse=True)
cnt = 0
for i in range(m):
    for j in range(b[i][0]):
        if cnt > n-1 or b[i][1]<a[cnt]:
            t = True
            break
        a[cnt] = b[i][1]
        cnt+=1
    if t==True:
        break
print(sum(a))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
t = False
a = list(map(int,input().split()))
a.sort()
b = []
for i in range(m):
    b.append(list(map(int,input().split())))
b = sorted(b, key=lambda x: x[1],reverse=True)
cnt = 0
for i in range(m):
    for j in range(b[i][0]):
        if b[i][1]<a[cnt]:
            t = True
            break
        a[cnt] = b[i][1]
        cnt+=1
    if t==True:
        break
print(sum(a))
Problem p03127 (python)

Fixed submission:
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

n = int(input())
enemy = list(set(map(int,input().split())))
if len(enemy)==1:
    print(enemy[0])
else:
    enemy.sort()
    min_n = 10**10
    for i in range(len(enemy)-1):
        min_n = min(min_n,gcd(enemy[i],enemy[i+1]))
    print(min_n)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
enemy = list(set(map(int,input().split())))
if len(enemy)==1:
    print(enemy[0])
else:
    enemy.sort()
    min_n = 10**10
    for i in range(len(enemy)-1):
        min_n = min(min_n,math.gcd(enemy[i],enemy[i+1]))
    print(min_n)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
enemy = list(set(map(int,input().split())))
if len(enemy)==1:
    print(enemy[0])
else:
    enemy.sort()
    min_n = 10**10
    for i in range(n-1):
        min_n = min(min_n,math.gcd(enemy[i],enemy[i+1]))
    print(min_n)
Problem p02933 (python)

Fixed submission:
a = int(input())
s = input()
if a < 3200:
  print("red")
else:
  print(s)

Buggy submission (verdict: Runtime Error):
a = input()
s = input()
if a < 3200:
  print("red")
else:
  print(s)
Problem p03327 (python)

Fixed submission:
n = int(input())

if n < 1000:
    print("ABC")
else:
    print("ABD")

Buggy submission (verdict: Runtime Error):
n = int(input())

if n < 1000:
    input('ABC')
else:
    input('ABD')

Buggy submission (verdict: Runtime Error):
n = int(input())

if n < 1000:
    input("ABC")
else:
    input("ABD")

Buggy submission (verdict: Runtime Error):
n = int(input())

if 1 <= n <= 999:
   input("ABC")
else:
    input("ABD")
Problem p02624 (python)

Fixed submission:
#!/usr/bin/env python3

#                 N    N'
#   | 1  2  3  4  5
# 1 | 1  2  3  4  5 :  N // 1   1 * N' (N'+1) // 2
# 2 |    2     4    :  N // 2   2 * N' (N'+1) // 2
# 3 |       3       :  N // 3   3 * N' (N'+1) // 2
# 4 |          4    :  N // 4   4 * N' (N'+1) // 2
# 5 |             5 :  N // 5   5 * N' (N'+1) // 2


def solve(N):
    answer = 0
    for i in range(1, N + 1):
        mprime = N // i
        answer += i * (mprime * (mprime + 1)) // 2
    return answer


def main():
    N = int(input())  # type: int
    answer = solve(N)
    print(answer)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
from itertools import chain
import numpy as np


def solve(N: int):
    fx = np.zeros(N + 1, dtype=np.uint64)
    for i in range(1, N + 1):
        fx[i::i] += 1
    return np.sum(np.arange(0, N + 1, dtype=np.uint64) * fx)


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N = map(int, line.split())
    N = int(next(tokens))  # type: int
    answer = solve(N)
    print(answer)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from itertools import chain
import numpy as np


def sieve(n: int):
    """n以下の(1を含まない)素数を返す"""
    if n < 2:
        return []
    primes = [2]
    if n == 2:
        return primes
    flags = np.array([True for i in range(3, n + 1, 2)])
    for i in range(len(flags)):
        if flags[i]:
            n = i * 2 + 3
            primes.append(n)
            flags[i::n] = False
    return primes


def print_a(A):
    for i in range(0, len(A), 5):
        s = f"{i:3} :"
        for j in range(i, min(i + 5, len(A))):
            s += f"{A[j]:7d}"
        print(s)


def f(X, primes):
    y = 1
    for prime in primes:
        if prime > X:
            break
        count = 1
        while X % prime == 0:
            X = X // prime
            count += 1
        y *= count
    return y


def solve(N: int):
    primes = sieve(N)
    fx = np.ones(N + 1, dtype=np.uint64)
    for prime in primes:
        factor = prime
        t = 1
        while factor <= N:
            fx[factor::factor] *= (t + 1)
            fx[factor::factor] = fx[factor::factor] / t
            t += 1
            factor *= prime
    fx *= np.arange(0, len(fx), dtype=np.uint64)
    return fx.sum()


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N = map(int, line.split())
    N = int(next(tokens))  # type: int
    answer = solve(N)
    print(answer)


if __name__ == "__main__":
    main()
Problem p02970 (python)

Fixed submission:
#!/usr/bin/env python3


def solv(n, d):
    ll = d * 2 + 1
    ans = (n + ll - 1) // ll
    return ans


if __name__ == '__main__':

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

    ans = solv(n, d)

    print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def solve(N, d):
    total = 0
    for i1 in range(len(d)):
        for i2 in range(i1+1, len(d)):
            total += d[i1] * d[i2]
    return total


if __name__ == '__main__':
    N = int(input())
    d = map(int, input().split())

    ans = solve(N, list(d))

    print(ans)
Problem p02990 (python)

Fixed submission:
#!/usr/bin/env python3

import math


P_NUM = 1000000007


def ncr(n, r):
    return math.factorial(n) // math.factorial(n-r) // math.factorial(r)


def solv(n, k):
    blue = k
    red = n - k
    for i in range(1, k+1):
        # print('blue=', blue, ' i=', i)
        blue_ptn = ncr(blue-1, i-1)
        # print('blue_ptn=', blue_ptn)
        # print('red=', red, ' i=', i)
        if red+1 < i:
            red_ptn = 0
        else:
            red_ptn = ncr(red+1, i)
        # print('red_ptn=', red_ptn)
        print(blue_ptn * red_ptn % P_NUM)


if __name__ == '__main__':

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

    solv(n, k)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

import math


P_NUM = 1000000007


def ncr(n, r):
    return math.factorial(n) // math.factorial(n-r) // math.factorial(r)


def solv(n, k):
    for i in range(1, k+1):
        blue_ptn = ncr(k-1, i-1)
        red_ptn = ncr(n-k+1, i)
        print(blue_ptn * red_ptn % P_NUM)


if __name__ == '__main__':

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

    solv(n, k)
Problem p03038 (python)

Fixed submission:
#!/usr/bin/env python3


def solv(n, m, a, s):
    a = sorted(a)
    s = sorted(s, key=lambda x: -x[1])
    i = 0
    sum0 = 0
    for (b, c) in s:
        if (i+b) < n and a[i+b] < c:
            sum0 += b*c
            i += b
        else:
            for _ in range(b):
                if i >= n:
                    return sum0
                elif c <= a[i]:
                    return sum0 + sum(a[i:])
                sum0 += c
                i += 1
    if i >= n:
        return sum0
    return sum0 + sum(a[i:])


if __name__ == '__main__':

    n, m = map(int, input().split())
    a = map(int, input().split())
    s = []
    for _ in range(m):
        b, c = map(int, input().split())
        s.append((b, c))

    ans = solv(n, m, a, s)

    print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import numpy as np


def solv(n, m, a, s):
    a = np.sort(a)
    s = sorted(s, key=lambda x: -x[1])
    i = 0
    for (b, c) in s:
        for _ in range(b):
            if c <= a[i]:
                return a.sum()
            elif i >= n:
                return a.sum()
            a[i] = c
            i += 1
    return a.sum()


if __name__ == '__main__':

    n, m = map(int, input().split())
    a = np.fromiter(map(int, input().split()), dtype='uint64')
    s = []
    for _ in range(m):
        b, c = map(int, input().split())
        s.append((b, c))

    ans = solv(n, m, a, s)

    print(ans)

Buggy submission (verdict: Runtime Error):
 
def solv(n, m, a, s):
    a = sorted(a)
    s = sorted(s, key=lambda x: -x[1])
    i = 0
    for (b, c) in s:
        for _ in range(b):
            if c <= a[i]:
                return sum(a)
            elif i >= n:
                return sum(a)
            a[i] = c
            i += 1
    return sum(a)
 
 
if __name__ == '__main__':
 
    n, m = map(int, input().split())
    a = map(int, input().split())
    s = []
    for _ in range(m):
        b, c = map(int, input().split())
        s.append((b, c))
 
    ans = solv(n, m, a, s)
 
    print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3


def solv(n, m, a, s):
    a = sorted(a)
    s = sorted(s, key=lambda x: -x[1])
    i = 0
    for (b, c) in s:
        for _ in range(b):
            if c <= a[i]:
                return sum(a)
            elif i >= n:
                return sum(a)
            a[i] = c
            i += 1
    return sum(a)


if __name__ == '__main__':

    n, m = map(int, input().split())
    a = map(int, input().split())
    s = []
    for _ in range(m):
        b, c = map(int, input().split())
        s.append((b, c))

    ans = solv(n, m, a, s)

    print(ans)