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
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *













































def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007




def main():
	N,Y = inputMap()

	for man in range(N+1):
		for gosen in range(N-man+1):
			tmp = man*10000 + gosen*5000 + 1000*(N-man-gosen)

			if tmp == Y:
				print("{} {} {}".format(man,gosen,N-man-gosen))
				sys.exit()

	print("{} {} {}".format(-1,-1,-1))







def bisect_left_reverse(a, x):
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok

def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok





def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None




def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)




def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y




def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv



def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)



if __name__ == "__main__":
	main()

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
flag = False
for x in reversed(range(N + 1)):
    for y in reversed(range(N + 1 - x)):
        z = N - x - y
        if 10 * x + 5 * y + 1 * z == Y:
            print(x, y, z)
            flag = True
            break
    else:
        continue
    break

if not flag:
    print(-1, -1, -1)

Solution (Python):
N, Y = map(int, input().split())
flag = False
for x in reversed(range(N + 1)):
    for y in reversed(range(N + 1 - x)):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            flag = True
            break
    else:
        continue
    break
if not flag:
  print(-1, -1, -1)

Solution (Python):
n,y=map(int,input().split())
flag=False
for i in range(0,n+1):
  if flag:
    break
  for j in range(0,n+1):
    if (n-i-j)>=0 and i*10000+j*5000+(n-i-j)*1000==y:
      print(i,j,(n-i-j))
      flag=True
      break
if flag==False:
  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 k>=0 and 10000*i+5000*j+1000*k==Y:
            print(i,j,k)
            exit()
print(-1,-1,-1)

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

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

x = -1
y = -1
z = -1
if Y%1000 == 0:
  Y = Y//1000
  n = (Y-N)//9
  for i in range(n+1):
    if ((Y-N)-9*i)%4==0 and (Y-N)>=9*i and N>=i+((Y-N)-9*i)//4:
      x = i
      y = ((Y-N)-9*i)//4
      z = N-x-y
      break
print(x,y,z,sep=' ')

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

Solution (Python):
n, y = map(int, input().split())
max_x = y // 10000
max_y = y // 5000
max_z = y // 1000

for i in range(max_x + 1):
    for j in range(max_y + 1):
        remain = y - 10000 * i - 5000 * j
        if remain < 0:
            continue
        if remain // 1000 == n - (i + j):
            print(i, j, (n - i - j))
            exit()
print(-1, -1, -1)

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,y = readInts()
for m in range(n+1):
    for f in range(n-m+1):
        
        if 10000 * m + 5000 * f + 1000 * (n - m - f) == y:
            print(m,f,(n-m-f))
            exit()
print(-1,-1,-1)

Solution (Python):
import itertools

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

l = list(range(n+1))
for v, vv in itertools.combinations_with_replacement(l, 2):
    itiman = v
    gosen = vv - v
    sen = n - vv
    if y == itiman*10 + gosen*5 + sen:
        print(itiman, gosen, sen)
        exit()
print(-1, -1, -1)

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

for x in range(N+1):
    for y in range(N-x+1):
        z = N - x - y
        if 10*x  + 5*y + z == Y:
            print(x, y, z)
            exit()

print(-1, -1, -1)

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

Solution (Python):
N,Y = map(int,input().split())
if Y-1000*N<0:
    a1 = -1
    a2 = -1
    a3 = -1
else:
    flag = 0
    for i in range((Y//1000-N)//9+1):
        if (Y//1000-N-9*i)%4==0:
            a1 = i
            a2 = (Y//1000-N-9*i)//4
            a3 = N-a1-a2
            if a1>=0 and a2>=0 and a3>=0:
                flag = 1
                break
    if flag==0:
        a1 = -1
        a2 = -1
        a3 = -1
print(a1,a2,a3)

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

for x in range(n+1):
  for y in range(n+1):
    z = n-x-y
    if z < 0: continue
    if 10000*x + 5000*y + 1000*z == Y:
      print(x,y,z)
      exit()
print(-1,-1,-1)

Solution (Python):
N, Y=list(map(int, input().split()))
ans=[-1, -1, -1]
flag=False
for x in range(N, -1, -1):
    for y in range(N-x, -1, -1):
        if 10000*x+5000*y+1000*(N-x-y)==Y:
            ans=[x,y,N-x-y]
            flag=True
            break
        if flag==True:
            break
    if flag==True:
        break
print(ans[0],ans[1],ans[2])

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

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

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()

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

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

Solution (Python):
import sys
input = sys.stdin.readline

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

for i in range(N+1):
    for j in range(N-i+1):
        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()))

for i in range(2001):
    a = i
    b = (y-10000*a-1000*n+1000*a) / 4000
    c = n-a-b
    if b == int(b) and c == int(c) and b >= 0 and c >= 0:
        print(a, int(b), int(c))
        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
from itertools import accumulate, permutations, combinations, product
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
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):
		k = N-i-j
		if k < 0:
			continue
		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())
