Problem:
 Score : 300 points    Problem Statement The commonly used bills in Japan are 10000 -yen, 5000 -yen and 1000 -yen bills. Below, the word "bill" refers to only these.  According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.      Constraints  1 ≤ N ≤ 2000  1000 ≤ Y ≤ 2 × 10^7  N is an integer.  Y is a multiple of 1000 .         Input Input is given from Standard Input in the following format:  N  Y       Output If the total value of N bills cannot be Y yen, print -1 -1 -1 .  If the total value of N bills can be Y yen, let one such set of bills be " x  10000 -yen bills, y  5000 -yen bills and z  1000 -yen bills", and print x , y , z with spaces in between. If there are multiple possibilities, any of them may be printed.        Sample Input 1 9 45000      Sample Output 1 4 0 5  If the envelope contained 4  10000 -yen bills and 5  1000 -yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9  5000 -yen bills, so the output 0 9 0 is also correct.       Sample Input 2 20 196000      Sample Output 2 -1 -1 -1  When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000 -yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.       Sample Input 3 1000 1234000      Sample Output 3 14 27 959  There are also many other possibilities.       Sample Input 4 2000 20000000      Sample Output 4 2000 0 0

Solution (Python):

import sys

def find_array(N: int, Y: int):
    for a in range(N + 1):
        for b in range(N - a + 1):
            c = N - a - b
            if a * 10000 + b * 5000 + c * 1000 == Y:
                return [a, b, c]
    return [-1, -1, -1]

def solve(N: int, Y: int):
    array = find_array(N, Y)
    print(' '.join(map(str,array)))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
 
def find_array(N: int, Y: int):
    for a in range(N + 1):
        for b in range(N - a + 1):
            c = N - a - b
            if a * 10000 + b * 5000 + c * 1000 == Y:
                return [a, b, c]
    return [-1, -1, -1]
 
def solve(N: int, Y: int):
    array = find_array(N, Y)
    print(' '.join(map(str,array)))
    return
 
 

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)
 
if __name__ == '__main__':
    main()

Solution (Python):

import sys

def find_array(N: int, Y: int):
    for a in range(N + 1):
        for b in range(N - a + 1):
            c = N - a - b
            if a * 10000 + b * 5000 + c * 1000 == Y:
                return [a, b, c]
    return [-1, -1, -1]

def solve(N: int, Y: int):
    array = find_array(N, Y)
    print(' '.join(map(str,array)))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)

if __name__ == '__main__':
    main()

Solution (Python):

import sys

def find_array(N: int, Y: int):
    for a in range(N + 1):
        for b in range(N + 1):
            if a + b > N:
                break
            c = N - a - b
            if a * 10000 + b * 5000 + c * 1000 == Y:
                return [a, b, c]
    return [-1, -1, -1]

def solve(N: int, Y: int):
    array = find_array(N, Y)
    
    print(' '.join(map(str,array)))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)

if __name__ == '__main__':
    main()

Solution (Python):
N, Y = map(int, input().split())
for n10k in range(N + 1):
    for n5k in range(N - n10k + 1):
        n1k = (N - n5k - n10k)
        if n10k * 10000 + n5k * 5000 + n1k * 1000 == Y:
            print(n10k, n5k, n1k)
            quit()
else:
    print(-1, -1, -1)

Solution (Python):
N, Y = list(map(int, input().split()))

flag = False
for x in range(N+1):
  for y in range(N-x+1):
    z = N - x - y
    if Y == 10000 * x + 5000 * y + 1000 * z:
      print(x, y, z)
      flag = True
      quit()
if ~flag:
  print("-1 -1 -1")

Solution (Python):
found = False
a, b = map(int, input().split())
for i in range(int(b/10000)+1):
    for j in range(int(int(b-i*10000)/5000)+1):
        if(i*10000+j*5000+1000*(a-i-j)==b):
            print(str(i)+" "+str(j)+" "+str(a-i-j))
            found = True
            break
    if(found):
        break
if not found:
    print("-1 -1 -1")

Solution (Python):
n,y=map(int,input().split())

n1=y//1000
n5=y//5000
n10=y//10000
for x1 in range(n1+1):
    if x1>n:continue
    for x5 in range(n5+1):
        x10=n-x1-x5
        if n10<x10:continue
        if x10<0:break
        if x1*1000+x5*5000+x10*10000==y and x1+x5+x10==n:
                print(x10,x5,x1)
                exit()
