Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Edges = list(map(int,input().split()))

Edges=sorted(Edges)
cnt =0
# for i in c:
#     e1=(i[1] + i[2])
#     e2=(i[0] + i[2])
#     e3=(i[0] + i[1])

#     if i[0] < e1 and i[1] < e2 and i[2] < e3:
#         cnt+=1

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        list_ab = list(filter(lambda x : x > Edges[b] and x < ab ,Edges))
        cnt += max(0,len(list_ab))


print(cnt)

Fixed submission:
N=int(input())
Edges = list(map(int,input().split()))

Edges=sorted(Edges)
cnt =0
# for i in c:
#     e1=(i[1] + i[2])
#     e2=(i[0] + i[2])
#     e3=(i[0] + i[1])

#     if i[0] < e1 and i[1] < e2 and i[2] < e3:
#         cnt+=1


import bisect

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        idx = bisect.bisect_left(Edges,ab)

        cnt += max(0,idx-b-1)


print(cnt)

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

Edges=sorted(Edges)
cnt =0
# for i in c:
#     e1=(i[1] + i[2])
#     e2=(i[0] + i[2])
#     e3=(i[0] + i[1])

#     if i[0] < e1 and i[1] < e2 and i[2] < e3:
#         cnt+=1

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        list_ab = list(filter(lambda x : x > Edges[b] and x < ab ,Edges))
        cnt += max(0,len(list_ab))


print(cnt)

Fixed submission:
N=int(input())
Edges = list(map(int,input().split()))

Edges=sorted(Edges)
cnt =0
# for i in c:
#     e1=(i[1] + i[2])
#     e2=(i[0] + i[2])
#     e3=(i[0] + i[1])

#     if i[0] < e1 and i[1] < e2 and i[2] < e3:
#         cnt+=1


import bisect

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        idx = bisect.bisect_left(Edges,ab)

        cnt += max(0,idx-b-1)


print(cnt)

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

from itertools import combinations

c =list(combinations(Edges,3))

cnt =0
for i in c:
    e1=(i[1] + i[2])
    e2=(i[0] + i[2])
    e3=(i[0] + i[1])

    if i[0] < e1 and i[1] < e2 and i[2] < e3:
        cnt+=1

print(cnt)

Fixed submission:
N=int(input())
Edges = list(map(int,input().split()))

Edges=sorted(Edges)
cnt =0
# for i in c:
#     e1=(i[1] + i[2])
#     e2=(i[0] + i[2])
#     e3=(i[0] + i[1])

#     if i[0] < e1 and i[1] < e2 and i[2] < e3:
#         cnt+=1


import bisect

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        idx = bisect.bisect_left(Edges,ab)

        cnt += max(0,idx-b-1)


print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())

import numpy as np



points=np.array([K]*N)

for i in range(Q):
    a = int(input())
    a=a-1
    points=points-1

    points[a]+=1


for j in points:
    if j>0:
        print('Yes')
    else:
        print('No')

Fixed submission:
N,K,Q = map(int,input().split())

import numpy as np

points=np.array([K]*N)
dis = np.array([0]*N)
for i in range(Q):
    a = int(input())
    a=a-1
    dis[a]+=1

points-=Q
points += dis

for j in points:
    if j>0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
prod = list(map(int,input().split()))


prod = sorted(prod,reverse=True)

for _ in range(m):
    prod[0]=prod[0]//2

    prod=sorted(prod,reverse=True)



print(sum(prod))

Fixed submission:
import heapq

n,m = map(int,input().split())
prod = list(map(int,input().split()))
prod = list(map(lambda x: x*(-1),prod))

heapq.heapify(prod)

for _ in range(m):
    a = heapq.heappop(prod)*(-1)

    a = a//2

    heapq.heappush(prod,(-1)*a)


ans = list(map(lambda x: (-1)*x,prod))

print(sum(ans))
Buggy python submission (verdict: Runtime Error):
N=int(input())

seq=[]

for i in range(N):

    a= int(input())
    
    seq.append(a)

numbers=set(seq)
numbers=sorted(numbers,reverse=True)

