Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
# wv_list = [tuple(map(int,input().split())) for _ in range(N)]
w_list = []
v_list = []
for i in range(N):
    w,v = map(int,input().split())
    w_list.append(w)
    v_list.append(v)

memo = [[None  for _ in range(W+1)] for _ in range(N+1)]

def rec(check_item,residual_w):
    if memo[check_item][residual_w]:
        return memo[check_item][residual_w]    
    if check_item == N:
        res = 0
    elif residual_w < w_list[check_item]:
        res = rec(check_item+1, residual_w)
    else:
#         print(check_item,residual_w)
        res = max(rec(check_item+1,residual_w),
                  rec(check_item+1,residual_w-w_list[check_item])+v_list[check_item])
    memo[check_item][residual_w] = res
    
    return res

print(rec(0,W))

Fixed submission:
N,W = map(int,input().split())
wv_list = [tuple(map(int,input().split())) for _ in range(N)]

memo = [0  for _ in range(W+1)]

for weight,value in wv_list:
    for w in range(W+1)[::-1]:
        if w  >= weight:
            memo[w] = max(memo[w], memo[w-weight]+value)
            
print(memo[W])
Buggy python submission (verdict: Runtime Error):
S = input()
l = len(S)
diff = 999

for i in range(0,S-2):
    n = int(S[i:i+3])
    if diff > abs(753-n):
        diff = abs(753-n)
    
print(diff)

Fixed submission:
S = input()
l = len(S)
diff = 999

for i in range(0,l-2):
    n = int(S[i:i+3])
    if diff > abs(753-n):
        diff = abs(753-n)
    
print(diff)

Buggy python submission (verdict: Runtime Error):
S = input()

diff = 999

for i in range(0,8):
    n = int(S[i:i+3])
    if diff > abs(753-n):
        diff = abs(753-n)
    
print(diff)

Fixed submission:
S = input()
l = len(S)
diff = 999

for i in range(0,l-2):
    n = int(S[i:i+3])
    if diff > abs(753-n):
        diff = abs(753-n)
    
print(diff)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
S = input()
T = input()

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x
 
def lcm(x, y):
    return int(x/gcd(x, y)*y)

lenx = lcm(N,M)

s_list = list(S)
t_list = list(T)

baisuu_s = lenx/N
baisuu_t = lenx/M
def check():
    for i in range(0,lenx,baisuu_s):
        if i % baisuu_s==0 and i%baisuu_t == 0:
            if s_list[int(i/baisuu_s)] == t_list[int(i/baisuu_t)]:
                pass
            else:
                return False
    return True

if check():
    print(lenx)
else:
    print(-1)

Fixed submission:
N,M = map(int,input().split())
S = input()
T = input()

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x
 
def lcm(x, y):
    return int(x/gcd(x, y)*y)

lenx = lcm(N,M)

s_list = list(S)
t_list = list(T)

baisuu_s = int(lenx/N)
baisuu_t = int(lenx/M)
def check():
    for i in range(0,lenx,baisuu_s):
        if i % baisuu_s==0 and i%baisuu_t == 0:
            if s_list[int(i/baisuu_s)] == t_list[int(i/baisuu_t)]:
                pass
            else:
                return False
    return True

if check():
    print(lenx)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
S = input()
T = input()

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x
 
def lcm(x, y):
    return int(x/gcd(x, y)*y)

lenx = lcm(N,M)

s_list = list(S)
t_list = list(T)

baisuu_s = lenx/N
baisuu_t = lenx/M
def check():
    for i in range(0,lenx):
        if i % baisuu_s==0 and i%baisuu_t == 0:
            if s_list[int(i/baisuu_s)] == t_list[int(i/baisuu_t)]:
                pass
            else:
                return False
    return True

if check():
    print(lenx)
else:
    print(-1)

Fixed submission:
N,M = map(int,input().split())
S = input()
T = input()

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x
 
def lcm(x, y):
    return int(x/gcd(x, y)*y)

lenx = lcm(N,M)