print(-1,-1,-1)

Solution (Python):
def solve(N, Y):
    for a in range(N + 1):
        for b in range(N + 1 - a):
            c = N - (a + b)
            if a * 10000 + b * 5000 + c * 1000 == Y:
                return a, b, c
    return -1, -1, -1


N, Y = [int(n) for n in input().split()]
print(*solve(N, Y))

Solution (Python):


def main():
    n, Y = map(int, input().split())

    total = 0
    flag = False
    res = [-1] * 3

    for x in range(n+1):
        total = 10000 * x

        if total == Y and x == n:
            res = [x, 0, 0]
            break

        for y in range(n-x+1):
            z = n - x - y
            total = 10000 * x + 5000 * y + 1000 * z

            if total == Y:
                res = [x, y, z]
                flag = True
                break
        
        if flag:
            break

    print(res[0], res[1], res[2])

if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, Y = MAP()

for i in range(Y//10000+1):
	rr = Y - 10000*i
	kk = N - i
	for j in range(rr//5000 + 1):
		remain = rr - 5000*j
		k = kk - j
		if k >= 0 and k*1000 == remain:
			print(i, j, k)
			exit()

print(-1, -1, -1)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, Y = MAP()

for i in range(N+1):
	for j in range(N+1-i):
		x = i
		y = j
		z = (Y - 10000*x - 5000*y)//1000

		if x+y+z == N:
			print(x, y, z)
			exit()

print(-1, -1, -1)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, Y = MAP()

for i in range(N+1):
	for j in range(N+1-i):
		remain = Y - 10000*i - 5000*j
		k = N - i - j
		if k >= 0 and remain >= 0 and k*1000 == remain:
			print(i, j, k)
			exit()

print(-1, -1, -1)

Solution (Python):
n, y = map(int, input().split())
for m10 in range(n+1):
    for m5 in range(n-m10 +1):
        m1 = n - m10 - m5
        if m10 *10000 + m5 * 5000 + m1 * 1000 == y:
            print(m10, m5, m1)
            exit(0)
print("-1 -1 -1")

Solution (Python):
n, d = map(int, input().split())
ans = [-1]*3
for x in range(n+1):
    for y in range(n-x+1):
        if d == 10000*x + 5000*y + 1000*(n-x-y):
            ans = [x, y, n-x-y]
        
        
        
        
        
print(*ans)

Solution (Python):
n, d = map(int, input().split())
ans = [-1]*3
for x in range(n+1):
    for y in range(n-x+1):
        zd = d - 10000*x - 5000*y
        if zd//1000 == n-x-y:
            ans[0] = x
            ans[1] = y
            ans[2] = zd//1000
            break
print(*ans)

Solution (Python):
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N-x+1):
        z = N-x-y
        if 0 <= z <= 2000 and 10000*x+5000*y+1000*z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Solution (Python):
from sys import stdin


def main(N,Y):
    if 10000*N < Y:
        return -1, -1, -1
    else:
        for a in range(N+1):
            for b in range(N+1-a):
                c = N-a-b
                if 10000*a+5000*b+1000*c == Y:
                    return a,b,c
        return -1, -1, -1

if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, Y = list(map(int,_in[0].split(' ')))
    
    a,b,c = main(N,Y)
    
    print(a,b,c)

Solution (Python):
N,Y = map(int,input().split())

ten=-1
five=-1
one=-1

for i in range(N+1):
    for j in range(0, N-i+1):
        k = N-i-j
        if(10000*i + 5000*j + 1000*k == Y):
            ten = i
            five = j
            one = k

out = str(ten) + ' ' + str(five) + ' ' + str(one)
print(out)

Solution (Python):
n,y=map(int,input().split())
flag=False
for a in range(n+1):
    for b in range(n-a+1):
        if y-10000*a-5000*b==1000*(n-a-b) and n-a-b>=0:
            print(a,b,n-b-a)
            flag=True
            break
    if flag: break
if flag==False: print("-1 -1 -1")

Solution (Python):
n,y=map(int,input().split())
flag=False
for a in range(n+1):
    for b in range(n-a+1):
        if y-10000*a-5000*b==1000*(n-a-b):
            print(a,b,n-b-a)
            flag=True
            break
    if flag: break
if flag==False: print("-1 -1 -1")

Solution (Python):
def main():
    N,Y = [int(x) for x in input().split()]
    for x in range(N+1):
        if 10000*x > Y:
            break
        for y in range(N+1):
            if 10000*x+5000*y > Y:
                break
            z = N-(x+y)
            if z < 0 or z > N:
                continue
            
            if Y == 10000*x+5000*y+1000*z:
                print(x,y,z)
                return
    print(-1,-1,-1)

if __name__ == '__main__':
    main()

Solution (Python):

N,Y = map(int, input().split())
A = B = C = -1
 
for i in range(N+1) :
    for j in range(N+1-i):
        k = N-i-j
        if 10000*i + 5000*j + 1000*k == Y:
            A = i
            B = j
            C = k
            break
    else:
        continue
    break
        
    
     
print(A,B,C)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    N, Y = map(int,input().split())

    for a in range(N+1):
        for b in range(N+1):
            if N-a-b>=0:
                c = N-a-b
            else:
                break
            if 10000*a+5000*b+1000*c == Y:
                print(a,b,c);exit()
    print(-1,-1,-1)

main()

Solution (Python):
def solve(N, Y):
    for x in range(0, N+1, 1):
        for y in range(0, N+1, 1):
            z = N - x - y
            if(z >= 0 and Y == 10000 * x + 5000 * y + 1000 * z):
                return (x, y, z)
    
    return (-1, -1, -1)



def main():
    N, Y = map(int, input().split())
    comb = solve(N, Y)
    print(*comb)
    




main()

Solution (Python):
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N-x+1):
        z = N-x-y
        if 0 <= z <= 2000 and 10000*x+5000*y+1000*z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Solution (Python):
