Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, K= map(int, input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]

A=np.array(sorted(A, reverse=True))
F=np.array(sorted(F))

lower_bound=0
upper_bound=np.max(A*F)
K_tmp=0

while upper_bound>=lower_bound:
    mid=(lower_bound+upper_bound)//2
    K_tmp=np.sum(np.maximum(A-mid//F, 0))
    if K_tmp<=K:
        upper_bound=mid-1
    else:
        lower_bound=mid+1

print(lower_bound)


Fixed submission:
import numpy as np
N, K= map(int, input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]

A=np.array(sorted(A, reverse=True))
F=np.array(sorted(F))

lower_bound=0
upper_bound=np.max(A*F)
K_tmp=0

while upper_bound>=lower_bound:
    mid=(lower_bound+upper_bound)//2
    K_tmp=np.sum(np.maximum(A-mid//F, 0))
    if K_tmp<=K:
        upper_bound=mid-1
    else:
        lower_bound=mid+1

print(lower_bound)

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

def is_ok(arg):
    cnt=0
    for i in range(n):
        cnt+=max(a[i]-arg//f[i], 0)
    return cnt<=k

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(-1, 10**12))


Fixed submission:
import numpy as np
N, K= map(int, input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]

A=np.array(sorted(A, reverse=True))
F=np.array(sorted(F))

lower_bound=0
upper_bound=np.max(A*F)
K_tmp=0

while upper_bound>=lower_bound:
    mid=(lower_bound+upper_bound)//2
    K_tmp=np.sum(np.maximum(A-mid//F, 0))
    if K_tmp<=K:
        upper_bound=mid-1
    else:
        lower_bound=mid+1

print(lower_bound)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left

n=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(n-2):
    a=L[i]
    for j in range(i+1,n-1):
        ans+=bisect_left(L,a+L[j])-j-1
print(ans)


Fixed submission:
A,B=map(int,input().split())
print(max(0, A-2*B))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
L=list(map(int,input().split()))
L=sorted(L)

from itertools import combinations
from bisect import bisect_right,bisect_left

comb=combinations(L, 2)
cnt=0
for cb in comb:
    b,c=min(cb), max(cb)
    # a must be b or lower
    hi=bisect_left(L, b)
    low=bisect_right(L, c-b)
    #print(b,c,hi,low)
    cnt+=max(0,hi-low)
print(cnt)

Fixed submission:
from bisect import bisect_left

n=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(n-2):
    a=L[i]
    for j in range(i+1,n-1):
        ans+=bisect_left(L,a+L[j])-j-1
print(ans)

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

from itertools import combinations
from bisect import bisect_right,bisect_left

comb=combinations(L, 2)
cnt=0
for cb in comb:
    b,c=min(cb), max(cb)
    # a must be b or lower
    hi=bisect_left(L, b)
    new_L=L[:hi]
    low=bisect_right(new_L, c-b)
    #print(b,c,hi,low)
    cnt+=max(0,hi-low)
print(cnt)


Fixed submission:
from bisect import bisect_left

n=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(n-2):
    a=L[i]
    for j in range(i+1,n-1):
        ans+=bisect_left(L,a+L[j])-j-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
L=list(map(int,input().split()))
from itertools import combinations
comb=combinations(L, 3)
cnt=0
for cb in  comb:
    a,b,c=cb[0],cb[1],cb[2]
    if a<b+c and b<a+c and c<a+b:
        cnt+=1
print(cnt)

Fixed submission:
from bisect import bisect_left

n=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(n-2):
    a=L[i]
    for j in range(i+1,n-1):
        ans+=bisect_left(L,a+L[j])-j-1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())
cnt=[]
tmp=1
n=len(s)
for i in range(1,n):
    if s[i]==s[i-1]:
        tmp+=1
    else:
        cnt.append((s[i-1], tmp))
        tmp=1
    if i==n-1:
        cnt.append((s[i], tmp))

ans=0
if len(cnt)==1:
    ans=cnt[0][1]*k//2
elif cnt[0][0]!=cnt[-1][0]:
    for x,y in cnt:
        ans+=y//2
    ans*=k
else:
    for x,y in cnt:
        ans+=y//2
    ans*=k
    if (cnt[0][1]+cnt[-1][1])%2==0:
        ans+=k-1
print(ans)

Fixed submission:
s = list(input())
k = int(input())
n=len(s)
if n!=1:
    cnt=[]
    tmp=1
    for i in range(1,n):
        if s[i]==s[i-1]:
            tmp+=1
        else:
            cnt.append((s[i-1], tmp))
            tmp=1
        if i==n-1:
            cnt.append((s[i], tmp))

    ans=0
    if len(cnt)==1:
        ans=cnt[0][1]*k//2
    elif cnt[0][0]!=cnt[-1][0]:
        for x,y in cnt:
            ans+=y//2
        ans*=k
    else:
        for x,y in cnt:
            ans+=y//2
        ans*=k
        if (cnt[0][1]+cnt[-1][1])%2==0:
            ans+=k-1
    print(ans)

else:
    print(k//2)

Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())
cnt=0
tmp=1
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        tmp+=1
    else:
        cnt+=tmp//2
        tmp=1
cnt+=tmp//2
if s[0]!=s[1] and s[-1]!=s[-2] and s[0]==s[-1]:
    cnt+=1

print(cnt*k)

Fixed submission:
s = list(input())
k = int(input())
n=len(s)
if n!=1:
    cnt=[]
    tmp=1
    for i in range(1,n):
        if s[i]==s[i-1]:
            tmp+=1
        else:
            cnt.append((s[i-1], tmp))
            tmp=1
        if i==n-1:
            cnt.append((s[i], tmp))

    ans=0
    if len(cnt)==1:
        ans=cnt[0][1]*k//2
    elif cnt[0][0]!=cnt[-1][0]:
        for x,y in cnt:
            ans+=y//2
        ans*=k
    else:
        for x,y in cnt:
            ans+=y//2
        ans*=k
        if (cnt[0][1]+cnt[-1][1])%2==0:
            ans+=k-1
    print(ans)

else:
    print(k//2)
Buggy python submission (verdict: Runtime Error):
H,W,A,B=map(int,input().split())
Ans=[["0"]*W for _ in range(H)]
for i in range(A, W):
    for j in range(B):
        Ans[i][j]="1"
for i in range(A):
    for j in range(B,H):
        Ans[i][j]="1"
for a in Ans:
    moji="".join(a)
    print(moji)

Fixed submission:
H,W,A,B=map(int,input().split())
Ans=[["0"]*W for _ in range(H)]
if B>0:
    for i in range(A, W):
        for j in range(B):
            Ans[j][i]="1"
if A>0:
    for i in range(A):
        for j in range(B,H):
            Ans[j][i]="1"
for a in Ans:
    moji="".join(a)
    print(moji)
Buggy python submission (verdict: Time Limit Exceeded):
def z_arr(s):
    """An advanced computation of Z-values of a string."""
    # From https://ivanyu.me/blog/2013/10/15/z-algorithm/
 
    Z = [0] * len(s)
    Z[0] = len(s)
 
    rt = 0
    lt = 0
 
    for k in range(1, len(s)):
        if k > rt:
            # If k is outside the current Z-box, do naive computation.
            n = 0
            while n + k < len(s) and s[n] == s[n+k]:
                n += 1
            Z[k] = n
            if n > 0:
                lt = k
                rt = k+n-1
        else:
            # If k is inside the current Z-box, consider two cases.
 
            p = k - lt  # Pair index.
            right_part_len = rt - k + 1
 
            if Z[p] < right_part_len:
                Z[k] = Z[p]
            else:
                i = rt + 1
                while i < len(s) and s[i] == s[i - k]:
                    i += 1
                Z[k] = i - k
 
                lt = k
                rt = i - 1
    return Z
 
if __name__=="__main__":
    n=int(input())
    s=input()
    ans=0
    for i in range(len(s)):
        A=z_arr(s[i:])
        for a in range(len(A)):
            if A[a]<=a:
                ans=max(ans, A[a])
    print(ans)

Fixed submission:
N = int(input())
S = input()
 
 
r = 1
ans = 0
for l in range(N):
 
    while True:
        #print(S.rfind(S[l:r+1]), S[l:r+1], l, r)
 
        if S.rfind(S[l:r+1]) >= r+1:
            r += 1
            ans = max(ans, r-l)
        else:
            break
 
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
B=list(map(int,input().split()))
B.append(0)
A=[min(B[i],[i+1]) for i in range(n)]
print(sum(A))


Fixed submission:
N=int(input())
B=input().split()
B=[int(n) for n in B]
A=[]
A.append(B[0])
last=0
for i in range(N-2):
    last=B[i]
    if last>B[i+1]:
        A.append(B[i+1])
    else:
        A.append(last)
    last=B[i+1]
A.append(last)
if N>2:
    print(sum(A))
else:
    print(sum(B)*2)
Buggy python submission (verdict: Runtime Error):
tmp=1
for i in range(1,N):
    if S[i-1]==S[i]:
        tmp+=1
    else:
        A.append(tmp)
        tmp=1
A.append(tmp)
 
ans=sum(A)-len(A)+(K)*2
 
if ans<N-1:
    print(ans)
else: print(N-1)

Fixed submission:
N, K=map(int, input().split())
S=input()
A=[]
tmp=1
for i in range(1,N):
    if S[i-1]==S[i]:
        tmp+=1
    else:
        A.append(tmp)
        tmp=1
A.append(tmp)

ans=sum(A)-len(A)+(K)*2

if ans<N-1:
    print(ans)
else: print(N-1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K=map(int, input().split())
S=input()
A=[]
tmp=1
for i in range(1,N):
    if S[i-1]==S[i]:
        tmp+=1
    else:
        A.append(tmp)
        tmp=1
A.append(tmp)

while K>0:
    #print(A)
    K-=1
    tmpmax=0
    tmpindex=0
    if len(A)>2:
        for i in range(1,len(A)-1):
            tmp=A[i-1]+A[i]+A[i+1]
            if tmp>tmpmax:
                tmpindex=i
                tmpmax=tmp
        A[tmpindex]=tmpmax
        A.pop(tmpindex-1)
        A.pop(tmpindex)
    elif len(A)==2:
        K+=1
        break
    else: break

if len(A)>=2 and K==0:
    print(sum(A)-len(A))
else:
    print(N-1)

Fixed submission:
N, K=map(int, input().split())
S=input()
A=[]
tmp=1
for i in range(1,N):
    if S[i-1]==S[i]:
        tmp+=1
    else:
        A.append(tmp)
        tmp=1
A.append(tmp)

ans=sum(A)-len(A)+(K)*2

if ans<N-1:
    print(ans)
else: print(N-1)
Buggy python submission (verdict: Runtime Error):
n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
ab.sort(reverse=True)
import heapq
h = []
ans = 0
for i in range(1, m+1):
    print(h)
    while ab and ab[-1][0] == i:
        heapq.heappush(h,ab.pop()[1]*(-1))
    if h:
        ans -= heapq.heappop(h)
print(ans)

Fixed submission:
n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
ab.sort(reverse=True)
import heapq
h = []
ans = 0
for i in range(1, m+1):
    while ab and ab[-1][0] == i:
        heapq.heappush(h,ab.pop()[1]*(-1))
    if h:
        ans -= heapq.heappop(h)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
    
import heapq
ans=0
h=[]
for d in range(m-1, -1, -1):
    for v in ab:
        if v[0]<=m-d:
            heapq.heappush(h, v[1]*(-1)) 
    ab=[v for v in ab if v[0]>m-d]
    try:
        ans-=heapq.heappop(h)
    except IndexError:
        ans+=0
print(ans)

Fixed submission:
n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
ab.sort(reverse=True)
import heapq
h = []
ans = 0
for i in range(1, m+1):
    while ab and ab[-1][0] == i:
        heapq.heappush(h,ab.pop()[1]*(-1))
    if h:
        ans -= heapq.heappop(h)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
ans=0
for d in range(m-1, -1, -1):
    candidate=[i for i in ab if i[0]<=(m-d)]
    if candidate!=[]:
        get=max(list(i[1] for i in candidate))
        work=[t for t in candidate if t[1]==get] 
        ab.remove(work[0])
        ans+=get
print(ans)

Fixed submission:
n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
ab.sort(reverse=True)
import heapq
h = []
ans = 0
for i in range(1, m+1):
    while ab and ab[-1][0] == i:
        heapq.heappush(h,ab.pop()[1]*(-1))
    if h:
        ans -= heapq.heappop(h)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
dp=[[0]*13 for _ in range(len(s))]
if s[0]=='?':
  dp[0]=[1]*10+[0]*3
else:
  dp[0][int(s[0])]+=1

MOD=10**9+7
for i in range(1,len(s)):
  if s[i]=='?':
    for j in range(13):
      for k,l in enumerate([5,6,7,8,9]):
        dp[i][((j*10)%13+k)%13]+=dp[i-1][j]
        dp[i][((j*10)%13+k)%13]%=MOD
        dp[i][((j*10)%13+l)%13]+=dp[i-1][j]
        dp[i][((j*10)%13+l)%13]%=MOD
  else:
    k=int(s[i])
    for j in range(13):
      dp[i][((j*10)%13+k)%13]+=dp[i-1][j]
      dp[i][((j*10)%13+k)%13]%=MOD
print(dp[-1][5])

Fixed submission:
s=input()
dp=[[0]*13 for _ in range(len(s))]
if s[0]=='?':
  dp[0]=[1]*10+[0]*3
else:
  dp[0][int(s[0])]+=1

MOD=10**9+7
for i in range(1,len(s)):
  if s[i]=='?':
    for j in range(13):
      for k in range(10):
        dp[i][((j*10)%13+k)%13]+=dp[i-1][j]
        dp[i][((j*10)%13+k)%13]%=MOD
  else:
    k=int(s[i])
    for j in range(13):
      dp[i][((j*10)%13+k)%13]+=dp[i-1][j]
      dp[i][((j*10)%13+k)%13]%=MOD
print(dp[-1][5])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
dp=[[0]*13 for _ in range(len(s))]
if s[0]=='?':
  dp[0]=[1]*10+[0]*3
else:
  dp[0][int(s[0])]+=1

MOD=10**9+7
for i in range(1,len(s)):
  if s[i]=='?':
    for j in range(13):
      for k in range(10):
        dp[i][((j*10)%13+k)%13]+=dp[i-1][j]
        dp[i][((j*10)%13+k)%13]%=MOD
  else:
    k=int(s[i])
    for j in range(13):
      dp[i][((j*10)%13+k)%13]+=dp[i-1][j]
      dp[i][((j*10)%13+k)%13]%=MOD
print(dp[-1][5])

Fixed submission:
s=input()
dp=[[0]*13 for _ in range(len(s))]
if s[0]=='?':
  dp[0]=[1]*10+[0]*3
else:
  dp[0][int(s[0])]+=1

MOD=10**9+7
for i in range(1,len(s)):
  if s[i]=='?':
    for j in range(13):
      for k in range(10):
        dp[i][((j*10)%13+k)%13]+=dp[i-1][j]
        dp[i][((j*10)%13+k)%13]%=MOD
  else:
    k=int(s[i])
    for j in range(13):
      dp[i][((j*10)%13+k)%13]+=dp[i-1][j]
      dp[i][((j*10)%13+k)%13]%=MOD
print(dp[-1][5])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
M=10**9+7
import numpy as np
dp=np.zeros((len(s)+1,13),dtype="int64")
dp[0][0]=1
for i in range(-1,-len(s)-1,-1):
    dp[-i-1]%=M
    if s[i]!="?":
        a=(int(s[i])*(10**(-i-1)))%13
        for j in range(13):
            dp[-i][(j+a)%13]=dp[-i-1][j]
    elif s[i]=="?":
        dp[-i]=dp[-i-1]
        for k in range(1,10):
            a=k*(10**(-i-1))%13
            for j in range(13):
                dp[-i][(j+a)%13]+=(dp[-i-1][j])
print(dp[-1][5]%M)

Fixed submission:
s=input()
dp=[[0]*13 for _ in range(len(s))]
if s[0]=='?':
  dp[0]=[1]*10+[0]*3
else:
  dp[0][int(s[0])]+=1

MOD=10**9+7
for i in range(1,len(s)):
  if s[i]=='?':
    for j in range(13):
      for k in range(10):
        dp[i][((j*10)%13+k)%13]+=dp[i-1][j]
        dp[i][((j*10)%13+k)%13]%=MOD
  else:
    k=int(s[i])
    for j in range(13):
      dp[i][((j*10)%13+k)%13]+=dp[i-1][j]
      dp[i][((j*10)%13+k)%13]%=MOD
print(dp[-1][5])
Buggy python submission (verdict: Runtime Error):
s=int(input())
x1,y1=0,0

if s<=10**9:
  x2=1
  y3=s
  y2=0
  x3=0
elif: s==10**18:
    x2=0
    y2=10**9
    x3=10**9
    y3=0
else:
  x2=10**9
  y2=1
  a=s//x2
  b=s%x2
  y3=a+1
  x3=x2-b
print(x1, y1, x2, y2, x3, y3)

Fixed submission:
s=int(input())
x1,y1=0,0

if s<=10**9:
  x2=1
  y3=s
  y2=0
  x3=0
elif s==10**18:
    x2=0
    y2=10**9
    x3=10**9
    y3=0
else:
  x2=10**9
  y2=1
  a=s//x2
  b=s%x2
  y3=a+1
  x3=x2-b
print(x1, y1, x2, y2, x3, y3)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int, input().split()))
box=[0]*n
for i in range(n-1,-1,-1):
    if n//(i+1)<=1 and A[i]==1:
        box[i]=1
    elif n//(i+1)<=1 and A[i]==0:
        pass
    elif n//(i+1)>1:
        if A[i]==sum(box[2*(i+1)-1::(i+1)])%2:
            pass
        elif A[i]!=sum(box[2*(i+1)-1::(i+1)])%2:
            box[i]=1
ans=""
for i in range(n):
    if box[i]==1:
        ans+=str(A[i])+" "
if sum(box)%2==A[0]:
    print(sum(box))
    print(ans)
else: print("-1")

Fixed submission:
r=int(input())
print(3*(r**2))

Buggy python submission (verdict: Runtime Error):
r=int(input())
print(3*(a**2))

Fixed submission:
r=int(input())
print(3*(r**2))
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
if l-r>=673:
  print(0)
else:
  ans=float('inf')
  for i in range(l,r):
    for j in range(i+1,r+1):
      ans=min((i*j)%2019,ans)
  print(ans)


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

Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
if l-r>=673:
  print(0)
else:
  ans=float('inf')
  for i in range(l,r):
    for j in range(i+1,r+1):
      ans=min((i*j)%2019,ans)
  print(ans)


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

Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
if l-r>=673:
  print(0)
else:
  ans=float('inf')
  for i in range(l,r+1):
    for j in range(l,r+1):
      if i!=j:
        ans=min(i*j%2019,ans)
  print(ans)

Fixed submission:
l,r=map(int,input().split())
if abs(l-r)>=673:
  print(0)
else:
  ans=float('inf')
  for i in range(l,r):
    for j in range(i+1,r+1):
      ans=min((i*j)%2019,ans)
  print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int, input().split())
import math
n1=math.ceil(a/min(c,d))
if a<=min((c,d))*n1<=b:
    l1=(b-min((c,d))*n1)//min((c,d))+1
else: l1=0
  n2=math.ceil(a/max(c,d))
if a<=max((c,d))*n2<=b:
    l2=(b-max((c,d))*n2)//max((c,d))+1
else: l2=0
lcm=(c*d)//math.gcd(c, d)
n3=math.ceil(a/lcm)
if a<=lcm<=b:
    l3=(b-lcm)*n3//lcm+1
else: l3=0
ans=(b-a+1)-(l1+l2-l3)
print(ans)

Fixed submission:
a,b,c,d=map(int,input().split())
total=b-a+1
cdead=b//c-(a-1)//c
ddead=b//d-(a-1)//d
from fractions import gcd

def lcm(a,b):
    x= a*b // gcd(a,b)
    return x

z=lcm(c,d)
cddead=b//z-(a-1)//z
print(total-cdead-ddead+cddead)
Buggy python submission (verdict: Runtime Error):
w, h, x, y=map(int, input().split())
centX=w/2
centY=h/2
if x==centX and y==centY
    print(w*h/2, " ", "1")
else: print(w*h/2, " ", "0")

Fixed submission:
w, h, x, y=map(int, input().split())
centX=w/2
centY=h/2
if x==centX and y==centY:
    print(w*h/2, " ", "1")
else: print(w*h/2, " ", "0")
Buggy python submission (verdict: Runtime Error):
A, B=int(input())
if A>=13:
    print(B)
elif 6<=A<=12:
    print(B/2)
else:
    print(0)

Fixed submission:
A, B=map(int, input().split())
if A>=13:
    print(B)
elif 6<=A<=12:
    print(int(B/2))
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import numpy as np
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
A=np.array(A, dtype=np.int64)
BC=[]
for _ in range(m):
    b,c=map(int,input().split())
    BC.append((b,c))
BC=sorted(BC, reverse=True, key=lambda x: x[1])

for i in range(m):
    b,c=BC[i]
    ind=bisect.bisect_left(A, c)
    if ind>0:
        x,y=min(ind, b), max(ind, b)
        A=np.concatenate([A[x:y],np.array([c]*x,dtype=np.int64),A[y:]])
    else:
        break
print(sum(A))

Fixed submission:
import numpy as np
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
A=np.array(A, dtype=np.int64)
BC=[]
for _ in range(m):
    b,c=map(int,input().split())
    BC.append((b,c))
BC=sorted(BC,reverse=True, key=lambda x:x[1])
D=[]
cnt=0
for i in range(m):
    b,c=BC[i]
    cnt+=b
    D+=[c]*b
    if cnt>=n:
        break
if cnt>=n:
    D=D[:n]
else:
    D+=[0]*(n-cnt)
D=np.array(D, dtype=np.int64)

A=np.maximum(A,D)
print(np.sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
BC=[]
for _ in range(m):
    b,c=map(int,input().split())
    BC.append((b,c))
BC=sorted(BC, reverse=True, key=lambda x: x[1])

for i in range(m):
    b,c=BC[i]
    ind=bisect.bisect_left(A, c)
    if ind>0:
        x,y=min(ind, b), max(ind, b)
        A=A[x:y]+[c]*x+A[y:]
    else:
        break
print(sum(A))

Fixed submission:
import numpy as np
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
A=np.array(A, dtype=np.int64)
BC=[]
for _ in range(m):
    b,c=map(int,input().split())
    BC.append((b,c))
BC=sorted(BC,reverse=True, key=lambda x:x[1])
D=[]
cnt=0
for i in range(m):
    b,c=BC[i]
    cnt+=b
    D+=[c]*b
    if cnt>=n:
        break
if cnt>=n:
    D=D[:n]
else:
    D+=[0]*(n-cnt)
D=np.array(D, dtype=np.int64)

A=np.maximum(A,D)
print(np.sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
BC=[]
for _ in range(m):
    b,c=map(int,input().split())
    BC.append((b,c))
BC=sorted(BC, reverse=True, key=lambda x: x[1])

for i in range(m):
    b,c=BC[i]
    ind=bisect_left(A, c)
    x,y=min(ind, b), max(ind, b)
    A=A[x:y]+[c]*x+A[y:]
print(sum(A))

Fixed submission:
import numpy as np
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
A=np.array(A, dtype=np.int64)
BC=[]
for _ in range(m):
    b,c=map(int,input().split())
    BC.append((b,c))
BC=sorted(BC,reverse=True, key=lambda x:x[1])
D=[]
cnt=0
for i in range(m):
    b,c=BC[i]
    cnt+=b
    D+=[c]*b
    if cnt>=n:
        break
if cnt>=n:
    D=D[:n]
else:
    D+=[0]*(n-cnt)
D=np.array(D, dtype=np.int64)

A=np.maximum(A,D)
print(np.sum(A))
Buggy python submission (verdict: Runtime Error):
n, k=map(int, input(),split())
print(n-k+1)

Fixed submission:
n, k=map(int, input().split())
print(n-k+1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n==1:
    print(0)
pf={}
m=n
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
ans=[]
m=0
for i in range(1, int(n**0.5)+1):
    if n%i==0:
        m=n//i-1
        if n%m==i and n//m==i:
            ans.append(m)

#print(int(n**0.5))
print(sum(ans))

Fixed submission:
n=int(input())
if n==1:
    print(0)
else:
    pf={}
    m=n
    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:pf[m]=1
    ans=[]
    m=0
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            m=n//i-1
            if n%m==i and n//m==i:
                ans.append(m)

    #print(int(n**0.5))
    print(sum(ans))

Buggy python submission (verdict: Runtime Error):
n=int(input())
pf={}
m=n
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
ans=[]
m=0
for i in range(1, int(n**0.5)+1):
    if n%i==0:
        m=n//i-1
        if n%m==i and n//m==i:
            ans.append(m)

#print(int(n**0.5))
print(sum(ans))

Fixed submission:
n=int(input())
if n==1:
    print(0)
else:
    pf={}
    m=n
    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:pf[m]=1
    ans=[]
    m=0
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            m=n//i-1
            if n%m==i and n//m==i:
                ans.append(m)

    #print(int(n**0.5))
    print(sum(ans))