for i in range(n+1):
	if 10000*i > y:
		break
	for j in range(n+1-i):
		if 10000*i+5000*j > y:
			break
		elif 10000*i+5000*j+1000*(n-i-j) == y:
			print(i, j, n-i-j)
			exit()
print(-1, -1, -1)

Solution (Python):
n,y= map(int, input().split())
x=[]
for i in range(0,n+1):
    for j in range(0,n+1-i):
        k=n-i-j
        if y==10000*i+5000*j+1000*k:
            x.append(i)
            x.append(j)
            x.append(k)
if not x:
    print('-1 -1 -1')
else:
    print(x[0],x[1],x[2])

Solution (Python):
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n,y = nm()

for i in range(2001):
    for j in range(2001):
        k = n - i - j
        res = 10000*i + 5000*j + 1000*k
        if k >= 0 and res == y:
            print(i,j,k)
            sys.exit(0)
else:
    print(-1,-1,-1)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot





N, Y = getNM()

n10k = Y // 10000
ans = []
for i in range(n10k + 1):
    left5 = Y - (i * 10000)
    n5k = left5 // 5000
    for j in range(n5k + 1):
        left1 = left5 - (j * 5000)
        l = left1 // 1000
        if i + j + l == N:
            ans = [i, j, l]
if len(ans) == 0:
    print(-1, -1, -1)
else:
    print(*ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot





N, Y = getNM()

n10k = Y // 10000
ans = []
for i in range(n10k + 1):
    left5 = Y - (i * 10000)
    n5k = left5 // 5000
    for j in range(n5k + 1):
        left1 = left5 - (j * 5000)
        l = left1 // 1000
        if i + j + l == N:
            ans = [i, j, l]
if len(ans) == 0:
    print(-1, -1, -1)
else:
    print(*ans)

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]







N,Y=l()
ans=[-1,-1,-1]
for i in range(N+1):
    for j in range(N+1):
        if(i+j>N):
            break
        z=N-i-j
        if(i*1000+j*5000+z*10000==Y):
            ans=[z,j,i]
            break
    if(ans!=[-1,-1,-1]):
        break
print(*ans)

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

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

print('-1 -1 -1')