A_max=numbers[0]

if len(numbers)>=2:
    A_second = numbers[1]

for k in range(N):
    if seq[k]==A_max:
        print(A_second)
    else:
        print(A_max)

# 2.両端から
# left=[0]
# for i in range(N-1):
#     left_i=max(left[i],seq[i])

#     left.append(left_i)

# right=[0]

# for j in range(N-1):
#     right_j = max(right[j],list(reversed(seq))[j])

#     right.append(right_j)

# right = list(reversed(right))

# for k in range(N):
#     print(max(left[k],right[k]))

Fixed submission:
N=int(input())

seq=[]

for i in range(N):
    a= int(input())
    seq.append(a)

import heapq

tmp=list(map(lambda x: x*(-1),seq))
heapq.heapify(tmp)

a=heapq.heappop(tmp)*(-1)
b=heapq.heappop(tmp)*(-1)

for j in range(N):
    if seq[j]==a:
        print(b)
    else:
        print(a)

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

seq=[]

for i in range(N):

    a= int(input())
    
    seq.append(a)

left=[0]
for i in range(N-1):
    left_i=max(left[i],seq[i])

    left.append(left_i)

right=[0]

for j in range(N-1):
    right_j = max(right[j],list(reversed(seq))[j])

    right.append(right_j)

right = list(reversed(right))

for k in range(N):
    print(max(left[k],right[k]))

Fixed submission:
N=int(input())

seq=[]

for i in range(N):
    a= int(input())
    seq.append(a)

import heapq

tmp=list(map(lambda x: x*(-1),seq))
heapq.heapify(tmp)

a=heapq.heappop(tmp)*(-1)
b=heapq.heappop(tmp)*(-1)

for j in range(N):
    if seq[j]==a:
        print(b)
    else:
        print(a)

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

seq=[]

for i in range(N):

    a= int(input())
    
    seq.append(a)

left=[0]
for i in range(N-1):
    left_i=max(left[i],seq[i])

    left.append(left_i)

right=[0]

for j in range(N-1):
    right_j = max(right[j],list(reversed(seq))[j])

    right.append(right_j)

right = list(reversed(right))

for k in range(N):
    print(max(left[k],right[k]))

Fixed submission:
N=int(input())

seq=[]

for i in range(N):
    a= int(input())
    seq.append(a)

import heapq

tmp=list(map(lambda x: x*(-1),seq))
heapq.heapify(tmp)

a=heapq.heappop(tmp)*(-1)
b=heapq.heappop(tmp)*(-1)

for j in range(N):
    if seq[j]==a:
        print(b)
    else:
        print(a)

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

import numpy as np
seq=np.array([])

for i in range(N):

    a= int(input())
    
    seq=np.append(seq,a)

index=np.argsort(seq)[::-1]
for j in range(N):
    if index[0]==j:
        print(int(seq[index[1]]))
    else:
        print(int(seq[index[0]]))


Fixed submission:
N=int(input())

seq=[]

for i in range(N):
    a= int(input())
    seq.append(a)

import heapq

tmp=list(map(lambda x: x*(-1),seq))
heapq.heapify(tmp)

a=heapq.heappop(tmp)*(-1)
b=heapq.heappop(tmp)*(-1)

for j in range(N):
    if seq[j]==a:
        print(b)
    else:
        print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
totals=[0]*n

