peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
import sys

N,Y = map(int,input().split())

for a in range(N+1):
    for b in range(N-a):
        c = N - a - b
        if 10000 * a + 5000 * b + 1000 * c == Y:
            print(a,b,c)
            sys.exit()

print("-1 -1 -1")
# Judge status: Wrong Answer
s = input()

ans = 1
tmp = s[0]
t = False

for i in range(1, len(s)):
    if tmp == s[i] and i == len(s) - 1:
        break
        
    if t:
        tmp = s[i - 1] + s[i]
        t = False
        ans += 1
        continue
        
    if tmp == s[i]:
        t = True
        
    else:
        ans += 1
        tmp = s[i]

print(ans)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

addans=0

for i in range(n-1) :
  if a[i]+1 == a[i+1] :
    addans += c[a[i]-1]
print(sum(b)+addans)
# Judge status: Wrong Answer

Flag =  0 
S = input()
SA = [str(c) for c in S]
A = list(['A','A','A'])
B = list(['B','B','B'])
print(SA)
if(set(S) == set(A) and set(S) ==set(B)):
    print("No")
else:
    print("Yes")
# Judge status: Accepted
def primeFact(n):
    i = 2
    pl = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            pl.append(i)
        i += 1
    if n > 1:
        pl.append(int(n))
    return pl


a, b = map(int, input().split())
print(len(set(primeFact(a)) & set(primeFact(b))) + 1)
# Judge status: Accepted
def main():
  h, n = map(int,input().split())
  magics = []
  for i in range (n):
    a, b = map(int,input().split())
    magics.append([a,b])
  # Using Secondary Array in For Loop
  dp = [0] * (h + max(a for a, b in magics))
  for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in magics)
  print(dp[h])  

if __name__ == '__main__':
  main()
# Judge status: Wrong Answer
N, K = list(map(int, input().split()))
E = 0

for i in range(1, N + 1):
  cnt = N + 2 - i 
  E += 0.5 ** cnt
  
print(E / N)
# Judge status: Accepted
import numpy as np
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
A_diff = np.diff(A)
A_diff_sum = np.sum(A_diff)
max_diff = np.max([np.max(A_diff), (N - A[-1] + A[0])])
ans = A_diff_sum - max_diff + (N - A[-1] + A[0])
print(ans)
# Judge status: Accepted
x,y = map(int,input().split())
if 0 <= x < y or x < y <= 0:
    print(abs(y-x))
elif 0 < y < x or y < x < 0:
    print(abs(x-y) + 2)
elif x < y:
    if y < abs(x):
        print(abs(x)-y + 1)
    else:
        print(y-abs(x) + 1)
else:
    if x < abs(y):
        print(abs(y)-x + 1)
    else:
        print(x-abs(y) + 1)
# Judge status: Wrong Answer
n = int(input())
s =  [input().split() for i in range(n)]
temp = s
data = sorted(s,key=lambda x:(x[0],-int(x[1])))


for i in range(n):
    y = temp[i]
    result = data.index(y)
    print(result+1)
# Judge status: Wrong Answer
def main():
    k = int(input())
    s = input()

    l = len(s)
    if l <= k:
        print(s)
    else:
        print(s+"...")

if __name__ == '__main__':
    main()
# Judge status: Accepted
A,B = list(map(int,input().split()))
s = list(map(int,input().split()))
s1 = sorted(s,reverse = True)
s2 = s1[B::]
print(sum(s2))
# Judge status: Accepted
n=int(input())
alist=[]
blist=[]
for i in range(n):
    a, b = map(int,input().split())
    alist.append(a)
    blist.append(b)

alist=sorted(alist)
blist=sorted(blist)

if n%2==1:
    center=(n-1)//2
    answer=blist[center]-alist[center]+1
    print(answer)