def readinput():
    n,y=list(map(int,input().split()))
    return (n,y)

def main(n,y):
    k=0 
    l=0 
    m=0 
    
    kmax=y//10000
    for kk in range(kmax+1):
        res1=y-10000*kk
        lmax=res1//5000
        for ll in range(lmax+1):
            res2=res1-5000*ll
            m=res2//1000
            if(kk+ll+m==n):
                return (kk,ll,m)
    return(-1,-1,-1)

if __name__=='__main__':
    n,y=readinput()
    k,l,m=main(n,y)
    print(' '.join(map(str,(k,l,m))))

Solution (Python):
n, y = map(int, input().split())

flg = 0

def calc():
    global flg
    for i in range(n + 1):
        for j in range(n + 1):
            k = n - (i + j)
            if k < 0:
                break
            y_now = 10000 * i + 5000 * j + 1000 * k
            if i + j + k == n and y_now == y:
                print(i,j,k)
                flg = 1
                return

    if flg != 1:
        print('-1', '-1', '-1')

calc()

Solution (Python):
n, y = map(int,input().split())
 
for i in range(0,n+1):
  for j in range(0, n-i+1):
    if y == 10000*i + 5000*j + 1000*(n-i-j):
      print("{0} {1} {2}".format(i, j, n-i-j))
      exit()
print("-1 -1 -1")

Solution (Python):
import sys
n,y = map(int,input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i+5000*j+1000*(n-i-j) == y:
            print(str(i)+" "+str(j)+" "+str(n-i-j))
            sys.exit()
print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())


def isTrue(x, y, z, Y):
    if Y == 10000 * x + 5000 * y + 1000 * z:
        return True
    return False


for i in range(N + 1):
    for j in range(N - i + 1):
        if isTrue(i, j, N - i - j, Y):
            print(i, j, N - i - j)
            exit()

print(-1, -1, -1)

Solution (Python):


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

for i in range(N+1):
    for j in range(N+1-i):
        output = 10000 * i + 5000 * j + 1000 * (N-i-j)
        if output == Y:
            print(i,j,N-i-j)
            exit()
print(-1, -1, -1)

Solution (Python):
n,y = map(int,input().split())
for i in range(n+1):
  for j in range(n-i+1):
    if y == 10000*i+5000*j+1000*(n-i-j) :
      print(i,j,n-i-j)
      exit()
      
print(-1,-1,-1)

Solution (Python):
N,Y=map(int,input().split())
for x in range(N+1):
  for y in range(N+1-x):
    z=N-x-y
    if 10000*x+5000*y+1000*z==Y:
      print(x,y,z)
      exit()
