Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
l=[[0,0] for _ in range(m)]
for i in range(m):
    l[i][1],l[i][0]=map(int,input().split())

l=sorted(l)

ans=1
for _ in range(n-1):
    for i in l[1:]:
        if i[1]<l[0][0]:
            l.remove(i)
    l.remove(l[0])
    if len(l)!=0:
        ans+=1
    else:
        break

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
l=[[0,0] for _ in range(m)]
for i in range(m):
    l[i][1],l[i][0]=map(int,input().split())

l=sorted(l)

ans=1

c=l[0][0]
for i in range(m):
    if l[i][1]>=c:
        ans+=1
        c=l[i][0]
    else:
        continue
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
l=[[0,0] for _ in range(m)]
for i in range(m):
    l[i][1],l[i][0]=map(int,input().split())

l=sorted(l)

ans=1
for _ in range(n-1):
    ll=[]
    for i in l:
        if i[1]>=l[0][0]:
            ll.append(i)
    l=ll
    if len(l)!=0:
        ans+=1
    else:
        break

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
l=[[0,0] for _ in range(m)]
for i in range(m):
    l[i][1],l[i][0]=map(int,input().split())

l=sorted(l)

ans=1

c=l[0][0]
for i in range(m):
    if l[i][1]>=c:
        ans+=1
        c=l[i][0]
    else:
        continue
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[[0,0] for _ in range(m)]
for i in range(m):
    l[i][1],l[i][0]=map(int,input().split())

l=sorted(l)
ans=1
for _ in range(n-1):
    ll=[]
    for i in l:
        if i[1]>=l[0][0]:
            ll.append(i)
    l=ll
    if len(l)!=0:
        ans+=1
    else:
        break

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
l=[[0,0] for _ in range(m)]
for i in range(m):
    l[i][1],l[i][0]=map(int,input().split())

l=sorted(l)

ans=1

c=l[0][0]
for i in range(m):
    if l[i][1]>=c:
        ans+=1
        c=l[i][0]
    else:
        continue
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

ans=0
for _ in range(2*(10**4)):
    count=0
    for i in range(n):
        if a[i]%2!=0:
            a[i]*=3
            count+=1
        else:
            a[i]=a[i]//2
            break
    if count==n:
        break
    if count!=n:
        ans+=1
print(ans)

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

b=[]
for i in range(1,30):
    b.append(2**i)
#print(b)
ans=0
u=len(b)
for i in range(n):
    for j in range(u):
        if a[i]%b[j]==0:
            ans+=1
print(ans)

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

ans=0
for _ in range(10**5):
    count=0
    for i in range(n):
        if a[i]%2!=0:
            a[i]*=3
            count+=1
        else:
            a[i]=a[i]//2
            break
    if count==n:
        break
    if count!=n:
        ans+=1
print(ans)

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

b=[]
for i in range(1,30):
    b.append(2**i)
#print(b)
ans=0
u=len(b)
for i in range(n):
    for j in range(u):
        if a[i]%b[j]==0:
            ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=str(input())


ans=10**100
for i in range(n):
    a=s.count('W',0,i)
    b=s.count('E',i+1,n)
    if a+b<=ans:
        ans=a+b
print(ans)


Fixed submission:
n=int(input())
s=str(input())

l=[]
c=s.count('E',1)
for i in range(1,n):
    if s[i-1]=='W':
        c+=1
    if s[i]=='E':
        c-=1
    l.append(c)