s_list = list(S)
t_list = list(T)

baisuu_s = int(lenx/N)
baisuu_t = int(lenx/M)
def check():
    for i in range(0,lenx,baisuu_s):
        if i % baisuu_s==0 and i%baisuu_t == 0:
            if s_list[int(i/baisuu_s)] == t_list[int(i/baisuu_t)]:
                pass
            else:
                return False
    return True

if check():
    print(lenx)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
from math import ceil

D,G = map(int,input().split())

pc_list = [[i]+list(map(int,input().split())) for i in range(D)]


def func(g,cnt,l):
    if len(l) == D:
        if g <= 0:
            return cnt
        idx = rindex_zero(l)
        i,p,c = pc_list[idx]
        if g < 100*(i+1)*(p-1):
            cnt += ceil(g/(100*(i+1)))
            return cnt
        return 10**9
    length = len(l)
    i,p,c = pc_list[length]
#     print(i,p,c,l)
    a = func(g-(100*(i+1)*p+c), cnt+p,l+[1])
    b = func(g, cnt,l +[0])
    return min(a,b)
        
print(func(G,0,[]))

Fixed submission:
from math import ceil

D,G = map(int,input().split())

pc_list = [[i]+list(map(int,input().split())) for i in range(D)]
def rindex_zero(l):
    return len(l) - l[::-1].index(0)-1

def func(g,cnt,l):
    if len(l) == D:
        if g <= 0:
            return cnt
        idx = rindex_zero(l)
        i,p,c = pc_list[idx]
        if g <= 100*(i+1)*(p-1):
            cnt += ceil(g/(100*(i+1)))
            return cnt
        return 10**9
    length = len(l)
    i,p,c = pc_list[length]
#     print(i,p,c,l)
    a = func(g-(100*(i+1)*p+c), cnt+p,l+[1])
    b = func(g, cnt,l +[0])
    return min(a,b)
        