print(-1,-1,-1)

Solution (Python):
import sys

n,y = map(int,input().split())
ans = 0

for i in range(n+1):
  for j in range(n+1):
    if 1000*(n-j-i) == y - 5000*i - 10000*j:
      if n-j-i>=0:
        ans +=1
        print(j,i,n-j-i)
        sys.exit()
 
if ans == 0:
  print("-1 -1 -1")

Solution (Python):
n, y = map(int, input().split())
existence = False
for i in range(n+1):
    for j in range(n+1-i):
        k = (y - 10000*i - 5000*j)/1000
        if k == n-i-j:
            print(i, j, int(k))
            existence = True
            break
    else:
        continue
    break

if not existence:
    print("-1 -1 -1")

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N, Y = map(int, readline().split())
    Y //= 1000
    for a in range(N+1):
        for b in range(N+1-a):
            if 10*a+5*b+(N-a-b)==Y:
                print(a, b, N-a-b)
                break
        else:
            continue
        break
    else:
        print('-1 -1 -1')

if __name__ == '__main__':
    main()

Solution (Python):
N, Y = map(int, input().split())
for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - x -y
        if 0 <= z <= 2000 and 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Solution (Python):
N, Y = [int(i) for i in input().split()]
flag = False
for x in range(N + 1):
    for y in range(N + 1 - x):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z
        if total == Y:
            flag = True
            print('{} {} {}'.format(x,y,z))
            break
    if flag:
        break
if not flag:
    print('-1 -1 -1')

Solution (Python):
import itertools

l = list(input().split())
n = int(l[0])
total = int(l[1])

exist = False
for x, y in itertools.product(range(0, n + 1), range(0, n + 1)):
    z = n - x - y
    if 0 <= z and  (x + y + z == n) and ((x * 10000 + y * 5000 + z * 1000) == total):
        print("{} {} {}".format(x, y, z))
        exist = True
        break

if not exist:
    print("-1 -1 -1")

Solution (Python):
import sys
N, Y  = map(int, input().split())
flag = False

for i in range(N+1): 
    for j in range(N-i+1): 
        k=N-i-j
            
        total = i*10000 + j*5000 + k*1000
           
        if(0<= k and total==Y):
            print(i, j, k)
            exit()

print(-1, -1, -1)

Solution (Python):
import sys
N, Y  = map(int, input().split())
flag = False

for i in range(N+1): 
    for j in range(N-i+1): 
        k=N-i-j
            
        total = i*10000 + j*5000 + k*1000
           
        if(0<= k <=2000 and total==Y):
            print(i, j, k)
            exit()

print(-1, -1, -1)

Solution (Python):
N,Y=map(int,input().split())
answer=-1,-1,-1
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            answer=x,y,z
            break
    else:
        continue
    break
print(*answer)

Solution (Python):
N, Y = map(int, input().split())
ans=[]
for i in range(N+1):
  for j in range(N+1-i):
    if Y-i*10000-j*5000==(N-i-j)*1000:
      ans.append([str(i), str(j), str(N-i-j)])
if not ans:
  print(-1, -1, -1)
else:
  print(' '.join(ans[0]))

Solution (Python):
N,Y = map(int,input().split())
Y /= 1000