for i in range(n-1,-1,-1):
    if totals[i]%2==a[i]:
        continue
    else:
        ans[i]+=1
        tmp=1
        while tmp*tmp<=i+1:
            if (i+1)%tmp==0:
                totals[tmp-1]+=1
                if tmp !=(i+1)//tmp:
                    totals[((i+1)//tmp)-1]+=1

            tmp+=1


cnt=ans.count(1)

print(cnt)
if cnt!=0:
    b=[]
    for j in range(n):
        if ans[j]==1:
            b.append(j+1)

    print(*b)
    

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
totals=[0]*n


def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


for i in range(n-1,-1,-1):
    if totals[i]%2==a[i]:
        continue
    else:
        ans[i]+=1
        arr=make_divisors(i+1)

        for num in arr:
            totals[num-1]+=1

cnt=ans.count(1)

print(cnt)
if cnt!=0:
    b=[]
    for j in range(n):
        if ans[j]!=0:
            b.append(j+1)

    print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
totals=[0]*n


def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


for i in range(n-1,-1,-1):
    if totals[i]%2==a[i]:
        continue
    else:
        ans[i]+=1
        arr=make_divisors(i+1)

        for num in arr:
            totals[num-1]+=1

cnt=ans.count(1)

print(cnt)
if cnt!=0:
    b=[]
    for j in range(n):
        if ans[j]!=0:
            b.append(j+1)

    print(*b)
    


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
totals=[0]*n


def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


for i in range(n-1,-1,-1):
    if totals[i]%2==a[i]:
        continue
    else:
        ans[i]+=1
        arr=make_divisors(i+1)

        for num in arr:
            totals[num-1]+=1

cnt=ans.count(1)

print(cnt)
if cnt!=0:
    b=[]
    for j in range(n):
        if ans[j]!=0:
            b.append(j+1)

    print(*b)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

from collections import Counter

c=Counter(a)

v=list(c.values())
k=list(c.keys())

v=sorted(v)

ans='Yes'
if len(k)==3:
    for i in range(3):
        if v[i]!=n/3:
            ans='No'
            break
elif len(k)==2:
    for j in range(2):
        if v[j]!=n/3 and j==0:
            ans='No'
        elif v[j]!=2*n/3 andj==1:
            ans='No'
elif len(k)==1 and k[0]==0:
    ans='Yes'
else:
    ans='No'

print(ans)

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

ans='No'
from collections import Counter

c=Counter(a)
keys = list(c.keys())
values =list(c.values())

if keys==[0]:
    ans='Yes'
elif len(keys)==3 and values[0]==n/3 and values[1]==n/3 and keys[0]^keys[1]==keys[2]:
    ans='Yes'
elif len(keys)==2 and c[0]==n/3:
    ans='Yes'

print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

from collections import Counter

c=Counter(a)

if len(list(c.keys())) ==3:
    if list(c.values())==[n//3,n//3,n//3]:
        print('Yes')
elif len(list(c.keys()))==2:
    if c.most_common()[0][1]==2*n//3:
        print('Yes')
elif len(list(c.keys()))==1:
    if c.keys()[0]==0:
        print('Yes')
else:
    print('No')

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

ans='No'
from collections import Counter

c=Counter(a)
keys = list(c.keys())
values =list(c.values())

if keys==[0]:
    ans='Yes'
elif len(keys)==3 and values[0]==n/3 and values[1]==n/3 and keys[0]^keys[1]==keys[2]:
    ans='Yes'
elif len(keys)==2 and c[0]==n/3:
    ans='Yes'

print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
from fractions import math

lcm = c*d//math.gcd(c,d)

num_b_c = b//c
num_b_d = b//d
num_b_cd = b//lcm

if a%c==0:
    num_a_c = a//c - 1
else:
    num_a_c = a//c

if a%d==0:
    num_a_d = a//d - 1
else:
    num_a_d = a//d

if a%lcm==0:
    num_a_cd = a//lcm - 1 
else:

    num_a_cd = a//lcm


alls = b - a + 1


c_div = num_b_c - num_a_c
d_div = num_b_d - num_a_d

cd_div = num_b_cd -num_a_cd


print(alls - ( c_div + d_div - cd_div))



Fixed submission:
a,b,c,d = map(int,input().split())
from fractions import gcd

lcm = c*d//gcd(c,d)

num_b_c = b//c
num_b_d = b//d
num_b_cd = b//lcm

if a%c==0:
    num_a_c = a//c - 1
else:
    num_a_c = a//c

if a%d==0:
    num_a_d = a//d - 1
else:
    num_a_d = a//d

if a%lcm==0:
    num_a_cd = a//lcm - 1 
else:

    num_a_cd = a//lcm


alls = b - a + 1


c_div = num_b_c - num_a_c
d_div = num_b_d - num_a_d

cd_div = num_b_cd -num_a_cd


print(alls - ( c_div + d_div - cd_div))
Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(int,input().split())

flg = 0
s=0

if x<=w/2 and y <= h/2:
    if x*h==w*y:
        flg=1
    s = max(x*h,w*y)

elif x<=w/2 and y>h/2:
    if x*h==w*(h-y):
        flg=1
    s = max(x*h,w*(h-y))
    
elif x>w/2 and y <= h/2:
    if (w-x)*h==w*y:
        flg==1:

    s = max( (w-x)*h , w*y)

elif x>w/2 and y > h/2:
    if (w-x)*h==w*(h-y):
        flg=1

    s = max( (w-x)*h, w*(h-y))

# if  x==w/2 and y==h/2:
#     flg = 1

# if w==h and x==y:
#     flg ==1

print(s,flg)

Fixed submission:
w,h,x,y = map(int,input().split())

print(w*h/2, 1 if x==w/2 and y==h/2 else 0)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a = []

mod = 1000000007

dp=[0]*(n+1)

dp[0]=1
dp[1]=1

for _ in range(m):
    s = int(input())
    a.append(s)

    dp[s]=0


for i in range(2,n+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%mod) 


Fixed submission:
n,m=map(int,input().split())
a = []

mod = 1000000007

dp=[0]*(n+1)

dp[0]=1
dp[1]=1
d={}
for j in range(n+1):
    d[j]=0

for _ in range(m):
    s = int(input())
    d[s]=1
    dp[s]=0

for i in range(2,n+1):
    if d[i]==1:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%mod)

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

mod = 1000000007

dp=[0]*(n+1)

dp[0]=1
dp[1]=1

for _ in range(m):
    s = int(input())
    a.append(s)

    dp[s]=0


for i in range(2,n+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%mod) 


Fixed submission:
n,m=map(int,input().split())
a = []

mod = 1000000007

dp=[0]*(n+1)

dp[0]=1
dp[1]=1
d={}
for j in range(n+1):
    d[j]=0

for _ in range(m):
    s = int(input())
    d[s]=1
    dp[s]=0

for i in range(2,n+1):
    if d[i]==1:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%mod)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a = []

mod = 1_000_000_007

dp=[0]*(n+1)

dp[0]=1
dp[1]=1

for _ in range(m):
    s = int(input())
    a.append(s)

    dp[s]=0


for i in range(2,n+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%mod) 


Fixed submission:
n,m=map(int,input().split())
a = []

mod = 1000000007

dp=[0]*(n+1)

dp[0]=1
dp[1]=1
d={}
for j in range(n+1):
    d[j]=0

for _ in range(m):
    s = int(input())
    d[s]=1
    dp[s]=0

for i in range(2,n+1):
    if d[i]==1:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())