print(func(G,0,[]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(lambda x: int(x),input().split()))
b = list(map(lambda x: int(x),input().split()))
c = list(map(lambda x: int(x),input().split()))

count = 0
for mid in b:
    upper_count = len(list(filter(lambda x: x<mid, a)))
    lower_count = len(list(filter(lambda x: x>mid, c)))
    count += upper_count * lower_count
print(count)

Fixed submission:
import bisect

n = int(input())
a = sorted(list(map(lambda x: int(x),input().split())))
b = sorted(list(map(lambda x: int(x),input().split())))
c = sorted(list(map(lambda x: int(x),input().split())))

count = 0
for mid in b:
    upper_count = bisect.bisect_left(a,mid)
    lower_count = len(c) - bisect.bisect_right(c,mid)
    count += upper_count * lower_count
print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a_str = input().split()
a_num = [int(a) for a in a_str]
a_array = np.array(a_num)

rate_list = [1,400,800,1200,1600,2000,2400,2800,3200]

count = 0

for i in range(8):
    if len(a_array[np.where((a_array>=rate_list[i])&(a_array<rate_list[i+1]))]):
        count += 1

min_count = count

count += len(a_array[a_array>=rate_list[8]])
max_count = min(count,8)

print(str(min_count)+" "+str(max_count))

Fixed submission:
import numpy as np

n = int(input())
a_str = input().split()
a_num = [int(a) for a in a_str]
a_array = np.array(a_num)

rate_list = [1,400,800,1200,1600,2000,2400,2800,3200]

count = 0

for i in range(8):
    if len(a_array[np.where((a_array>=rate_list[i])&(a_array<rate_list[i+1]))]):
        count += 1

if count == 0:
    min_count = 1
else:
    min_count = count

count += len(a_array[a_array>=rate_list[8]])
max_count = count

print(str(min_count)+" "+str(max_count))
Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k = input().split()
n = int(n)
k = int(k)
l = list()
for i in range(n):
    a, b = input().split()
    l.append([int(a),int(b)])

ar = np.array(l)
ar_s = ar.sort(0)
count = np.cumsum(ar_s[:,1])

print(ar_s)
print(count)
print(int(ar_s[np.where(count >=k)[0][0]][0]))

Fixed submission:
N, K = map(int,input().split())
# a_list = []
b_dict = {}

for i in range(N):
    a, b = map(int,input().split())
    if a in b_dict:
        b_dict[a] += b
    else:
        b_dict[a] = b
        
a_list = list(b_dict.keys())
a_list.sort()


for a in a_list:
    K -= b_dict[a]
    if K <= 0:
        break

print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k = input().split()
n = int(n)
k = int(k)
l = list()
for i in range(n):
    a, b = input().split()
    for j in range(int(b)):
        l.append(int(a))

l.sort()
print(l[k-1])
    

Fixed submission:
N, K = map(int,input().split())
# a_list = []
b_dict = {}

for i in range(N):
    a, b = map(int,input().split())
    if a in b_dict:
        b_dict[a] += b
    else:
        b_dict[a] = b
        
a_list = list(b_dict.keys())
a_list.sort()


for a in a_list:
    K -= b_dict[a]
    if K <= 0:
        break

print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = 1
for i in range(1,n+1):
    p *= i

a = p % (10**9 + 7)
print(a)

Fixed submission:
N = int(input())

result = 1
for i in range(1,N+1):
    result *= i
    result %= 10**9+7
print(result)
Buggy python submission (verdict: Runtime Error):
s = list(input())

kws = ["dream", "dreamer", "erase", "eraser"]

def func(s):
  bool = False
  for kw in kws:
    if s.startswith(kw):
      bool = bool or func(s[len(kw):])
  return bool

result = func(s)

if result:
  print("YES")
else:
  print("NO")


Fixed submission:
s_list = list(input())

kws = [list(kw) for kw in ["dream", "dreamer", "erase", "eraser"]]

memo = [0 for _ in range(len(s_list)+1)]
memo[0] = 1
for i in range(len(s_list)):
    if memo[i] == 1:
        for kw in kws:
            l = len(kw)
            if s_list[i:i+l] == kw:
                memo[i+l] = 1

if memo[-1] == 1:
    print("YES")
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
n,x = map(int,input().split())

def get_result():
    if x == 1 or x == 2*n-1:
        return []
    
    if N == 2:
        return [1,2,3]
    
    if x == 2:
        center = [3,2,1,4]
        others = list(range(5,2*n))
    elif x == 2*n-2:
        center = [2*n-3,2*n-2,2*n-1,2*n-4]
        others = list(range(1,2*n-4))
    else:
        center = [x+1,x,x-1,x+2]
        others = list(range(1,x-1)) + list(range(x+3,2*n))
    split_idx = n-2
    result = others[:split_idx] + center + others[split_idx:]
    
    return result


res = get_result()
if len(res)==0:
    print("No")
else:
    print("Yes")
    for r in res:
        print(r)
        

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

def get_result():
    if x == 1 or x == 2*n-1:
        return []
    
    if n == 2:
        return [1,2,3]
    
    if x == 2:
        center = [3,2,1,4]
        others = list(range(5,2*n))
    elif x == 2*n-2:
        center = [2*n-3,2*n-2,2*n-1,2*n-4]
        others = list(range(1,2*n-4))
    else:
        center = [x+1,x,x-1,x+2]
        others = list(range(1,x-1)) + list(range(x+3,2*n))
    split_idx = n-2
    result = others[:split_idx] + center + others[split_idx:]
    
    return result


res = get_result()
if len(res)==0:
    print("No")
else:
    print("Yes")
    for r in res:
        print(r)

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

def get_result():
    if x == 1 or x == 2*n-1:
        return []
    
    if N == 2:
        return [1,2,3]
    
    if x == 2:
        center = [3,2,1,4]
        others = list(range(5,2*n))
    elif x == 2*n-1:
        center = [2*n-3,2*n-2,2*n-1,2*n-4]
        others = list(range(1,2*n-4))
    else:
        center = [x+1,x,x-1,x+2]
        others = list(range(1,x-1)) + list(range(x+3,2*n))
    split_idx = 2*n-2
    result = others[:split_idx] + center + others[split_idx:]
    
    return result


res = get_result()
if len(res)==0:
    print("No")
else:
    print("Yes")
    for r in res:
        print(r)
        

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

def get_result():
    if x == 1 or x == 2*n-1:
        return []
    
    if n == 2:
        return [1,2,3]
    
    if x == 2:
        center = [3,2,1,4]
        others = list(range(5,2*n))
    elif x == 2*n-2:
        center = [2*n-3,2*n-2,2*n-1,2*n-4]
        others = list(range(1,2*n-4))
    else:
        center = [x+1,x,x-1,x+2]
        others = list(range(1,x-1)) + list(range(x+3,2*n))
    split_idx = n-2
    result = others[:split_idx] + center + others[split_idx:]
    
    return result


res = get_result()
if len(res)==0:
    print("No")
else:
    print("Yes")
    for r in res:
        print(r)
Buggy python submission (verdict: Runtime Error):
A,B,C,D=map(int,input().split())
win=A/D
lose=C/B
if win=>lose:
  print("Yes")
else:
  if lose<=1:
    print("Yes")
  else:
    if lose-win<1 and A%D!=0:
      print("Yes")
    else:
      print("No")

Fixed submission:

import math
A,B,C,D=map(int,input().split())
win=math.ceil(A/D)
lose=math.ceil(C/B)
if lose<=win:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=[0]*N
for i in range(1,N):
  ans[i]=A.count(i)
  print(ans[i])
print(A.count(N))


Fixed submission:
N=int(input())
A=list(map(int,input().split()))
ans=[0]*N
for i in range(N-1):
  ans[A[i]]+=1
del ans[0]
ans.append(A.count(N))
for i in range(N):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):
N=int(input())
print("Yes" if N[0]==7 or N[1]==7 or N[2]==7 else "No") 

