Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import functools


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

scores = list(map(int, input().split()))

answers = []

prev_mul_scores_last_k = functools.reduce(lambda acc, score: acc * score, scores[:k])

prev_score = scores[0]

for i in range(k, n):
    mul_scores_last_k = (prev_mul_scores_last_k // prev_score) * scores[i]

    if prev_mul_scores_last_k < mul_scores_last_k:
        answers.append('Yes')
    else:
        answers.append('No')

    prev_mul_scores_last_k = mul_scores_last_k
    prev_score = scores[i - (k - 1)]

for answer in answers:
    print(answer)


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

scores = list(map(int, input().split()))

answers = []

prev_score = scores[0]

for i in range(k, n):
    if prev_score < scores[i]:
        answers.append('Yes')
    else:
        answers.append('No')

    prev_score = scores[i - (k - 1)]

for answer in answers:
    print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import functools


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

scores = list(map(int, input().split()))

answers = []

prev_mul_scores_last_k = functools.reduce(lambda acc, score: acc * score, scores[:k])

prev_score = scores[0]

for i in range(k, n):
    mul_scores_last_k = (prev_mul_scores_last_k // prev_score) * scores[i]

    if prev_mul_scores_last_k < mul_scores_last_k:
        answers.append('Yes')
    else:
        answers.append('No')

    prev_mul_scores_last_k = mul_scores_last_k
    prev_score = scores[i - (k - 1)]

for answer in answers:
    print(answer)

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

scores = list(map(int, input().split()))

answers = []

prev_score = scores[0]

for i in range(k, n):
    if prev_score < scores[i]:
        answers.append('Yes')
    else:
        answers.append('No')

    prev_score = scores[i - (k - 1)]

for answer in answers:
    print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import functools
from operator import mul


n = int(input())

nums = list(map(int, input().split()))

product = 1

for num in nums:
    product *= num

if product > 1e18:
    product = -1

print(product)


Fixed submission:
n = int(input())

nums = list(map(int, input().split()))

product = 1

for num in nums:
    product *= num

    if product > 1e18:
        product = -1
        break

if 0 in nums:
    product = 0

print(product)

Buggy python submission (verdict: Time Limit Exceeded):
import functools
from operator import mul


n = int(input())

nums = list(map(int, input().split()))

product = functools.reduce(mul, nums, 1)

if product > 1e18:
    product = -1

print(product)


Fixed submission:
n = int(input())

nums = list(map(int, input().split()))

product = 1

for num in nums:
    product *= num

    if product > 1e18:
        product = -1
        break

if 0 in nums:
    product = 0

print(product)
Buggy python submission (verdict: Runtime Error):
num_strs = input().split()

a = int(num_strs[0])
b = int(num_strs[1] * 100)

print((a * b) // 100)


Fixed submission:
import decimal

a, b = list(map(decimal.Decimal, input().split()))

print(int(a * b))
Buggy python submission (verdict: Runtime Error):
import math


hour_hand_speed = (2 * math.pi) / (12 * 60)
minute_hand_speed = (2 * math.pi) / 60

hour_hand, minute_hand, hour, minute = list(
    map(int, input().split())
)

elapsed_time = 60 * hour + minute

hour_hand_angle = elapsed_time * hour_hand_speed
minute_hand_angle = minute * minute_hand_speed

angle_btw_hour_minute = abs(hour_hand_angle - minute_hand_angle)

distance = math.sqrt(
    hour_hand**2 + minute_hand**2 - (2 * hour_hand * minute_hand * math.cos(angle_btw_hour_minute))
)

print(distance)import math


hour_hand_speed = (2 * math.pi) / (12 * 60)
minute_hand_speed = (2 * math.pi) / 60

hour_hand, minute_hand, hour, minute = list(
    map(int, input().split())
)

elapsed_time = 60 * hour + minute

hour_hand_angle = elapsed_time * hour_hand_speed
minute_hand_angle = minute * minute_hand_speed

angle_btw_hour_minute = abs(hour_hand_angle - minute_hand_angle)

distance = math.sqrt(
    hour_hand**2 + minute_hand**2 - (2 * hour_hand * minute_hand * math.cos(angle_btw_hour_minute))
)

print(distance)

Fixed submission:
import math


hour_hand_speed = (2 * math.pi) / (12 * 60)
minute_hand_speed = (2 * math.pi) / 60

hour_hand, minute_hand, hour, minute = list(
    map(int, input().split())
)

elapsed_time = 60 * hour + minute

hour_hand_angle = elapsed_time * hour_hand_speed
minute_hand_angle = minute * minute_hand_speed

angle_btw_hour_minute = abs(hour_hand_angle - minute_hand_angle)

distance = math.sqrt(
    hour_hand**2 + minute_hand**2 - (2 * hour_hand * minute_hand * math.cos(angle_btw_hour_minute))
)

print(distance)
Buggy python submission (verdict: Runtime Error):
number = int(input())

num_eight_divisors = 0

numbers = list(range(9, number + 1, 2))

for i in range(9, number + 1, 2):
    divisors = [1, i]

    for j in range(2, i):
        q, mod = divmod(i, j)

        if mod == 0:
            divisors.append(j, q)

    if len(set(divisors)):
        num_eight_divisors = num_eight_divisors + 1

print(num_eight_divisors)


Fixed submission:
number = int(input())

num_eight_divisors = 0

numbers = list(range(9, number + 1, 2))

for i in range(9, number + 1, 2):
    divisors = [1, i]

    for j in range(2, i):
        q, mod = divmod(i, j)

        if mod == 0:
            divisors.append(j)
            divisors.append(q)

    if len(set(divisors)) == 8:
        num_eight_divisors = num_eight_divisors + 1

print(num_eight_divisors)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
if k%10==0 or k%10==2 or k%10==4 or k%10==5 or k%10==6 or k%10==8:
    print(-1)
else:
    s = 7
    i = 1
    while(True):
        if s%k==0:
            print(i)
            exit()
        else:
            s = s*10+7
            i += 1

Fixed submission:
k = int(input())
a = 0
for i in range(k):
    a = (a*10+7)%k
    if a == 0:
        print(i+1)
        exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
from copy import copy

def f(n,cnt):
    if n==0:
        return cnt
    popcnt = bin(n).count('1')
    return f(n%popcnt,cnt+1)

n = int(input())
x = list(input())


for i in range(n):
    y = copy(x)
    if y[i] == '0':
        y[i] = '1'
    else:
        y[i] = '0'

    y = ''.join(y)
    m = int(y,2)
    print(f(m,0))

Fixed submission:
def f(n,cnt):
    if n==0:
        return cnt
    popcnt = bin(n).count('1')
    return f(n%popcnt,cnt+1)

n = int(input())
x = input()

m = int(x,2)
m_cnt = x.count('1')

mp = m%(m_cnt+1)
mm = m%(m_cnt-1) if m_cnt > 1 else 0

for i,s in enumerate(x):
    i = n-1-i
    num = None

    if s == '0':
        mod = m_cnt+1
        num = (mp+pow(2,i,mod))%mod
    elif m_cnt > 1:
        mod = m_cnt-1
        num = (mm-pow(2,i,mod))%mod
    else:
        print(0)
        continue

    print(1+f(num,0))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for x in range(1,n+1):
    y = int(n/x)
    ans += y*(y+1)*x//2

print(ans)

Fixed submission:
n = int(input())
ans = 0
for x in range(1,n+1,1):
    y = int(n/x)
    ans += y*(y+1)*x/2

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from math import floor
n = int(input())
ans = 0
for x in range(1,n+1):
    y = floor(n/x)
    ans += y*(y+1)*x//2

print(ans)

Fixed submission:
n = int(input())
ans = 0
for x in range(1,n+1,1):
    y = int(n/x)
    ans += y*(y+1)*x/2

print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
a = list(map(int,input().split()))
b = []

k = len(bin(max(a)))-2
for x in a:
    b.append([int(y) for y in list(bin(x)[2:].zfill(k))])

b = np.array(b)
c = b.T

ans = []
for i in range(k):
    one = sum(c[i])
    if one%2==0:
        pass
    else:
        c[i] = (c[i]+1)%2

d = c.T

for i in range(n):
    ans.append(int(''.join([str(y) for y in d[i]]),2))

print(*ans)

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

A = 0
for i in range(n):
    A ^= a[i]

ans = [A^x for x in a]
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

cnt = 0
for i in range(n):
    x = a[i]
    f = 1
    for j in range(n):
        if i == j:
            continue
        if x%a[j]==0:
            f = 0
            break   
    if f:
        cnt += 1
        
print(cnt)

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

cnt = [0]*(10**6+1)

for elem in a:
    cnt[elem] += 1

unique = []
for i in range(10**6+1):
    if cnt[i] == 1:
        unique.append(i)

cnt = [0]*(10**6+1)
a = list(set(a))

for elem in a:
    for m in range(elem*2,10**6+1,elem):
        cnt[m] = 1

ans = 0
for elem in unique:
    if cnt[elem] == 0:
        ans += 1

print(ans)

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

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]

div = []
for i in range(n):
    div.append(make_divisors(a[i]))


cnt = 0
for j in range(n):
    f = 1
    for k in range(len(div[j])):
        if k != len(div[j])-1:
            if div[j][k] not in a:
                pass
            else:
                f = 0
                break
        else:
            if a.count(div[j][k]) == 1:
                pass
            else:
                f = 0
    if f:
        cnt += 1

print(cnt)

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

cnt = [0]*(10**6+1)

for elem in a:
    cnt[elem] += 1

unique = []
for i in range(10**6+1):
    if cnt[i] == 1:
        unique.append(i)

cnt = [0]*(10**6+1)
a = list(set(a))

for elem in a:
    for m in range(elem*2,10**6+1,elem):
        cnt[m] = 1

ans = 0
for elem in unique:
    if cnt[elem] == 0:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
tel = [int(e)-1 for e in input().split()]

now = 0
cnt = 0
pl = [0]

while k > 0:
    now = tel[now]
    k -= 1
    if now in pl:
        break
    else:
        pl.append(now)
    
loop = now
cnt = 0
while k > 0:
    now = tel[now]
    cnt += 1
    k -= 1
    if now == loop:
        break

k %= cnt
for i in range(k):
    now = tel[now]

print(now+1)


Fixed submission:
n,k = map(int,input().split())
tel = [int(e)-1 for e in input().split()]

pl = [0]
for i in range(2*n+1000):
    nxt = tel[pl[-1]]
    pl.append(nxt)

if k < n + 1:
    print(pl[k]+1)
    exit()

loop_end = n
loop_start = n-1
while pl[loop_start] != pl[loop_end]:
    loop_start -= 1

#pl[loop_start] == pl[loop_end]
period = loop_end - loop_start

k %= period

while k < n:
    k += period

print(pl[k]+1)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
tel = [int(e) for e in input().split()]

now = 0
cnt = 0
pl = [0]

while k > 0:
    now = tel[now]-1
    k -= 1
    if now in pl:
        break
    else:
        pl.append(now)
    
loop = now
cnt = 0
while k > 0:
    now = tel[now]-1
    cnt += 1
    k -= 1
    if now == loop:
        break

k %= cnt
for i in range(k):
    now = tel[now]-1

print(now+1)

Fixed submission:
n,k = map(int,input().split())
tel = [int(e)-1 for e in input().split()]

pl = [0]
for i in range(2*n+1000):
    nxt = tel[pl[-1]]
    pl.append(nxt)

if k < n + 1:
    print(pl[k]+1)
    exit()

loop_end = n
loop_start = n-1
while pl[loop_start] != pl[loop_end]:
    loop_start -= 1

#pl[loop_start] == pl[loop_end]
period = loop_end - loop_start

k %= period

while k < n:
    k += period

print(pl[k]+1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
tall = [int(e) for e in input().split()]
bridge = [[] for _ in range(n)]

for i in range(m):
    c = [int(f)-1 for f in input().split()]
    
    if tall[c[1]] not in bridge[c[0]]:
        bridge[c[0]].append(tall[c[1]])
    if tall[c[0]] not in bridge[c[1]]:
        bridge[c[1]].append(tall[c[0]])

cnt = 0
for j in range(n):
    if len(bridge[j]) == 0:
        cnt += 1
    elif tall[j] > max(bridge[j]):
        cnt += 1
    else:
        pass

print(cnt)

Fixed submission:
import copy
n,m = map(int,input().split())
tall = [int(e) for e in input().split()]

bridge = copy.copy(tall)

for i in range(m):
    c = [int(f)-1 for f in input().split()]
    a,b = c[0],c[1]
    if bridge[a] < tall[b]:
        bridge[a] = tall[b]
    elif bridge[a] == tall[b]:
        bridge[a] = 10**10
    if bridge[b] < tall[a]:
        bridge[b] = tall[a]
    elif bridge[b] == tall[a]:
        bridge[b] = 10**10

cnt = 0
for j in range(n):
    if tall[j] == bridge[j]:
        cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
from itertools import permutations

n,m,q = map(int,input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q

for i in range(q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1


arr = [0]*(n+m)
for j in range(m):
    arr[j] = 1

ans = 0

for vec in permutations(arr):
    zero_cnt = 0
    score = 0
    A = []
    for k in range(n+m):
        if vec[k] == 0:
            zero_cnt += 1
        else:
            A.append(zero_cnt)

    for l in range(q):
        if A[b[l]] - A[a[l]] == c[l]:
            score += d[l]

    ans = max(ans,score)


print(ans)

Fixed submission:
from itertools import combinations_with_replacement

n,m,q = map(int,input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q

for i in range(q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1


arr = [0]*(n+m)
for j in range(m):
    arr[j] = 1

ans = 0

for A in combinations_with_replacement(range(1,m+1),n):
    score = 0
    for l in range(q):
        if A[b[l]] - A[a[l]] == c[l]:
            score += d[l]

    ans = max(ans,score)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = list(input())
s = deque(s)
n = int(input())

for i in range(n):
    q = input().split()
    if q[0] == '1':
        s.reverse()
    else:
        if q[1] == '1':
            s.appendleft(q[2])
        else:
            s.append(q[2])

print(''.join(s))

Fixed submission:
from collections import deque

s = list(input())
s = deque(s)
n = int(input())
dire = False

for i in range(n):
    q = input().split()
    if q[0] == '1':
        dire = not dire
    else:
        t = int(q[1])-1

        if dire ^ t:
            s.append(q[2])
        else:
            s.appendleft(q[2])
if dire:
    s.reverse()

print(''.join(s))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
key = []
value = []

for i in range(n):
    s = input()
    if s in key:
        value[key.index(s)] += 1
    else:
        key.append(s) 
        value.append(1)

m = max(value)
arr = []
y = len(key)

for j in range(y):
    if value[j] == m:
        arr.append(key[j])

arr.sort()
x = len(arr)
for k in range(x):
    print(arr[k])

Fixed submission:
n = int(input())
dic = {}

for i in range(n):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1

m = max(dic.values())
arr = []

for j in dic:
    if dic[j] == m:
        arr.append(j)

arr.sort()

for k in arr:
    print(k)
Buggy python submission (verdict: Runtime Error):
from math import gcd

a,b = map(int,input().split())
c = a*b//gcd(a,b)
print(c)

Fixed submission:
from fractions import gcd

a,b = map(int,input().split())
print(a*b//gcd(a,b))

Buggy python submission (verdict: Runtime Error):
from math import gcd

a,b = map(int,input().split())
print(a*b//gcd(a,b))

Fixed submission:
from fractions import gcd

a,b = map(int,input().split())
print(a*b//gcd(a,b))

Buggy python submission (verdict: Runtime Error):
from math import gcd

a,b = map(int,input().split())
print(a*b//gcd(a,b))

Fixed submission:
from fractions import gcd

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

ans = 0
MOD = 10**9+7

for i in range(n-1):
    for j in range(i+1,n):
        ans += (a[i]^a[j])
    ans %= MOD

print(ans)

Fixed submission:
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=int)

ans = 0
MOD = 10**9+7

k = max(a)
j = 0
while k:
    bits = (a>>j)&1
    one = np.count_nonzero(bits)
    ans += (one%MOD)*((n-one)%MOD)*pow(2,j,MOD)
    ans %= MOD
    j += 1
    k >>= 1

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

cnt = 0
for i in range(1000):
    p = str(i).zfill(3)
    f1,f2,f3 = 0,0,0
    for j in range(n):
        if not f1:
            if p[0] == s[j]:
                f1 = 1
        elif not f2:
            if p[1] == s[j]:
                f2 = 1
        elif not f3:
            if p[2] == s[j]:
                f3 = 1
        else:
            break

    if f1 and f2 and f3:
        cnt += 1

print(cnt)

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

cnt = 0
for i in range(10):
    p1 = s.find(str(i))
    if p1 == -1:
        continue
    
    for j in range(10):
        p2 = s.find(str(j),p1+1)
        if p2 == -1:
            continue

        for k in range(10):
            p3 = s.find(str(k),p2+1)
            if p3 != -1:
                cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
if(h==1 or w==1):
    print(1)
    sys.exit()
if((h*w)%2):
    print(int((h*w)//2+1))
else:
    print(int((h*w)//2))

Fixed submission:
import sys
h,w=map(int,input().split())
if(h==1 or w==1):
    print(1)
    sys.exit()
if((h*w)%2):
    print(int((h*w)//2+1))
else:
    print(int((h*w)//2))

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
if((h*w)%2):
    print((h*w)//2+1)
else:
    print((h*w)/2)
  


    

Fixed submission:
import sys
h,w=map(int,input().split())
if(h==1 or w==1):
    print(1)
    sys.exit()
if((h*w)%2):
    print(int((h*w)//2+1))
else:
    print(int((h*w)//2))
Buggy python submission (verdict: Runtime Error):
import sys
import math
input=sys.stdin.readline
INF=1000000000
# A Dynamic Programming based Python Program for 0-1 Knapsack problem 
# Returns the maximum value that can be put in a knapsack of capacity W 
def knapSack(W,l, n):
    
    
    
    min_cost = [[0 for i in range(W+1)] for j in range(n+1)] 
    # fill 0th row with infinity 
    for i in range(W+1): 
        min_cost[0][i] = INF 
  
    # fill 0th column with 0 
    for i in range(1, n+1): 
        min_cost[i][0] = 0
    # now check for each weight one by one and fill the 
    # matrix according to the condition 
    for i in range(1, n+1): 
        for j in range(1, W+1): 
            # wt[i-1]>j means capacity of bag is 
            # less than weight of item 
            if (l[i-1][0] > j): 
                min_cost[i][j] = min(min_cost[i-1][j] ,l[i-1][1])
            # here we check we get minimum cost either 
            # by including it or excluding it 
            else: 
                min_cost[i][j] = min(min_cost[i-1][j], 
                    min_cost[i][j-l[i-1][0]] + l[i-1][1]) 
    
  
    # exactly weight W can not be made by given weights 
    if(min_cost[n][W] == INF): 
        return -1
    else: 
        return min_cost[n][W]

h,n=map(int,input().split())
l=list()
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
print( knapSack(h , l , n) ) 


Fixed submission:
import sys
import math
input=sys.stdin.readline


h,a=map(int,input().split())
ans=h//a
h=h%a
if(h>0):
    print(ans+1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
input=sys.stdin.readline
INF=1000000000
# A Dynamic Programming based Python Program for 0-1 Knapsack problem 
# Returns the maximum value that can be put in a knapsack of capacity W 
def knapSack(W,l, n):
    
    
    
    min_cost = [[0 for i in range(W+1)] for j in range(n+1)] 
    # fill 0th row with infinity 
    for i in range(W+1): 
        min_cost[0][i] = INF 
  
    # fill 0th column with 0 
    for i in range(1, n+1): 
        min_cost[i][0] = 0
    # now check for each weight one by one and fill the 
    # matrix according to the condition 
    for i in range(1, n+1): 
        for j in range(1, W+1): 
            # wt[i-1]>j means capacity of bag is 
            # less than weight of item 
            if (l[i-1][0] > j): 
                min_cost[i][j] = min(min_cost[i-1][j] ,l[i-1][1])
            # here we check we get minimum cost either 
            # by including it or excluding it 
            else: 
                min_cost[i][j] = min(min_cost[i-1][j], 
                    min_cost[i][j-l[i-1][0]] + l[i-1][1]) 
    
  
    # exactly weight W can not be made by given weights 
    if(min_cost[n][W] == INF): 
        return -1
    else: 
        return min_cost[n][W]

h,n=map(int,input().split())
l=list()
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
print( knapSack(h , l , n) ) 


Fixed submission:

INF=1000000000
# A Dynamic Programming based Python Program for 0-1 Knapsack problem 
# Returns the maximum value that can be put in a knapsack of capacity W 
def knapSack(W,l, n):
    
    
    
    min_cost = [[0 for i in range(W+1)] for j in range(n+1)] 
    # fill 0th row with infinity 
    for i in range(W+1): 
        min_cost[0][i] = INF 
  
    # fill 0th column with 0 
    for i in range(1, n+1): 
        min_cost[i][0] = 0
    # now check for each weight one by one and fill the 
    # matrix according to the condition 
    for i in range(1, n+1): 
        for j in range(1, W+1): 
            # wt[i-1]>j means capacity of bag is 
            # less than weight of item 
            if (l[i-1][0] > j): 
                min_cost[i][j] = min(min_cost[i-1][j] ,l[i-1][1])
            # here we check we get minimum cost either 
            # by including it or excluding it 
            else: 
                min_cost[i][j] = min(min_cost[i-1][j], 
                    min_cost[i][j-l[i-1][0]] + l[i-1][1]) 
    
  
    # exactly weight W can not be made by given weights 
    if(min_cost[n][W] == INF): 
        return -1
    else: 
        return min_cost[n][W]

h,n=map(int,input().split())
l=list()
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
print( knapSack(h , l , n) )
Buggy python submission (verdict: Runtime Error):
#code
n=int(input())
b=input()

b=b.split()

b=list(map(int,b))
a=list()
for i in range(len(b)-1):
    if(i==0):
        a.append(b[i])
        a.append(b[i])
    else:
        a.append(min(b[i],b[i+1]))
a.append(max(b[len(b)-1],a[len(a)-1]))
sum=0 
for i in range(len(a)):
    sum+=a[i]
print(sum)


Fixed submission:
#code
n=int(input())
b=input()

b=b.split()

b=list(map(int,b))
a=list()
a.append(b[0])

for i in range(1,len(b)):
    
    
    a.append(min(b[i],b[i-1]))
if(n>2):
    a.append(b[len(b)-1])
if(n==2):
    a.append(b[0])
sum=0 
for i in range(len(a)):
    sum+=a[i]
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

suba=[0]
subb=[0]

for i in range(n):
    suba.append(a[i]+suba[i])
for j in range(m):
    subb.append(b[j]+subb[j])

ans=0

for i in range(n+1):
    j=m
    while True:
        #print(i,j)
        if k<suba[i]:
            i=0
            j=0
            break

        if subb[j]<=k-suba[i]:
            break
        j-=1
    ans=max(ans,i+j)
print(ans)

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

suba=[0]
subb=[0]

for i in range(n):
    suba.append(a[i]+suba[i])
for j in range(m):
    subb.append(b[j]+subb[j])

ans=0
j=m
for i in range(n+1):
        #print(i,j)
    if k<suba[i]:
        break

    while subb[j]>k-suba[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)