else:
    #print(alist, blist)
    mae=(alist[(n//2)-1]+alist[(n//2)])/2
    ato=(blist[(n//2)-1]+blist[(n//2)])/2
    #print(mae, ato)
    print(int((ato-mae)*2+1))
# Judge status: Accepted
n,d = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(n)]

def dist_squere(x, y):
    d = 0
    for i,j in zip(x,y):
        d += (i-j)**2
    return d**.5

from itertools import combinations

ans = 0
for x,y in combinations(X, 2):
    if dist_squere(x, y).is_integer():
        ans += 1

print(ans)
# Judge status: Wrong Answer
N=input()
count=0
for i in range(3):
    #print(N[i])
    if N[i]==N[i+1]:
        count=count+1
if count>1:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n = int(input())
dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if s not in dic:
    dic[s] = 0
  dic[s] += 1
ans = 0
for i in dic.values():
  ans += i * (i - 1)
print(ans)
# Judge status: Accepted
a,b=map(int,input().split())
ans= a if a<=b else a-1
print(ans)
# Judge status: Accepted
def f():
  n=int(input())
  l=[list(map(int,input().split())) for i in range(n-1)]+[[0,0,1]]
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      now=a+s-(-max(0,now-s)//d)*d
    print(now)
if __name__=="__main__":
  f()
# Judge status: Accepted
import math
n,d = map(int,input().split())

print(math.ceil(n/(2*d+1)))
# Judge status: Wrong Answer
a,b=map(int,input().split())
if a*500>=b :
  print('YES')
else:
  print('NO')
# Judge status: Accepted
a,sd,f=map(int,input().split())
print(f,a,sd)
# Judge status: Accepted
n, k = map(int, input().split())
if n * 500 >= k:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
s = input()
print ("Yes") if s[0] == s[1] == s[2] or s[1] == s[2] == s[3] else print ("No")
# Judge status: Wrong Answer
N=int(input())
S=input()
total=0
X=[]
for i in S:
  X.append(total)
  if i=="I":
    total+=1
  elif i=="D":
    total-=1
print(max(X))
# Judge status: Accepted
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

cnt = 0
for i in b:
	x = bisect.bisect_left(a,i)
	y = bisect.bisect_right(c,i)
	cnt += x*(n-y)
print (cnt)
# Judge status: Accepted
n = int(input())
x = n*800
y = (n//15)*200
print(x-y)
# Judge status: Accepted
from collections import defaultdict
n = int(input())
d = defaultdict(int)
count = 0
for i in range(n):
    s = "".join(sorted(input()))
    count += d[s]
    d[s] += 1
print(count)
# Judge status: Accepted
n = int(input())
cnt = 1
ans = 0
while 1:
    tmp = cnt ** 2
    if tmp <= n:
        ans = tmp
        cnt += 1
    else:
        break

print(ans)
# Judge status: Wrong Answer
n = int(input())
*a, = map(int,input().split())
a.reverse()
b = [a[0]]
for i in range(1,n+1):
    b.append(b[-1] + a[i])
b.reverse()
c = [1 for _ in range(n+1)]
ans = -1
for i in range(1,n+1):
    c[i] = min(c[i-1]*2,b[i])
    c[i] -= a[i]
    if c[i] <= 0:
        print(-1);exit()
print(sum(c) + sum(a[1:]))
# Judge status: Accepted
n = int(input())
a = list(input().split())

a = [int(a[i]) for i in range(n)]
ans = 0
for j in range(n):
    if j%2 == 0 and a[j]%2 == 1:
        ans = ans + 1

print(ans)
# Judge status: Accepted
n,k = map(int,input().split())
dls = list(map(int,input().split()))
while 1:
    s = list(map(int,list(str(n))))
    for i in dls:
        if i in s:
            break
    else:
        print(n)
        exit()
    n += 1
# Judge status: Accepted
a, b, c = map(int, input().split())
print("Yes" if a<=c<=b else "No")
# Judge status: Accepted
N, M = map(int, input().split())
A = list(map(lambda x: int(x), input().split()))
Q = []

for i in range(M):
    Q.append(tuple(map(int, input().split())))

A.sort()

Q.sort(key=lambda x: x[1], reverse=True)

cur = 0
for i in range(M):
    cnt = Q[i][0]
    while cnt > 0 and cur < N:
        if A[cur] >= Q[i][1]:
            break
        A[cur] = Q[i][1]
        cur += 1
        cnt -= 1

print(sum(A))
# Judge status: Accepted
n,x=map(int,input().split())
li=list(map(int,input().split()))
ans=1
l=0
for i in li:
  l+=i
  if l>x:
    break
  ans+=1
print(ans)
# Judge status: Wrong Answer
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
ans = 1
if N == K:
    print(1)
    exit()
else:
    if (N-K+1)%K == 0:
        ans += N-K+1
    else:
        ans += (N-K+1)%K+1
print(ans)
# Judge status: Wrong Answer
N=int(input())
H=list(map(int,input().split()))
depth=[0]*(N+1)
depth[0]=1
if H[0]>0 and N==1:
    print(1)
    exit()
for i in range(1,N+1):
    depth[i]=(depth[i-1]-H[i-1])*2
    if depth[i]<=0:
        print(-1)
        exit()
depth[N]=H[N]
for i in range(N-1,-1,-1):
    depth[i]=min(depth[i+1]+H[i],depth[i])
print(sum(depth))
# Judge status: Wrong Answer
import heapq

N, M = map(int, input().split())

a = [-int(x) for x in input().split()]

heapq.heapify(a)

num = 0
hq = 1

while num < M and hq != 0:
    hq = -heapq.heappop(a)//2
    heapq.heappush(a, -hq)
    num += 1

print(-sum(a))
# Judge status: Wrong Answer
n,a,b,c,d = map(int,input().split())
s = input()
S = s[:max(c,d)]

l = len(S)
C = True
D = False
for i in range(l-1):
  if S[i]=='#' and S[i+1]=='#':
    C = False
    break
  if d > i > 0:
    if S[i-1]=='.' and S[i]=='.' and S[i+1]=='.':
      D = True
      
if not C:
  print('No')
elif C and not D:
  if c < d:
    print('Yes')
  else:
    print('No')
else:
  print('Yes')
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
mai=0
for i in range(n):
    if a[i]<0:
        mai+=1
ans=0
for i in range(n):
    ans+=abs(a[i])
    a[i]=abs(a[i])
if mai%2==0:
    print(ans)
else:
    print(ans-2*abs(min(a)))
# Judge status: Accepted
import math
A,B = map(int,input().split())
flag = 0
for i in range(1,10**5):
    if math.floor(i*0.08) == A and math.floor(i*0.1) == B:
        print(i)
        flag += 1
        break
if flag == 0:
    print(-1)
# Judge status: Wrong Answer
x = int(input())/100

amt=100

t=0
while(amt<x):
  amt+= amt//100
  t+=1
  
print(t)
# Judge status: Accepted
x = int(input())

if x >= 30:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
a, b = list(map(int, input().split()))

ans = ""
if a <= b:
    for i in range(b):
        ans += str(a)
else:
    for i in range(a):
        ans += str(b)

print(ans)
# Judge status: Wrong Answer
N = int(input())
s = [input() for i in range(N)]
a = s.count("AC")
b = s.count("WA")
c = s.count("TLE")
d = s.count("RE")
print("AC * {}".format(a))
print("WA * {}".format(b))
print("TLE * {}".format(c))
print("RE * {}".format(d))
# Judge status: Wrong Answer
from sys import stdin
f_i = stdin

H, N = map(int, f_i.readline().split())

C = [10 ** 8] * (H * 2)
C[0] = 0
for line in f_i:
    A, B = map(int, line.split())
    for i, vals in enumerate(zip(C, C[A:]), start=A):
        v1, v2 = vals
        C[i] = min(v1 + B, v2)

print(min(C[H:]))
# Judge status: Accepted
A, B, C = list(map(int, input().split()))
print('Yes' if len(set([A, B, C]))==2 else 'No')
# Judge status: Accepted
n=int(input())
l=[int(input()) for i in range(5)]
for i in range(5):
    l[i]=int((n-1)/l[i])
print(max(l)+5)
# Judge status: Accepted
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b, c, d = rm()
if abs(a-c) <= d or abs(a-b) <= d and abs(b-c) <= d:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
a,b = map(int, input().split())

count = 0
for i in range(1,a+1):
    if int(str(i)+str(i)) <= int(str(a)+str(b)):
        count += 1

print(count)
# Judge status: Wrong Answer
X = int(input('今の温度は？>'))

if 40 >= X >= 30:
    command = 'yes'
elif 30 > X >= -40:
    command = 'no'
else:
    command = 'Error'
print(command)
# Judge status: Wrong Answer
S=input()
T=input()
a=0
l=len(T)-1
for i in range(len(S)-1,-1,-1):
  if S[i]=='?'or S[i]==T[l]:
    l-=1
  else:
    l=len(T)-1
  if l==-1:
    a=i
    break
if l!=-1:
  print('UNRESTORABLE')
else:
  c=0
  p=''
  for j in range(len(S)):
    if a<=j<a+len(T):
      p=p+T[c]
      c+=1
    else:
      if S[j]=='?':
        p=p+'a'
      else:
        p=p+S[j]
  print(p)
# Judge status: Wrong Answer
n = str(input())

if len(n) == 1:
  i = int(n)
else:
  i = int(n[-1:])

print(n[-1:])
  
if i in (2,4,5,7,9):
  print("hon")
elif i in (0,1,6,8):
  print("pon")
else:
  print("bon")
# Judge status: Accepted
HN=list(map(int,input().strip().split()))
H=HN[0]
N=HN[1]
A=list(map(int,input().strip().split()))

if sum(A)>=H:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
def q_d():
    n = int(input())
    a = list(map(int, input().split()))

    break_num = 0
    current_index = 1
    for i in range(n):
        if a[i] == current_index:
            current_index += 1
        else:
            break_num += 1

    if break_num == n:
        print(-1)
    else:
        print(break_num)


if __name__ == '__main__':
    q_d()
# Judge status: Accepted
n = int(input())
ans = 10**5+1
for a in range(1, n//2+1):
    a,b = list(str(a)), list(str(n-a))
    ans = min(ans, sum(list(map(int, a)))+sum(list(map(int, b))))
print(ans)
# Judge status: Wrong Answer
t,n=map(int,input().split())
count=0
for i in range(t):
	a,b=map(int,input().split())
	x=((a**2)+(b**2))**0.5
	if(x>=n):
		count+=1
print(count)
# Judge status: Accepted
S = input()
T = ['A', 'C', 'G', 'T']
ans, cnt = 0, 0

for i in range(len(S)):
    if S[i] in T:
        cnt += 1
        ans = max(ans, cnt)
    else:
        cnt = 0
print(ans)
# Judge status: Wrong Answer
N = int(input())
A = list(map(lambda a: int(a), input().split(" ")))
B = list(map(lambda b: int(b), input().split(" ")))
C = list(map(lambda c: int(c), input().split(" ")))
 
satis = 0
 
for i in range(len(A)):
  satis += B[A[i] - 1]
  if i >= 1 and A[i] - A[i-1] == 1:
    satis += C[i-1]
 
print(satis)
# Judge status: Accepted
s = input()
k = int(input())
for i, c in enumerate(s):
    if int(c)>1:
        if k<i+1:
            print(1)
        else:
            print(int(c))
        break
else:
    print(1)
# Judge status: Accepted
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
# Judge status: Accepted
f = [int(i) for i in input().split()]
n = f[0]
a = f[1]
b = f[2]

m = n // (a+b)
tmp = m * a
mod = n%(a+b)
print(tmp+min(mod,a))
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
print(c+b-a)
# Judge status: Accepted
def solve():
    H1,M1,H2,M2,K = map(int,input().split())
    M1 += H1 * 60
    M2 += H2 * 60
    print(M2-M1-K)

if __name__ == '__main__':
    solve()
# Judge status: Wrong Answer
S = input()
T = input()

if S in T:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n=int(input())
for i in range((n//4)+1):
  for j in range((n//7)+1):
    if n==4*i+7*j:
      print('Yes')
    else:
      print('No')
# Judge status: Accepted
n=int(input())
v=[]
for i in range(n):
  p=int(input())
  v.append(p)
vec=sorted(v)
for i in range(n):
  if v[i]==vec[n-1]:
    print(vec[n-2])
  else:
    print(vec[n-1])
# Judge status: Accepted
N,K=map(int,input().split())
A=list(map(int,input().split()))

ans=-(-(N-1)//(K-1))
print(ans)
# Judge status: Accepted
a,b=map(int,input().split())
for i in range(10*b,15*b):
  if int(i*0.08)==a and int(i*0.1)==b:
    print(i)
    exit()
print(-1)
# Judge status: Wrong Answer
N=int(input())
import collections
A=list(map(int,input().split()))

table=collections.defaultdict(int)
for x in A:
  table[x]+=1
table=list(table.items())
table=[x[0] for x in table if x[1]>1]
table.append(0)
table.append(0)
table.sort(reverse=True)
print(table[0]*table[1])
# Judge status: Wrong Answer
n,r = map(int,input().split())
print(r-(100*(10-n)))
# Judge status: Wrong Answer
n = int(input())
words = []
last = ''
ans = 'Yes'
for i in range(n):
  inp = input()
  if inp in words or last != inp[-1]:
    ans = 'No'
    break
  words.append(inp)
  last = inp[-1]
print(ans)
# Judge status: Accepted
S=input()
hug=0
for i in range(len(S)//2):
    if S[i]!=S[len(S)-i-1]:
        hug+=1
print(hug)
# Judge status: Accepted
k,s=map(int,input().split())
ans=0
for i in range(k+1):
    if s-i>=0:
        for j in range(min(s-i+1,k+1)):
            if s-i-j<=k and s-i-j>=0:
                ans+=1
print(ans)
# Judge status: Accepted
dur=int(input())
c=list(map(int,input().split()))
d=[0]*26
r=3
for i in range(dur):
  t=0
  s=list(map(int,input().split()))
  m=-1<<64
  for j in range(26):
    alt=s[j]+r*c[j]*(i+1-d[j])+sum([-r*c[k]*(i+1-d[k]) for k in range(26)])
    if alt>m:
      m=alt
      t=j
  print(t+1)
  d[t]=i+1
# Judge status: Accepted
n,k = map(int,input().split())
a = list(map(int,input().split()))

for _ in range(k):
    r = [0]*(n+1)
    for i in range(n):
        r[max(i-a[i],0)] += 1
        r[min(i+a[i]+1,n)] -= 1
    for i in range(n-1):
        r[i+1] += r[i]
    a = r
    if a.count(n)==n:
        break
print(*a[:-1])
# Judge status: Accepted
A,B=map(int,input().split())
cookie=[A,B,A+B]
for i in range(3):
    cookie[i]%=3

if 0 in cookie:
    print("Possible")
else:
    print("Impossible")
# Judge status: Accepted
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
L = [0] * N

for _ in range(M):
    a, b = map(int, readline().split())
    L[a - 1] += 1
    L[b - 1] += 1

for i in L:
    print(i)
# Judge status: Accepted
s=list(input())
K=int(input())
i=0
while i<len(s):
    if i==len(s)-1:
        s[i]=chr(97+(ord(s[i])-97+K)%26)
        break
    if K<abs(123-ord(s[i]))%26:
        i+=1
    elif K>=abs(123-ord(s[i]))%26:
        sub=abs(123-ord(s[i]))%26
        s[i]="a"
        K-=sub
        i+=1
print("".join(s))
# Judge status: Wrong Answer
a1, a2, a3 = map(int, input().split())
if a2+a2+a3 >= 22:
  print('bust')
else:
  print('win')
# Judge status: Accepted
a=list(map(lambda x:x,input().split()))
if(a[1]>a[0]):
  print(a[0]*int(a[1]))
else:
  print(a[1]*int(a[0]))
# Judge status: Accepted
N = int(input())
from collections import Counter
S = [''.join(sorted(input().rstrip())) for _ in range(N)]
ans = 0
for i in Counter(S).values():
    ans += i*(i-1)//2 
print(ans)
# Judge status: Accepted
n = int(input())
lst1 = list(map(int,input().split()))

lst2 = [0]*9

for i in range(n):
    for j in range(8):
        if lst1[i] < 400*(j+1):
            lst2[j] += 1
            break
    if lst1[i] >= 3200:
        lst2[8] += 1

ans = 0
for i in range(8):
    if lst2[i]:
        ans += 1

print(max(1,ans))
print(ans+lst2[8])
# Judge status: Accepted
N,K=map(int,input().split())
if N%K==0:
  print(0)
else:
  print(1)
# Judge status: Accepted
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
print(sum(a[0 : max(0, n - k)]))
# Judge status: Wrong Answer
k,a,b = map(int,input().split())
if b - a <= 1 or a >= k:
    print(k+1)
else:
    k -= a - 1
    ans = a
    ans += (b - a)*(k//2)
    if k/2 % 2 == 0:
        ans += 1
    print(ans)
# Judge status: Wrong Answer
def resolve():
    n = int(input())
    if n % 4 == 0 or n % 7 == 0 or n % 11 == 0 or (n % 11) % 4 == 0 or (n % 11) % 7 == 0:
        print("Yes")
    else:
        print("No")
        
resolve()
# Judge status: Accepted
def resolve(x,y):
    if (x+y)%2 == 1:
        return (x+y+1)//2
    else:
        return (x+y)//2
a,b=map(int,input().split())
print(resolve(a,b))
# Judge status: Wrong Answer
permutation_number = int(input())
permutation_value = list(map(int, input().split()))
condition_permutation = 0
for i in range(permutation_number - 1):
    if permutation_value[i - 1] < permutation_value[i] < permutation_value[i + 1] or permutation_value[i - 1] > permutation_value[i] > permutation_value[i + 1]:
        condition_permutation += 1
print(condition_permutation)
# Judge status: Accepted
# ABC148D

n = int(input())
a = list(map(int, input().split()))
if 1 not in a:
    print(-1)
else:
    count = 0
    find = 1
    for i in a:
        if i == find:
            find += 1
        else:
            count += 1
    print(count)
# Judge status: Accepted
s=input()
t=input()
ans=len(t)
cnt=0

for _ in range(len(s)):
  if _+len(t)>len(s):
    break
  mj=s[_:_+len(t)]
  for i in range(len(t)):
    if mj[i]!=t[i]:
      cnt += 1
  if ans>cnt:
    ans=cnt
  cnt=0
    
print(ans)
# Judge status: Accepted
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]


n,x = map(int, input().split())
l = list(map(int, input().split()))

temp = []

temp.append(0)
last = 0
for i in range(n):
    temp.append(last+l[i])
    last += l[i]
ans = 0
for i in range(n+1):
    if temp[i] <= x:
        ans += 1
print(ans)
# Judge status: Accepted
X = int(input())
amari = X % 500

print((X // 500)*1000 + (amari // 5 *5))
# Judge status: Accepted
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(n):
    for j in range(w+1):
        if j>=wv[i][0]:
            dp[i+1][j]=max(dp[i][j],dp[i][j-wv[i][0]]+wv[i][1])
        else:
            dp[i+1][j]=dp[i][j]
print(dp[-1][-1])
# Judge status: Accepted
n=int(input())-1
l=list(map(int,input().split()))
l.sort()
m=n//2
if l[m]==l[m+1]:
    print(0)
else:
    print(l[m+1]-l[m])
# Judge status: Wrong Answer
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
m=10**10
ans=0
for i in range(n):
    a=int(input())
    if a<=m:
        m=a
        ans+=1
print(ans)
# Judge status: Accepted
a, b, k =map(int, input().split())

if k <= a:
    a = a-k
    b = b

elif a+b <= k:
    a = 0
    b = 0

else:
    b = a+b-k
    a = 0
    

print(a, b)
# Judge status: Wrong Answer
print("bust" if sum(list(map(int, input().split()))) > 22 else "win")
# Judge status: Wrong Answer
n = input()
for i in n:
  if i == 7:
    print("Yes")
    quit()
print("No")
# Judge status: Accepted
import queue

N = int(input())
q = queue.Queue()
for i in range(1, 10):
    q.put(i)

ans = 0
for i in range(N):
    ans = q.get()
    m = ans % 10
    if ans % 10 != 0:
        q.put(ans * 10 + m - 1)
    q.put(ans * 10 + m)
    if ans % 10 != 9:
        q.put(ans * 10 + m + 1)

print(ans)
# Judge status: Wrong Answer
n=int(input())
if n%2==1:
  print(0)
else:
  c=0
  x=5
  while x<=n:
    c+=n//x
    x*=5
  print(c)
# Judge status: Accepted
a,b,c = map(int,input().split())
if a + b >= c:
	print("Yes")
else:
	print("No")
# Judge status: Accepted
A,B, C, K = map(int,input().split())
if K%2==0:
  print(A-B)
else:
  print(B-A)
# Judge status: Accepted
from collections import Counter
n=int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
ans=Counter(input())
for _ in range(n-1):
    temp=Counter(input())
    for char in alpha:
        ans[char]=min(ans[char],temp[char])
for char in alpha:
    for _ in range(ans[char]):
        print(char,end='')
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

total=0
for i in range(N):
    if A[i]-B[i]>=0:
        total+=B[i]
    elif A[i]-B[i]<0:
        total+=A[i]
        if A[i+1]-B[i]+A[i]>=0:
            total+=B[i]-A[i]
            A[i+1]-=B[i]-A[i]
        else:
            total+=A[i+1]
            A[i+1]=0
print(total)
# Judge status: Accepted
X, Y = map(int, input().split())
ans = -1
for i in range(10**8):
  Z = X*(i+2)
  if Z%Y != 0 and Z <= 10**18:
    ans = Z
    break
  if Z > 10**18:
    break
print(ans)
# Judge status: Wrong Answer
x = int(input())
#h, w = list(map(int, input().split()))
#((n+1)*n)//2 >= x
# (n+1)*n = 2*x
n = 1
a = ((n+1)*n)//2
while a < x:
    a = ((n+1)*n)//2
    n += 1
print(n-1)
# Judge status: Wrong Answer
n = list(map(int, input().split()))
print(n[1]*n[3])
# Judge status: Accepted
l = int(input(""))
a = 0.001
b = l - 2 * a
V = 0
V_vec = [0,0]
for i in range(l*999):
    if V < a * a * b :
        V = a * a * b
        V_vec = [a,b]
    a += 0.001
    b = l - 2 * a
print(V)