T = int(Y // 10)
F = int(Y // 5)

for t in range(T+1):
  for f in range(F+1):
    o = N - t - f
    if o < 0:
      break
    if 10*t + 5*f + o == Y:
      print(t,f,o)
      exit()
print(-1,-1,-1)

Solution (Python):
n, total = map(int, input().split())

min = n * 1000
max = n * 10000
if (total > max) or (total < min):
    print('-1 -1 -1')
else:
    min_man = (total - (5000 * n)) // 10000 if total - (5000 * n) > 0 else 0
    n -= min_man
    total -= min_man*10000
    min_sen = (total % 5000) // 1000
    total -= min_sen*1000
    n -= min_sen
    success = False
    if total == 0:
        print(str(min_man) + ' 0 ' + str(min_sen))
    else:
        for i in range(int(total // 10000)+1):
            if success:
                break
            ii = total - i*10000
            for j in range(int(ii // 5000)+1):
                jj = ii - j*5000
                k = jj//1000
                if i + j + k == n:
                    print(str(i+min_man) + ' ' + str(j) + ' ' + str(k+min_sen))
                    success = True
                    break

        if not success:
            print('-1 -1 -1')

Solution (Python):
import sys
n, y = map(int, input().split())
a = y//10000
b = (y-a*10000)//5000
c = (y-a*10000-b*5000)//1000
if not (a+b+c<=n<=y//1000):
    print(-1, -1, -1)
    sys.exit()
for i in range(a, -1, -1):
    for j in range(b+2*(a-i), -1, -1):
        k = (y-i*10000-j*5000)//1000
        if n==i+j+k:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Solution (Python):
n,X =map(int,input().split())
count=0
for a in range(n+1):
    for b in range(n+1):
            if 10000*a + 5000*b + 1000*(n-a-b) == X and n-a-b >=0 and count == 0:
                print(a,b,n-a-b)
                count+=1
if count==0:
    print("-1 -1 -1")

Solution (Python):
n, y = map(int, input().split())

ans = [-1, -1, -1]

for i in range(n+1):
  for j in range(n-i+1):
    if (10000*i + 5000*j + 1000*(n-i-j)) == y:
      ans = [i, j, n-i-j]
      break

print(' '.join(map(str, ans)))

Solution (Python):
N, Y = map(int, input().split())
ans1 = ["-1", "-1", "-1"]
for i in range(0, N+1):
    for j in range(0, N+1):
        if N-j>=0 and N-i-j >= 0:
            if Y == 10000*i+5000*j+1000*(N-i-j):
                ans1 = [str(i), str(j), str(N-i-j)]
print(" ".join(ans1))

Solution (Python):
n,s = map(int,input().split())
s = s // 1000
xmax = s//10
ymax = s//5
if(xmax > 2000):
    xmax=2000
if(ymax > 2000):
    ymax = 2000
isloop = True
for x in range(xmax+1):
    
    if(isloop==False):
        break
    xv = x*10
    for y in range(ymax+1):
        
        if(isloop==False):
            break
        yv = y*5
        xysum = xv+yv
        if(xysum > s):
            continue
        
        z = (s-(xysum))
        if((x+z+y)==n):
            print(x,y,z)
            isloop=False
            break

if(isloop==True):
    print(-1,-1,-1)

Solution (Python):
n,s = map(int,input().split())
xmax = s // 10000
ymax = s // 5000
if(xmax > 2000):
    xmax=2000
if(ymax > 2000):
    ymax = 2000
isloop = True
for x in range(xmax+1):
    
    if(isloop==False):
        break
    xv = x*10000
    for y in range(ymax+1):
        
        if(isloop==False):
            break
        yv = y*5000
        xysum = xv+yv
        if(xysum > s):
            continue
        
        z = (s-(xysum))//1000
        if((x+z+y)==n):
            print(x,y,z)
            isloop=False
            break

if(isloop==True):
    print(-1,-1,-1)

Solution (Python):
n,s = map(int,input().split())

isloop = True
for x in range(2001):
    
    if(isloop==False):
        break
    xv = x*10000
    for y in range(2001):
        
        if(isloop==False):
            break
        yv = y*5000
        xysum = xv+yv
        if(xysum > s):
            continue
        
        z = (s-(xysum))//1000
        if((x+z+y)==n):
            print(x,y,z)
            isloop=False
            break

if(isloop==True):
    print(-1,-1,-1)

Solution (Python):
N,Y = map(int,input().split())
a=-1
b=-1
c=-1
for x in range(N+1):
    for y in range(N+1-x):
        if N - x - y >= 0 and 10000*x + 5000*y + 1000*(N - x - y) == Y:
            a = x
            b = y
            c = N - x - y
            break

print(a,b,c)

Solution (Python):
import sys
N,Y=[int(x) for x in input().rstrip().split()]

flag=0
for x in range(N+1):
  for y in range(N+1):
    if (x*10000+y*5000+(N-(x+y))*1000)==Y and 0<=N-(x+y):
      print(x,y,N-(x+y))
      flag=1
      sys.exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())

ans = [-1, -1, -1]
for i in range(N+1):
    for j in range(N+1-i):
        if 10000*i + 5000*j + 1000*(N-(i+j)) == Y:
            ans = [i, j, N-(i+j)]
            break
    else:
        continue
    break

print(str(ans[0]) + ' ' + str(ans[1]) + ' ' + str(ans[2]))

Solution (Python):
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N-x+1):
        z = N-x-y
        if 0 <= z <= 2000 and 10000*x+5000*y+1000*z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Solution (Python):
n,y=map(int,input().split())
Y=y//1000
a,b,c=0,0,0
for i in range(Y//10+1):
    rest=n-i
    for j in range(rest+1):
        k=rest-j
        if 10*i+5*j+k==Y:
            print(i,j,k)
            exit()
            
print('-1 '*3)

Solution (Python):
import math

def readInt():
	return int(input())
 
def readInts():
	return list(map(int, input().split()))
 
def readChars():
	return input().split()

N,Y = readInts()
o = Y



for x in range(Y//10000,-1,-1):
	o=Y-x*10000
	
	for y in range(o//5000,-1,-1):
		
		o=Y-x*10000-y*5000
		z=o//1000
		res = x*10000+y*5000+z*1000
		if x+y+z>N or res>Y:
			break
		if res==Y and x+y+z==N:
			print(str(x)+" "+str(y)+" "+str(z))
			exit()

print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())

Y = Y/1000



flag = False

i = -1
j = -1
k = -1
for x in range(N+1):
  for y in range(N+1-x):
    sum_ = 10 * x + 5 * y + (N-x-y)
    if sum_ == Y:
      i = x
      j = y
      k = N - x - y
      

print(i, j , k)

Solution (Python):
N,Y = map(int,input().split())
for i in range(N+1):
    for j in range(N+1):
        x = i
        y = j
        z = N-(x+y)

        if z < 0:
            break
        if (10000*x + 5000*y + 1000*z) == Y:
            print (x,y,z)
            exit ()
print (-1,-1,-1)

Solution (Python):
n, y = map(int, (input().split()))
 
for i in range(n+1):
  for j in range(n+1-i):
    k = n - i - j
    if 10000*i + 5000*j + 1000*k == y:
      print(i, j, k)
      break
  else:
    continue
  break
else:
  print(-1, -1, -1)

Solution (Python):
N,Y=map(int,input().split())
a=0
b=0
c=0

for i in range(2001):
    for j in range(2001):
        k=N-i-j
        if 10000*i+5000*j+1000*k==Y and k>=0:
            
            a=i
            b=j
            c=N-i-j
        else:
            pass

if a==0 and b==0 and c==0:
    print(-1,-1,-1)
else:
    print(a,b,c)

Solution (Python):
N,Y = map(int, input().split())


a = -1
b = -1
c = -1

flag = 0

'''
    if flag == 1:
        break
    if  Y - 10000 * i  ==0 and i==N:
        a = i
        b = 0
        c = 0
        flag = 1
'''

for i in range(N + 1):
    for j  in range(N+1- i):
        k = N - i -j
        if Y - 10000 * i - 5000 * j - 1000 * k == 0:
            a = i
            b = j
            c   = k
            flag = 1
            break


print(str(a) +' '+ str(b) +' '+ str(c))

Solution (Python):
N,Y = map(int, input().split())


a = -1
b = -1
c = -1

flag = 0

for i in range(N + 1):
    if flag == 1:
        break
    if  Y - 10000 * i  ==0 and i==N:
        a = i
        b = 0
        c = 0
        flag = 1

    if Y - 10000 * i > 0:
        for j  in range(N+1- i):
                k = N - i -j
                if Y - 10000 * i - 5000 * j - 1000 * k == 0:
                    a = i
                    b = j
                    c   = k
                    flag = 1
                    break


print(str(a) +' '+ str(b) +' '+ str(c))

Solution (Python):
N,Y=map(int,input().split())
n=Y//10000

if n>N:
    print("-1 -1 -1")
    exit()

for i in range(n+1):
    fukuzawa=10000*i
    x=i
    for j in range(N-x+1):
        higuchi=5000*j
        y=j
        if fukuzawa+higuchi+1000*(N-x-y)==Y:
            z=N-x-y
            print(x,y,z)
            exit()
print("-1 -1 -1")

Solution (Python):
N , Y= map(int,input().split())

for a in range(N + 1):
    be = N - a 
    for b in range(be + 1):
        c = N - b - a
        kingaku = 1000 * c + 5000 * b + 10000 * a

        if kingaku == Y:
            print(a,b,c)
          
            break
    else:
        continue
    break
                   

else:
    print(-1,-1,-1)

Solution (Python):
N,Y = map(int,input().split())

count = 0
Y //= 1000
for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if z < 0:
            break
        if x+5*y+10*z == Y:
            print(z,y,x)
            exit()
print(-1,-1,-1)

Solution (Python):
N,Y = map(int, input().split())
"""
・10000x+5000y+1000z=Y
・x+y+z=N
・z=N-(x+y)>=0 x+y<=N
"""

for x in range(N + 1):
    for y in range(N + 1 - x):
        R = Y - 10000 * x - 5000 * y
        z = N - (x + y)
        if 1000 * z == R:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Solution (Python):
N,Y = map(int, input().split())
"""
・10000x+5000y+1000z=Y
・x+y+z=N
・z=N-(x+y)>=0 x+y<=N
"""

for x in range(N + 1):
    for y in range(N + 1 - x):
        R = Y - 10000 * x - 5000 * y
        z = N - (x + y)
        if 1000 * z == R:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Solution (Python):
n, y = map(int, input().split())

for a in range(n, -1, -1):
    b_max = n-a
    for b in range(b_max, -1, -1):
        c = b_max-b
        sum = a*10000 + b*5000 + c*1000
        if sum == y :
            print(a, b, c)
            break
    else:
        continue
    break
else:
    print("-1 -1 -1")

Solution (Python):
n, y = map(int, input().split())

for a in range(n, -1, -1):
    b_max = n-a
    for b in range(b_max, -1, -1):
        c = b_max-b
        sum = a*10000 + b*5000 + c*1000
        if sum == y :
            print(a, b, c)
            break
    else:
        continue
    break
else:
    print("-1 -1 -1")

Solution (Python):
n,y=map(int,input().split())

for i in range(n+1):
  for j in range(n+1-i):
    k=n-i-j
    if 10000*i+5000*j+1000*k==y:
      print(i,j,k)
      exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())

match = False
for a in range(N+1):
    for b in range(N+1):
        c = N - (a + b)
        y = 10000*a + 5000*b + 1000*c
        if c >= 0 and y == Y:
            match = True
            break
    if match:
        break

if match:
    print(a, b, c)
else:
    print(-1, -1, -1)

Solution (Python):

n , t = map(int,input().split())
for i in range(n+1):
    for j in range(n+1-i):
        k = n - i- j

        
        if 10000 * i + 5000 * j + 1000 * k == t:

            print('{} {} {}'.format(i, j ,k))
            exit(0)
print('{} {} {}'.format(-1 ,-1,-1))

Solution (Python):
import math
N,Y = map(int, input().split())
x = -1
y = -1
z = -1
a = math.floor(Y/10000)
for i in range(a, -1, -1):
    money = Y - i*10000
    b = math.floor(money/5000)
    if i+b > N:
        b = N - i
    for j in range(b, -1, -1):
        money = Y - i*10000
        money = money - j*5000
        c = math.floor(money/1000)
        money = money - c*1000
        if (money == 0) and (i+j+c == N):
            print('{} {} {}'.format(i, j, c))
            exit()
print('{} {} {}'.format(x,y,z))

Solution (Python):

n, y = map(int, input().split())

d = {}
for k in range(n + 1):
    s = 1000 * k
    d[s] = k
f = False
for i in range(n + 1):
    for j in range(n + 1):
        total = 10000 * i + 5000 * j
        s = y - total
        if s in d:
            k = d.get(s)
            if i + j + k == n:
                print(i, j, k)
                f = True
                break
    if f:
        break
else:
    print(-1, -1, -1)

Solution (Python):
N, Y = map(int,input().split())
a = Y//10000
b = (Y-a*10000)//5000
c = (Y-a*10000-b*5000)//1000
d = Y//1000
if N<a+b+c or N>d:
  print('-1 -1 -1')
  exit()
else:
  check = False
  for i in range(1+a):
    for j in range(1+a-i):
      for k in range(1+a-i-j):
        for l in range(1+b):
          if 9*i+5*j+k+4*l == N-(a+b+c):
            print(a-i-j-k, b+j+2*k-l, c+10*i+j*5+l*5)
            check = True
            exit()
  if check == False: print('-1 -1 -1')