Solution (Python):
def main():
    N,Y = map(int, input().split())
    
    for x in range(min(Y//10000+1, N+1)):
        for y in range(min((Y-x)//5000+1, N+1)):
            z = (Y-10000*x-5000*y)//1000
            if (Y-10000*x-5000*y)%1000==0 and z>=0 and (x+y+z)==N:
                ans = [x,y,z]
                print(*ans)
                return
    ans = [-1,-1,-1]
    print(*ans)
main()

Solution (Python):
N, Y = map(int,(input().split()))
a = min(Y // 10000,N)
flag = False

if Y == N * 10000:
    print(str(N) + ' 0 0')
else:
    for i in range(a+1):
        for j in range(N-i+1):
            k = N-i-j
            temp = (i * 10000) + (j * 5000) + (k * 1000)
            if temp == Y:
                print(str(i) + ' ' + str(j) + ' ' + str(k))
                flag = True
                break
        if flag:
            break

    if flag is not True:
        print('-1 -1 -1')

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

x, y, z = -1, -1, -1

for a in range(N+1):
    for b in range(N+1-a):
        if 10000*a + 5000*b + 1000*(N-a-b) == Y:
            x, y, z = a, b, N-a-b
        
print("{} {} {}".format(x,y,z))

Solution (Python):

import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement


from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter





j=0
k=0
n=3
r=1
a=[0]






"1行1つの整数を入力を取得し、整数と取得する"




"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''


'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD
combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        
        if n % k == 0:
            return False
            
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  

'''

def factorial(x, mod=10**9+7):
    
    
    
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''
"
def gcd(a, b):
    while b:
        
        
        a, b = b, a % b
    return a

"
def lcm(a, b):
    return a * b // gcd (a, b)

"
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table











'''
ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'
hexdigits = '0123456789abcdefABCDEF'
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv...\xaf\xb0...
lowercase = 'abcdefghijklmnopqrstuvwxyz'
octdigits = '01234567'
printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU...
punctuation = '!"
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
whitespace = '\t\n\x0b\x0c\r '
'''
'''
引数endに任意の文字列を指定すると、その文字列が改行の代わりに最後に挿入される。例えば連続するprint()の出力を改行なしで単純に連結したい場合は空文字列''を指定すればよい。

print('abc', end='---')
print('xyz')


print('abc', end='')
print('xyz')

source: print_basic.py
なお、デフォルトで改行されるのは引数endのデフォルト値が改行文字'\n'に設定されているから。
'''

def main():
    n=3
    steps=0
    state=0
    w=1
    j=0
    k=0
    
    
    
    n,y=map(int, input().split(" "))
    time10=-1
    time5=-1
    time1=-1
    if y%1000!=0:
        print(str(time10)+" "+str(time5)+" "+str(time1))
        sys.exit()
    time10=y//10000
    for i in range(time10+1):
        yex=y-10000*i
        time5=yex//5000
        for j in range(time5+1):
            yey=yex-5000*j
            time1=yey/1000
            
            if (i+j+time1)==n:
                print(str(i)+" "+str(j)+" "+str(int(time1)))
                sys.exit()
    time10=-1
    time5=-1
    time1=-1

    print(str(time10)+" "+str(time5)+" "+str(time1))

    
    
    
    
    
    
    


    
    
     

    l = ['aaa', 'bbb', 'ccc']
    x=l.index('aaa')
    
    
    
    

    
        
    
    

    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    
        
        
    
    
        
        
    


    
    



    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]
    

    ls = ["a", "b", "c", "d", "e"]


    
    

    
    

    
    
    
    
    
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

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

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

res10000 = -1
res5000 = -1
res1000 = -1

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

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

for i in range(N+ 1):
  for j in range(N+ 1- i):
    k = N- i- j
    if(10* i+ 5* j+ k == y):
      print("{} {} {}".format(i, j, k))
      b = True
      break
  if(b == True):
    break
    
if(b == False):
  print("-1 -1 -1")

Solution (Python):
def check(x, y, z):
    return 10000*x + 5000*y + 1000*z

def main():
    N, Y = map(int, input().split())
    for x in range(2001):
        if 10000*x > Y:
            break
        for y in range(0, 2001):
            z = N - (x+y)
            if z < 0:
                break
            if check(x, y, z) == Y:
                ans = (x, y, z)
                print(*ans)
                return
            if check(x, y, z) > Y:
                break
    ans = [-1, -1, -1]
    print(*ans)

if __name__ == "__main__":
    main()

Solution (Python):
def check(x, y, z):
    return 10000*x + 5000*y + 1000*z

def main():
    N, Y = map(int, input().split())
    for x in range(2001):
        for y in range(0, 2001):
            z = N - (x+y)
            if z < 0:
                break
            if check(x, y, z) == Y:
                ans = (x, y, z)
                print(*ans)
                return
            if check(x, y, z) > Y:
                break
    ans = [-1, -1, -1]
    print(*ans)

if __name__ == "__main__":
    main()

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

print(-1, -1, -1)

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

Solution (Python):
import sys
def S(): return sys.stdin.readline().rstrip()

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

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

print('-1 -1 -1')

Solution (Python):
def main():
  ans = [-1, -1, -1]
  N, Y = map(int, input().split())
  for i in range(N+1):
    for j in range(N+1-i):
      if 1000*i + 5000*j + 10000*(N-i-j) == Y:
        ans = [N-i-j, j, i]
  print(*ans)
if __name__ == "__main__":
  main()

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

for a in range(n + 1):
    b = (y - n - 9 * a) // 4
    c = n - a - b
    if 10 * a + 5 * b + c == y and b >= 0 and c >= 0:
        print(a, b, c)
        exit()

print(-1, -1, -1)

Solution (Python):
n, y = map(int, input().split())
c = int(y/1000)
flag = False
for i in range(c//9+1):
    for j in range((c-n-9*i)//4+1):
        if n-i-j < 0:
            break
        if c - 9*i - 4*j == n:
            flag = True
            break      
    if flag:
        break
if flag:
    print(i, j, n-i-j)
else:
    print(-1, -1, -1)

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

i_t = j_t = k_t = -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:
            i_t = i
            j_t = j
            k_t = k
print(str(i_t), str(j_t), str(k_t))

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

x=-1
y=-1
z=-1
bp=0

for i in range(N+1):
    for j in range(N+1-i):
        if Y==9000*i+4000*j+1000*N:
            x=i
            y=j
            z=N-i-j
            bp=1
            break
    if bp==1:
        break
        
print("{} {} {}".format(x,y,z))

Solution (Python):
from sys import stdin
def LI(): return list(map(int,stdin.readline().rstrip().split()))
 
inp = LI()
n,Y = [inp.pop(0) for _ in range(2)]

Y = Y//1000
for i in range(n,-1,-1):
    if 10*i<=Y:
        for j in range(n-i,-1,-1):
            tmp = 10*i+5*j+n-i-j
            if tmp == Y:
                print(str(i)+' '+str(j)+' '+str(n-i-j))
                exit()
            elif tmp < Y:
                break

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+1-i):
        tmp=1000*(n-i-j)+5000*i+10000*j
        if tmp==y:
            print(j,i,n-i-j)
            sys.exit()
print(-1,-1,-1)

Solution (Python):




import sys
from fractions import gcd
import math
from math import ceil,floor
import collections











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



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

Solution (Python):


num,total = map(int,input().split())

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

Solution (Python):
N,Y=map(int,input().split())
A=[]
for i in range(Y//10000+1):
    for j in range((Y-i*10000)//5000+1):
        c1=(Y-10000*i-5000*j)/1000
        c2=N-i-j
        if c1==c2:
            A=[i,j,c1]
            break
        if c1!=c2:
            continue
if len(A)==0:
    print("-1 -1 -1")
else:
    A[2]=int(A[2])
    
    print(str(A[0])+" "+str(A[1])+" "+str(A[2]))

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

for a in range(n + 1):
    for b in range(n + 1):
        c = n - a - b
        if c >= 0 and  a * 10000 + b * 5000 + c * 1000 == y:
            print(a, b, c)
            exit()
print('-1', '-1', '-1')

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

num_of_a = 0
num_of_b = 0
num_of_c = 0
flg = 0

while num_of_a <= n:
    remain1 = n - num_of_a
    num_of_b = 0
    num_of_c = 0
    while num_of_b <= remain1:
        remain2 = remain1 - num_of_b
        num_of_c = remain2
        ans = num_of_a*10000 + num_of_b*5000 + num_of_c*1000

        if ans == y:
            flg = 1
            break
        else:
            num_of_b += 1
    if flg == 1:
        break
    num_of_a += 1

if num_of_a == n+1:
    print("-1 -1 -1")
else:
    print(str(num_of_a)+" "+str(num_of_b)+" "+str(num_of_c))

Solution (Python):
N,Y=map(int,input().split())
A=[]
for i in range(Y//10000+1):
    for j in range((Y-i*10000)//5000+1):
        c1=(Y-10000*i-5000*j)//1000
        c2=N-i-j
        if c1==c2:
            A=[i,j,c1]
            break
        if c1!=c2:
            continue
if len(A)==0:
    print("-1 -1 -1")
else:
    A[2]=int(A[2])
    print(str(A[0])+" "+str(A[1])+" "+str(A[2]))

Solution (Python):
N,Y=map(int,input().split())
A=[]
for i in range(Y//10000+1):
    for j in range((Y-i*10000)//5000+1):
        c1=(Y-10000*i-5000*j)//1000
        c2=N-i-j
        if c1==c2:
            A=[i,j,c1]
            break
        if c1!=c2:
            continue
if len(A)==0:
    print("-1 -1 -1")
else:
    A[2]=int(A[2])
    
    print(str(A[0])+" "+str(A[1])+" "+str(A[2]))