cards=set([i+1 for i in range(n)])


for j in range(m):

    l,r = map(int,input().split())

    gates = set([j for j in range(l,r+1)])

    cards = cards&gates


print(len(cards))



Fixed submission:
n,m=map(int,input().split())
l = 1
r = n
for j in range(m):

    l_i,r_i = map(int,input().split())

    l = max(l,l_i)
    r = min (r,r_i)

if r>=l:
    print(r-l+1)
else:
    print(0)

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

cards=set([i+1 for i in range(n)])


for j in range(m):

    l,r = map(int,input().split())

    gates = set([j for j in range(l,r+1)])

    cards = cards&gates


print(len(cards))



Fixed submission:
n,m=map(int,input().split())
l = 1
r = n
for j in range(m):

    l_i,r_i = map(int,input().split())

    l = max(l,l_i)
    r = min (r,r_i)

if r>=l:
    print(r-l+1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int,input().split())


cnt=0
for i in range(n+1):
    for j in range(n+1):

        hB = n - (r*i) - (j*g)

        if hB >= 0 and hB%b==0:
            cnt+=1

print(cnt)


Fixed submission:
r,g,b,n = map(int,input().split())


cnt=0
for i in range(n+1):
    for j in range(n+1):

        hB = n - (r*i) - (j*g)

        if hB >= 0 and hB%b==0:
            cnt+=1

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