Fixed submission:
N=str(input())
print("Yes" if N[0]=="7" or N[1]=="7" or N[2]=="7" else "No")
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
st=""
n2=0
for i in range(N):
  c1=S[i]
  n1=ord(c1)
  if n1+N>26:
    n2=(((n1-65)+N)%26)+65
  else:
    n2=n1
  st=st+chr(n2)
print(st)

Fixed submission:
N=int(input())
S=input()
st=""
n2=0
for i in range(len(S)):
  c1=S[i]
  n1=ord(c1)
  if n1+N>26:
    n2=(((n1-65)+N)%26)+65
  else:
    n2=n1
  st=st+chr(n2)
print(st)
Buggy python submission (verdict: Runtime Error):
a=int(input())
S=input()
if a%2 != 0:
  print("No")
else:
  b=0
  while	b<=a//2-1:
        S[b]==S[a//2+b]
        b=b+1
  if b==a//2:
    print("Yes")
  else:
    print("No")

Fixed submission:
print(int(input())**2)
Buggy python submission (verdict: Runtime Error):
N=int(input())
b=list(map(int,input().split()))
c=[]
for i in range(N):
	c.append(b[i]**2)
print(((sum(b))**2-sum(c))/2)

Fixed submission:
N=list(map(int,input().split()))
if N[0]-N[1]*2>0:
  print(N[0]-N[1]*2)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
N=int(input())
print(sum(range(1,N)))


Fixed submission:
S=list(input())
T=list(input())
if S[0]==T[0] and S[1]==T[1] and S[2]==T[2]:
  print(3)
elif S[0]==T[0] and S[1]!=T[1] and S[2]!=T[2]:
  print(1)
elif S[0]!=T[0] and S[1]==T[1] and S[2]!=T[2]:
  print(1)
elif S[0]!=T[0] and S[1]!=T[1] and S[2]==T[2]:
  print(1)
elif S[0]!=T[0] and S[1]!=T[1] and S[2]!=T[2]:
  print(0)
else:
  print(2)

Buggy python submission (verdict: Runtime Error):
import math
A=list(map(int,input().split()))
print(math.ceil(A[1]/A[0]))


Fixed submission:
S=list(input())
T=list(input())
if S[0]==T[0] and S[1]==T[1] and S[2]==T[2]:
  print(3)
elif S[0]==T[0] and S[1]!=T[1] and S[2]!=T[2]:
  print(1)
elif S[0]!=T[0] and S[1]==T[1] and S[2]!=T[2]:
  print(1)
elif S[0]!=T[0] and S[1]!=T[1] and S[2]==T[2]:
  print(1)
elif S[0]!=T[0] and S[1]!=T[1] and S[2]!=T[2]:
  print(0)
else:
  print(2)

Buggy python submission (verdict: Runtime Error):
import math
A,B=list(map(int,input().split()))
print(math.ceil(B/A))


Fixed submission:
S=list(input())
T=list(input())
if S[0]==T[0] and S[1]==T[1] and S[2]==T[2]:
  print(3)
elif S[0]==T[0] and S[1]!=T[1] and S[2]!=T[2]:
  print(1)
elif S[0]!=T[0] and S[1]==T[1] and S[2]!=T[2]:
  print(1)
elif S[0]!=T[0] and S[1]!=T[1] and S[2]==T[2]:
  print(1)
elif S[0]!=T[0] and S[1]!=T[1] and S[2]!=T[2]:
  print(0)
else:
  print(2)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
print(sum(range(1,N)))


Fixed submission:
N=int(input())
print(sum(range(1,N)))

Buggy python submission (verdict: Runtime Error):
N=int(input())
print(sum(range(1,N))

Fixed submission:
N=int(input())
print(sum(range(1,N)))
Buggy python submission (verdict: Runtime Error):
A,B=int(input()),int(input())
C=A+B
D=A-B
E=A*B
if C>D and C>E:
    print(C)
elif D>C and D>E:
    print(D)
elif E>C and E>D:
    print(E)

Fixed submission:
i = list(map(int, input().split()))
a=i[0]+i[1]
b=i[0]-i[1]
c=i[0]*i[1]
if a>=b and a>=c:
  print(a)
elif b>=a and b>=c:
  print(b)
else:
  print(c)

Buggy python submission (verdict: Runtime Error):
int main() {
    int a, b;
    cin >> a >> b;
    int c = a * b;
    if (c % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
}

Fixed submission:
i = list(map(int, input().split()))
a=i[0]+i[1]
b=i[0]-i[1]
c=i[0]*i[1]
if a>=b and a>=c:
  print(a)
elif b>=a and b>=c:
  print(b)
else:
  print(c)

Buggy python submission (verdict: Runtime Error):
a=A+B
b=A-B
c=A*B
if a>b and a>c:
  print(a)
  elif b>a and b>c:
    print(b)
    elif c>a and c>b
    print(c)

Fixed submission:
i = list(map(int, input().split()))
a=i[0]+i[1]
b=i[0]-i[1]
c=i[0]*i[1]
if a>=b and a>=c:
  print(a)
elif b>=a and b>=c:
  print(b)
else:
  print(c)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=list(map(int,input().split()))
print(min(a,b)+min(c,d))

Fixed submission:
a,b,c,d=int(input()),int(input()),int(input()),int(input())
print(min(a,b)+min(c,d))
Buggy python submission (verdict: Runtime Error):
i=list(map(int,input().split()))
a=i[0]*i[1]
if a%%2==0:
  print("Even")
else:
  print("Odd")

Fixed submission:
i=list(map(int,input().split()))
a=i[0]*i[1]
if a%2==0:
  print("Even")
else:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
i=list(map(int,input(),split()))
a=i[0]*i[1]
if a%2==0:
  print("Evwn")
else:
  print("Odd")

Fixed submission:
i=list(map(int,input().split()))
a=i[0]*i[1]
if a%2==0:
  print("Even")
else:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
c=a*b
if c%2==0:
  print("Even")
  else:
    print("Odd")

Fixed submission:
i=list(map(int,input().split()))
a=i[0]*i[1]
if a%2==0:
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Runtime Error):
a=input()
print(a[0]+len(a)+a[-1])

Fixed submission:
a=input()
print(a[0]+str(len(a)-2)+a[-1])
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a+b<24:
  print(a+b)
  else:
    print((a+b)%24)

Fixed submission:
a,b=map(int,input().split())
if a+b<24:
  print(a+b)
else:
  print((a+b)%24)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
a_max = max(A)[0]
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max and count >= 2:
		print(a_max)
	else:
		b_max = 0
		for j in range(N):
				if A[j] == a_max:
					continue
				if A[j] > b_max:
					b_max = A[j]
		print(b_max)


Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
a_max = int(max(A))
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max or count >= 2:
		print(a_max)
	else:
		b_max = 0
		for j in range(N):
				if A[j] == a_max:
					continue
				if A[j] > b_max:
					b_max = A[j]
		print(b_max)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
a_max = max(A)[0]
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max and count >= 2:
		print(a_max)
	else:
		b_max = 0
		for i in range(N):
				if A[i] == a_max:
					continue
				if A[i] > b_max:
					b_max = A[i]
		print(b_max)


Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
a_max = int(max(A))
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max or count >= 2:
		print(a_max)
	else:
		b_max = 0
		for j in range(N):
				if A[j] == a_max:
					continue
				if A[j] > b_max:
					b_max = A[j]
		print(b_max)
Buggy python submission (verdict: Runtime Error):
inputs = input().split()

N = int(inputs[0])
M = int(inputs[1])

passIDs = [0] * (10**5 + 10)

for i in range(M):
    inputs = input().split()

    L = int(inputs[0])
    R = int(inputs[1])

    for j in range(L, R+1):
        passIDs[j] += 1

IDs = 0

for passId in passIDs:
    if passId == M:
        IDs += 1

print(IDs)



Fixed submission:
inputs = input().split()

A = int(inputs[0])
B = int(inputs[1])

if not 0 <= A <= 100:
    exit(0)

if not 2 <= B <= 1000:
    exit(0)

if not B % 2 == 0:
    exit(0)

if A <= 5:
    B = 0
elif 5 < A < 13:
    B /= 2

print(int(B))
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
s = {}
ans = 0

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				exit(1)
print(ans)


Fixed submission:
import sys

N,M = map(int,input().split())
s = {}
ans = 0

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				sys.exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
s = {}
ans = 0

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				exit(1)
print(ans)


Fixed submission:
import sys

N,M = map(int,input().split())
s = {}
ans = 0

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				sys.exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
arr = input().split()
K = int(arr[0])
A = int(arr[1])
B = int(arr[2])

x = 1
a = 0
n = 1 + K

while K > 0:
	if a > 0 and B > A:
		x += B
		a -= 1
		K -= 1
		continue

	if x >= A and B > A and K != 1:
		x -= A
		a += 1
		K -= 1
		continue

	x += 1
	K -= 1

print(max(x, n))


Fixed submission:
arr = input().split()
K = int(arr[0])
A = int(arr[1])
B = int(arr[2])

n = 1 + K
x = 1
if K > A:
	x = B
	K -= A+1

	temp = int(K / 2)

	x += temp * (B-A)
	K -= temp * 2

	while K > 0:
		K -= 1
		x += 1

print(max(x, n))
Buggy python submission (verdict: Runtime Error):
A = str(input())
B = int(input())
count = 0

for i in range(len(A)):
    if A[i] == "1":
        count += 1
    else:
        if B <= count:
            print(1)
            sys.exit()
        else:
            print(A[i])
            sys.exit()
print(1)


Fixed submission:
import sys
A = str(input())
B = int(input())
count = 0

for i in range(len(A)):
    if A[i] == "1":
        count += 1
    else:
        if B <= count:
            print(1)
            sys.exit()
        else:
            print(A[i])
            sys.exit()
print(1)