print(min(min(l),s.count('E')))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
x=list(map(int,input().split()))
t=x
for i in range(n):
    x=x[:i]+x[i+1:]
    x.sort()
    #print(x)
    print(x[(n-1)//2])
    x=t
  

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
t=sorted(x)
m=n//2
a=t[m-1];b=t[m]
#print(a,b)
for i in range(n):
    if x[i]<=a:
        print(b)
    else:
        print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import itertools
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
c=[i for i in range(1,a[-1]+1)]

ans=0
for i in range(n-1):
    l=len(list(itertools.combinations(c,a[i])))
    if l>=ans:
        ans=l
        z=a[i]

print(a[-1],z)

Fixed submission:
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
if n%2==0:
    c=a[-1]//2
else:
    c=a[-1]//2+0.5
#print(c)
b=[]
for i in range(n):
    b.append(abs(c-a[i]))
#print(b)
c=min(b)
for i in range(n):
    if b[i]==c:
        print(a[-1],a[i])
        break
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k=map(int,input().split())
l=[i for i in range(a,b+1)]
#print(l)
s=[]
for i in range(len(l)):
    if i<=k-1 or len(l)-k<=i:
        print(l[i])

Fixed submission:
a,b,k=map(int,input().split())
c=[i for i in range(a,min(a+k,b+1))]
d=[i for i in range(max(a,b-k+1),b+1)]
e=c+d
e=list(set(e))
e.sort()
for i in range(len(e)):
    print(e[i])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[list(map(int, input().split())) for i in range(n-1)]

#print(l)
for i in range(n-1):
    t=l[i][1]+l[i][0]
    for j in range(i+1,n-1):
        if l[j][1]>=t:
            t=l[j][1]+l[j][0]
        elif l[j][1]<t:
            if (t-l[j][1])%l[j][2]==0:
                t+=l[j][0]
            else:
                e=l[j][1]
                while t>l[j][1]:
                    l[j][1]+=l[j][2]
                t=l[j][1]+l[j][0]
                l[j][1]=e
    print(t)
print(0)

        

Fixed submission:
n=int(input())
l=[list(map(int, input().split())) for i in range(n-1)]

#print(l)
for i in range(n-1):
    t=l[i][1]+l[i][0]
    for j in range(i+1,n-1):
        if l[j][1]>=t:
            t=l[j][1]+l[j][0]
        elif l[j][1]<t:
            if (t-l[j][1])%l[j][2]==0:
                t+=l[j][0]
            else:
                x=(t-l[j][1])//l[j][2]+1
                t=l[j][2]*x+l[j][1]+l[j][0]           
    print(t)
    #print(l)
print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
q=int(input())
x=[0]*q;y=[0]*q
for i in range(q):
    x[i],y[i]=map(int,input().split())
l=[]
for i in range(min(x),max(y)+1,2):
    d=prime_factorize(i)
    e=prime_factorize((i+1)//2)
    #print(d)
    if d==[i] and e==[(i+1)//2]:
        l.append(i)
#print(l)
for i in range(q):
    ans=0
    for j in range(len(l)):
        if x[i]<=l[j]<=y[i]:
            ans+=1
    print(ans)

Fixed submission:
import sys
imput=sys.stdin.readline
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
q=int(input())
x=[0]*q;y=[0]*q
for i in range(q):
    x[i],y[i]=map(int,input().split())
l=[]
for i in range(min(x),max(y)+1,2):
    d=prime_factorize(i)
    e=prime_factorize((i+1)//2)
    #print(d)
    if d==[i] and e==[(i+1)//2]:
        l.append(i)
#print(l)
for i in range(q):
    ans=0
    for j in range(len(l)):
        if x[i]<=l[j]<=y[i]:
            ans+=1
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
d.sort();t.sort()

for i in range(m):
    b2=bisect.bisect_right(d,t[i])
    #print(d,t,b2)
    if d[b2-1]!=t[i]:
        print('NO')
        break
    else:
        d=d[:b2-1]+d[b2:]
else:
    print('YES')

Fixed submission:
from collections import Counter
n=int(input())
d=Counter(map(int,input().split()))
m=int(input())
t=Counter(map(int,input().split()))
for i in t.keys():
    if d[i]<t[i]:
        print('NO')
        break
else:
    print('YES')

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

for i in range(m):
    if t[i] not in d:
        print('NO')
        break
    else:
        d.remove(t[i])
else:
    print('YES')

Fixed submission:
from collections import Counter
n=int(input())
d=Counter(map(int,input().split()))
m=int(input())
t=Counter(map(int,input().split()))
for i in t.keys():
    if d[i]<t[i]:
        print('NO')
        break
else:
    print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
imput=sys.stdin.readline
n=int(input())
c=[]
for i in range(n):
    a=int(input())
    if a not in c:
        c.append(a)
    else:
        c.remove(a)
print(len(c))

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
a.append(1000000001)
a.append(0)
a.sort()
c=0
ans=0
s=0
#print(a)
for i in range(1,n+2):
    if a[i]==c:
        s+=1
    else:
        ans+=(s%2)
        c=a[i]
        s=1
    #print(s)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
c=[]
for i in range(n):
    a=int(input())
    if a not in c:
        c.append(a)
    else:
        c.remove(a)
print(len(c))

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
a.append(1000000001)
a.append(0)
a.sort()
c=0
ans=0
s=0
#print(a)
for i in range(1,n+2):
    if a[i]==c:
        s+=1
    else:
        ans+=(s%2)
        c=a[i]
        s=1
    #print(s)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

l=[0]*(max(a)+1)
for i in range(n):
    l[a[i]-1]+=1
#print(l)
ans=0
for i in range(len(l)-2):
    ans=max(ans,l[i]+l[i+1]+l[i+2])
ans=max(ans,l[0]+l[1],l[-1]+l[-2])
print(ans)

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

l=[0]*(max(a)+1)
for i in range(n):
    l[a[i]]+=1
#print(l)
ans=0
for i in range(len(l)-2):
    ans=max(ans,l[i]+l[i+1]+l[i+2])
if len(l)==1:
    print(l[0])
elif len(l)==2:
    print(sum(l))
else:
    ans=max(ans,l[0]+l[1],l[-1]+l[-2])
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(str,input().split()))
l=[a[0]]
if n%2==0:
    for i in range(1,n):
        if i%2==1:
            l=[a[i]]+l
        else:
            l=l+[a[i]]
    print(" ".join(map(str,l)))
else:
    for i in range(1,n):
        if i%2==0:
            l=[a[i]]+l
        else:
            l=l+[a[i]]
    print(" ".join(map(str,l)))

Fixed submission:
from collections import deque
n=int(input())
a=list(map(str,input().split()))
l=deque()
if n%2==0:
    for i in range(n):
        if i%2==1:
            l.appendleft(a[i])
        else:
            l.append(a[i])
    print(" ".join(map(str,l)))
else:
    for i in range(n):
        if i%2==0:
            l.appendleft(a[i])
        else:
            l.append(a[i])
    print(" ".join(map(str,l)))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(str,input().split()))
b=str(a[0])
if n%2==0:
    for i in range(1,n):
        if i%2==1:
            b=a[i]+' '+b
        else:
            b=b+' '+a[i]
    print(b)
else:
    for i in range(1,n):
        if i%2==0:
            b=a[i]+' '+b
        else:
            b=b+' '+a[i]
    print(b)

Fixed submission:
from collections import deque
n=int(input())
a=list(map(str,input().split()))
l=deque()
if n%2==0:
    for i in range(n):
        if i%2==1:
            l.appendleft(a[i])
        else:
            l.append(a[i])
    print(" ".join(map(str,l)))
else:
    for i in range(n):
        if i%2==0:
            l.appendleft(a[i])
        else:
            l.append(a[i])
    print(" ".join(map(str,l)))
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
for i in range(m):
    if l[i][0]>l[i][1]:
        l[i][0],l[i][1]=l[i][1],l[i][0]
l.sort()
r=[0]*(n-1)
for i in range(m):
    for j in range(l[i][0]-1,l[i][1]-1):
        r[j]+=1
#print(r,l)
for i in range(n-1):
    if r[i]%2==1:
        print('NO')
        break
else:
    print('YES')


Fixed submission:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
a=[0]*n
for i in range(m):
    a[l[i][0]-1]+=1
    a[l[i][1]-1]+=1
for i in range(n):
    if a[i]%2==1:
        print('NO')
        break
else:
    print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
n,x=map(int,input().split())
if x==1 or x==2*n-1:
    print('No')
else:
    print('Yes')
    l=[]
    r=[1,x,2*n-1]
    for i in range(2,2*n-1):
        if i!=x:
            l.append(i)
    #print(l,r)
    for i in range(1,2*n):
        if i==n:
            print(x)
        elif i==n-1:
            print(1)
        elif i==n+1:
            print(2*n-1)
        else:
            print(l[0])
            l=l[1:]

Fixed submission:
n,x=map(int,input().split())
if x==1 or x==2*n-1:
    print('No')
else:
    print('Yes')
    if x<=n-1:
        for i in range(2,x):
            print(i)
        for i in range(x+1,n+1):
            print(i)
        print(1);print(x);print(2*n-1)
        for i in range(n+1,2*n-1):
            print(i)
    else:
        for i in range(2,n):
            print(i)
        print(1);print(x);print(2*n-1)
        for i in range(n,x):
            print(i)
        for i in range(x+1,2*n-1):
            print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[list(map(int, input().split())) for i in range(n)]
a=0
b=0
for i in range(n):
    x=l[i][0]
    y=l[i][1]
    while l[i][0]<a or l[i][1]<b:
        l[i][0]+=x
        l[i][1]+=y
    a=l[i][0]
    b=l[i][1]
print(sum(l[-1]))

Fixed submission:
n=int(input())
l=[list(map(int, input().split())) for i in range(n)]
for i in range(n-1):
    a=1
    b=1
    if l[i+1][0]<l[i][0]:
        a=-(-l[i][0]//l[i+1][0])
    if l[i+1][1]<l[i][1]:
        b=-(-l[i][1]//l[i+1][1])
    l[i+1][0]*=max(a,b)
    l[i+1][1]*=max(a,b)
print(sum(l[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[list(map(int, input().split())) for i in range(n)]
a=0
b=0
for i in range(n):
    x=l[i][0]
    y=l[i][1]
    while l[i][0]<a or l[i][1]<b:
        l[i][0]+=x
        l[i][1]+=y
    a=l[i][0]
    b=l[i][1]
print(sum(l[-1]))

Fixed submission:
n=int(input())
l=[list(map(int, input().split())) for i in range(n)]
for i in range(n-1):
    a=1
    b=1
    if l[i+1][0]<l[i][0]:
        a=-(-l[i][0]//l[i+1][0])
    if l[i+1][1]<l[i][1]:
        b=-(-l[i][1]//l[i+1][1])
    l[i+1][0]*=max(a,b)
    l[i+1][1]*=max(a,b)
print(sum(l[-1]))
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
a=int(a)
b=int(b)
if 0<=a<6:
  b=0
elif 6<=a<13:
  b=b//2
else:
  b=b
print(b)

Fixed submission:
a,b = map(int,input().split())
if 0<=a<6:
  b=0
elif 6<=a<13:
  b=b//2
else:
  b=b
print(b)

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
a=int(a)
if 0<=a<6:
  b=0
elif 6<=a<13:
  b=b/2
else:
  b=b
b=int(b)
print(b)

Fixed submission:
a,b = map(int,input().split())
if 0<=a<6:
  b=0
elif 6<=a<13:
  b=b//2
else:
  b=b
print(b)
Buggy python submission (verdict: Runtime Error):
A=input().split()
#array = [int(input()) for i in range(int(A))]
x = []
print(x[1])
print(A)
target ="DENIED"
for i in x:
  if x.index[i]%2 == 0:
    if x.index[i]%3 == 0 or x.index[i]%5 == 0:
      target = "APPROVED"
      break
print(target)


Fixed submission:
A=input().split()
x = input().split()
target ="APPROVED"
for i in x:
  if int(i)%2 == 0:
    if int(i)%3 > 0 and int(i)%5 > 0:
      target = "DENIED"
      break
print(target)
Buggy python submission (verdict: Runtime Error):
  args = input()
  print(args)
  if 'A' in args:
    if 'B' in args:
      print('Yes')
      exit()
  print('No')

Fixed submission:
args = input()
if 'A' in args:
  if 'B' in args:
    print('Yes')
    exit()
print('No')

Buggy python submission (verdict: Runtime Error):
args = input()
if 'A' not in args:
  print('No')
  return
if 'B' not in args:
  print('No')
  return
print('yes')
  


Fixed submission:
args = input()
if 'A' in args:
  if 'B' in args:
    print('Yes')
    exit()
print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = {}
for i in range(n):
    s = input()
    d[s] = d[s]+1 if (s in d) else 1
d_sorted = sorted(d.items(), key=lambda x:x[1], reverse=True)
m = d_sorted[0][1]
result = []
for i in range(n):
    if d_sorted[i][1]!=m:
        break
    result.append(d_sorted[i][0])
print(*sorted(result), sep='\n')

Fixed submission:
n = int(input())
d = {}
for i in range(n):
    s = input()
    d[s] = d[s]+1 if (s in d) else 1
d_sorted = sorted(d.items(), key=lambda x:x[1], reverse=True)
m = d_sorted[0][1]
result = []
for i in d_sorted:
    if i[1]!=m:
        break
    result.append(i[0])
print(*sorted(result), sep='\n')

Buggy python submission (verdict: Runtime Error):
n = int(input())
d = {}
for i in range(n):
    s = input()
    d[s] = d[s]+1 if (s in d) else 1
d_sorted = sorted(d.items(), key=lambda x:x[1], reverse=True)
m = d_sorted[0][1]
for i in range(n):
    if d_sorted[i][1]!=m:
        break
    print(d_sorted[i][0])

Fixed submission:
n = int(input())
d = {}
for i in range(n):
    s = input()
    d[s] = d[s]+1 if (s in d) else 1
d_sorted = sorted(d.items(), key=lambda x:x[1], reverse=True)
m = d_sorted[0][1]
result = []
for i in d_sorted:
    if i[1]!=m:
        break
    result.append(i[0])
print(*sorted(result), sep='\n')
Buggy python submission (verdict: Runtime Error):
input()
print(''.join([s+t for s,t in zip(input(),input())]))

Fixed submission:
N=int(input())
S=input()
print(''.join([S[i]+S[i+N+1] for i in range(N)]))
Buggy python submission (verdict: Runtime Error):
print("bad" if [ str(x)[0]==str(x)[1] or str(x)[1]==str(x)[2] or str(x)[2]==str(x)[3] for x in [int(input())] ] == [1] else "good")

Fixed submission:
print("Bad" if [ x[0]==x[1] or x[1]==x[2] or x[2]==x[3] for x in [str(input())] ] == [1] else "Good")
Buggy python submission (verdict: Runtime Error):
import numpy as np
W,H,x,y = map(float, input().split())
print("{0} {1}".format(W*H/2, 1 (x+x==W)and(y+y==H) else 0) )

Fixed submission:
import numpy as np
W,H,x,y = map(float, input().split())
print("{0} {1}".format(W*H/2, 1 if (x+x==W)and(y+y==H) else 0) )

Buggy python submission (verdict: Runtime Error):
import numpy as np
W,H,x,y = map(float, input().split())
print("{0} {1}".format(W*H/2, 1 (x+x=W)and(y+y=H) else 0) )

Fixed submission:
import numpy as np
W,H,x,y = map(float, input().split())
print("{0} {1}".format(W*H/2, 1 if (x+x==W)and(y+y==H) else 0) )
Buggy python submission (verdict: Time Limit Exceeded):
print("".join([ [ "{0}\n".format(NQ_S[1][0][LR[0]-1:LR[1]].count('AC')) for LR in [list(map(int, input().split())) for i in range(NQ_S[0][1])] ] for NQ_S in [[[int(x) for x in input().split()],[str(x) for x in input().split()]]] ][0])[:-1])

Fixed submission:
print("".join([ [ [ "{0}\n".format(NQ_S[2][LR[1]-1]-NQ_S[2][LR[0]-1]) for LR in  [list(map(int, input().split())) for i in range(NQ_S[0][1])]] for x in [[NQ_S[2].append(NQ_S[2][i-1]+1) if NQ_S[1][0][i-1]=='A' and NQ_S[1][0][i]=='C' else NQ_S[2].append(NQ_S[2][i-1]) for i in range(1,len(NQ_S[1][0]))]]] for NQ_S in [[[int(x) for x in input().split()],[str(x) for x in input().split()],[0]]] ][0][0])[:-1])
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
AB=[[int(x) for x in input().split()] for i in range(N)]
AB.sort(key=lambda x: x[0])
out = 0
count = M
for i in range(M):
    if AB[i][1]<count+1:
        count-=AB[i][1]
        out+=AB[i][0]*AB[i][1]
    else:
        out+=count*AB[i][0]
        break
print(out)

Fixed submission:
N,M=map(int,input().split())
AB=[[int(x) for x in input().split()] for i in range(N)]
AB.sort(key=lambda x: x[0])
out = 0
count = M
for i in range(N):
    if AB[i][1]<count+1:
        count-=AB[i][1]
        out+=AB[i][0]*AB[i][1]
    else:
        out+=count*AB[i][0]
        break
print(out)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
AB=[[int(x) for x in input().split()] for i in range(N)]
AB.sort(key=lambda x: x[0])
out = 0
count = M
for i in range(M):
    if AB[i][1]<count+1:
        count-=AB[i][1]
        out+=AB[i][0]*AB[i][1]
    else:
        out+=count*AB[i][0]
        break
print(out)

Fixed submission:
N,M=map(int,input().split())
AB=[[int(x) for x in input().split()] for i in range(N)]
AB.sort(key=lambda x: x[0])
out = 0
count = M
for i in range(N):
    if AB[i][1]<count+1:
        count-=AB[i][1]
        out+=AB[i][0]*AB[i][1]
    else:
        out+=count*AB[i][0]
        break
print(out)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
dp=[1000000000000000]*N
h=[int(x) for x in input().split()]
dp[0]=0
for i in range(N):
    dp=dp[:i] + ([x if x<dp[i]+abs(h[i+j]-h[i]) else dp[i]+abs(h[i+j]-h[i]) for j,x in enumerate(dp[i:(i+K+1 if i+K+1<N else N)])]) + (dp[i+K+1:] if i+K+1<N else [])
#    for j in range(i,i+K+1 if i+K+1 < N else N):
#        dp[j] = dp[j] if dp[j]<dp[i]+abs(h[j]-h[i]) else dp[i]+abs(h[j]-h[i])
print(dp[-1])

Fixed submission:
N,K=map(int,input().split())
dp=[1000000000000000 for i in range(N)]
h=[int(x) for x in input().split()]
dp[0]=0
for i in range(N):
    for j in range(i,i+K+1 if i+K+1 < N else N):
        dp[j] = dp[j] if dp[j]<dp[i]+abs(h[j]-h[i]) else dp[i]+abs(h[j]-h[i])
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
dp=[1000000000000000]*N
h=[int(x) for x in input().split()]
dp[0]=0
for i in range(N):
    dp=dp[:i] + ([x if x<dp[i]+abs(h[i+j]-h[i]) else dp[i]+abs(h[i+j]-h[i]) for j,x in enumerate(dp[i:(i+K+1 if i+K+1<N else N)])]) + (dp[i+K+1:] if i+K+1<N else [])
#    for j in range(i,i+K+1 if i+K+1 < N else N):
#        dp[j] = dp[j] if dp[j]<dp[i]+abs(h[j]-h[i]) else dp[i]+abs(h[j]-h[i])
    print(dp)

Fixed submission:
N,K=map(int,input().split())
dp=[1000000000000000 for i in range(N)]
h=[int(x) for x in input().split()]
dp[0]=0
for i in range(N):
    for j in range(i,i+K+1 if i+K+1 < N else N):
        dp[j] = dp[j] if dp[j]<dp[i]+abs(h[j]-h[i]) else dp[i]+abs(h[j]-h[i])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
dp=[1000000000000000 for i in range(N)]
h=[int(x) for x in input().split()]
dp[0]=0
for i in range(N):
    for j in range(i,i+K+1 if i+K+1 < N else N):
        dp[j] = dp[j] if dp[j]<dp[i]+abs(h[j]-h[i]) else dp[i]+abs(h[j]-h[i])
print(dp[-1])

Fixed submission:
N,K=map(int,input().split())
dp=[1000000000000000 for i in range(N)]
h=[int(x) for x in input().split()]
dp[0]=0
for i in range(N):
    for j in range(i,i+K+1 if i+K+1 < N else N):
        dp[j] = dp[j] if dp[j]<dp[i]+abs(h[j]-h[i]) else dp[i]+abs(h[j]-h[i])
print(dp[-1])