from math import floor
total=0
for m in range(1,n):
    if floor(n/m)==n%m:
        total+=m

print(total)


Fixed submission:
n=int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

arr = make_divisors(n)
total=0
for m in arr:
    r = n//m

    if r<m-1:
        total +=m-1


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

v = list(map(int,input().split()))
c = list(map(int,input().split()))


x_y = 0
for i in range(2**n):

    tmp_x_y = 0
    tmp_cost=0
    tmp_value=0

    for j in range(n):
        if (i>>j) &1:
            tmp_cost+=c[j]
            tmp_value+=v[j]

    tmp_x_y = tmp_value - tmp_cost

    x_y = max(x_y,tmp_x_y)

print(x_y)

Fixed submission:
n= int(input())

v = list(map(int,input().split()))
c = list(map(int,input().split()))


x_y = 0
for i in range(2**n):

    tmp_x_y = 0
    tmp_cost=0
    tmp_value=0

    for j in range(n):
        if (i>>j) &1:
            tmp_cost+=c[j]
            tmp_value+=v[j]

    tmp_x_y = tmp_value - tmp_cost

    x_y = max(x_y,tmp_x_y)

print(x_y)
Buggy python submission (verdict: Time Limit Exceeded):
n,q =map(int,input().split())
s = input()

d= {}

for k in range(n):
    d[k]=0

for j in range(n):
    if j ==n-1:
        tmp_str = s[j]
    else:
        tmp_str = s[j:]

    d[j] += tmp_str.count('AC')

# print(d)

ans = []
for _ in range(q):
    l,r = map(int,input().split())

    ans.append(d[l-1] -d[r-1])


for i in ans:
    print(i)

Fixed submission:
n,q =map(int,input().split())
s = input()

d= {}

for k in range(n):
    d[k]=0

total = 0
for j in range(n-1):
    if s[j]=='A' and s[j+1]=='C':
        total+=1
        d[j+1]+=total
    else:
        d[j+1]=total
        
# print(d)

ans = []
for _ in range(q):
    l,r = map(int,input().split())

    ans.append(d[r-1] -d[l-1])


for i in ans:
    print(i)

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

d= {}

for k in range(n-1):
    d[k]=0

for j in range(n-1):
    if s[j:j+2]=='AC':
        d[j]+=1

# print(d)

ans = []
for _ in range(q):
    l,r = map(int,input().split())

    tmp = 0
    for p in range(l-1 , r-1):
        tmp+=d[p]

    ans.append(tmp)



for i in ans:
    print(i)

Fixed submission:
n,q =map(int,input().split())
s = input()

d= {}

for k in range(n):
    d[k]=0

total = 0
for j in range(n-1):
    if s[j]=='A' and s[j+1]=='C':
        total+=1
        d[j+1]+=total
    else:
        d[j+1]=total
        
# print(d)

ans = []
for _ in range(q):
    l,r = map(int,input().split())

    ans.append(d[r-1] -d[l-1])


for i in ans:
    print(i)

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

ans = []
for _ in range(q):
    l,r = map(int,input().split())

    tmp_str = s[l-1:r]

    ans.append( tmp_str.count('AC') )

for i in ans:
    print(i)

Fixed submission:
n,q =map(int,input().split())
s = input()

d= {}

for k in range(n):
    d[k]=0

total = 0
for j in range(n-1):
    if s[j]=='A' and s[j+1]=='C':
        total+=1
        d[j+1]+=total
    else:
        d[j+1]=total
        
# print(d)

ans = []
for _ in range(q):
    l,r = map(int,input().split())

    ans.append(d[r-1] -d[l-1])


for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

d={}

for i in range(n):
    A,B=map(int,input().split())

    if A in d:
        d[A]+=B
    else:
        d[A]=B

l = sorted(list(d.items()),key=lambda x: x[0])

total=0
cnt=0

for i in range(n):
    total+=l[i][0]*l[i][1]

    cnt+=l[i][1]

    if cnt>m:
        total -= l[i][0]*(cnt-m)
        print(total)
        exit(0) 

print(total)


Fixed submission:
n,m=map(int,input().split())

d={}

for i in range(n):
    A,B=map(int,input().split())

    if A in d:
        d[A]+=B
    else:
        d[A]=B

l = sorted(list(d.items()),key=lambda x: x[0])

total=0
cnt=0

for i in range(len(l)):
    total+=l[i][0]*l[i][1]

    cnt+=l[i][1]

    if cnt>m:
        total -= l[i][0]*(cnt-m)
        print(total)
        exit(0) 

print(total)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

d={}

for i in range(n):
    A,B=map(int,input().split())

    d[A]=B

l = sorted(list(d.items()),key=lambda x: x[0])

total=0
cnt=0
for i in range(n):
    total+=l[i][0]*l[i][1]

    cnt+=l[i][1]

    if cnt>m:
        total -= l[i][0]*(cnt-m)
        print(total)
        exit(0) 

print(total)


Fixed submission:
n,m=map(int,input().split())

d={}

for i in range(n):
    A,B=map(int,input().split())

    if A in d:
        d[A]+=B
    else:
        d[A]=B

l = sorted(list(d.items()),key=lambda x: x[0])

total=0
cnt=0

for i in range(len(l)):
    total+=l[i][0]*l[i][1]

    cnt+=l[i][1]

    if cnt>m:
        total -= l[i][0]*(cnt-m)
        print(total)
        exit(0) 

print(total)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
H=list(map(int,input().split()))

import numpy as np
dp = np.ones(N+1,dtype=float)*float('inf')
dp[0]=0
dp[1]=0
    

for i in range(N):
    if i!=0:
        for k in range(K):
            if i-k>=1:
                dp[i+1] = min ( dp[i+1] ,dp[i-k] + abs(H[i]-H[i-(k+1)]) )
print(int(dp[N]))
# print(dp)

Fixed submission:
N,K=map(int,input().split())
H=list(map(int,input().split()))

dp = [float('inf')]*(N+1)
dp[0]=0
dp[1]=0
    

for i in range(N):
    if i!=0:
        for k in range(K):
            if i-k>=1:
                dp[i+1] = min ( dp[i+1] ,dp[i-k] + abs(H[i]-H[i-(k+1)]) )
print(int(dp[N]))
# print(dp)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
H=list(map(int,input().split()))

import numpy as np
dp = np.ones(N+1,dtype=float)*float('inf')
dp[0]=0
dp[1]=0
    

for i in range(N):
    if i!=0:
        for k in range(K):
            if i-k>=1:
                dp[i+1] = min ( dp[i+1] ,dp[i-k] + abs(H[i]-H[i-(k+1)]) )
print(int(dp[N]))
# print(dp)

Fixed submission:
N,K=map(int,input().split())
H=list(map(int,input().split()))

dp = [float('inf')]*(N+1)
dp[0]=0
dp[1]=0
    

for i in range(N):
    if i!=0:
        for k in range(K):
            if i-k>=1:
                dp[i+1] = min ( dp[i+1] ,dp[i-k] + abs(H[i]-H[i-(k+1)]) )
print(int(dp[N]))
# print(dp)

Buggy python submission (verdict: Runtime Error):
import numpy as np

#入力
N,K=map(int,input().split())
H=list(map(int,input().split()))

dp = np.ones(N+1,dtype=float)*float('inf')
dp[0]=0
dp[1]=0
    

for i in range(N):
    if i!=0:
        for k in range(K):
            if i-k>=1:
                dp[i+1] = min ( dp[i+1] ,dp[i-k] + abs(H[i]-H[i-(k+1)]) )
print(int(dp[N]))
# print(dp)

Fixed submission:
N,K=map(int,input().split())
H=list(map(int,input().split()))

dp = [float('inf')]*(N+1)
dp[0]=0
dp[1]=0
    

for i in range(N):
    if i!=0:
        for k in range(K):
            if i-k>=1:
                dp[i+1] = min ( dp[i+1] ,dp[i-k] + abs(H[i]-H[i-(k+1)]) )
print(int(dp[N]))
# print(dp)