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):
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]))

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]))

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
        sm = 10000 * x + 5000 * y + 1000 * z
        if sm == Y:
            print(x, y, z)
            exit(0)
print(-1, -1, -1)

Solution (Python):
n,y = map(int,input().split())
u = [10000,5000,1000]
x = []
for i in range(0,n+1):
    for j in range(0,n-i+1):
        w = n-i-j
        if u[2]*i+u[1]*j+u[0]*w == y:
              x = [w,j,i]
              break

if len(x) == 0:
    print("-1 -1 -1")
else:
    print(" ".join(map(str,x)))

Solution (Python):
N, Y= list(map(int, input().split()))
ans = []
for i in range(N+1):
    for j in range (N-i+1):
        k = N-i-j 
        if 0<= k <= 2000 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 i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        if i*10000+j*5000+k*1000==y:
            print(i, j, k)
            exit()
print(-1, -1, -1)

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

print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
for i in range(2001):
	for j in range(2001):
		if (y-(10000*i+5000*j))//1000==n-i-j and n-i-j>=0:
			print(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):

        k = N - i - j

        if i * 10000 + j * 5000 + k * 1000 == Y:
            print (i,j,k)
            sys.exit()

print (-1,-1,-1)

Solution (Python):
def main():
    n, y = map(int, input().split())
    flag = False
    for i in range(n+1):
        for j in range(n+1):
            if i + j <= n and y == i * 10000 + j * 5000 + (n - i - j) * 1000:
                print(i, j, (n - i -j))
                flag = True
                if flag:
                    break
        else:
            continue
        break
    if not flag:
        print('-1 -1 -1')
if __name__ == '__main__':
    main()

Solution (Python):
n,kingaku = map(int,input().split())
all1000 = n*1000
if all1000>kingaku:
    print(-1,-1,-1)
    exit()
x = 0
y = 0
z = n
for i in range(n+1):
    x=i
    for j in range(n+1):
        z=n-(i+j)
        y=j
        if z<0:
            break
        money = x*10000 + y*5000 + z*1000
        if money == kingaku:
            print(x,y,z)
            exit()
print(-1,-1,-1)

Solution (Python):
n,kingaku = map(int,input().split())
all1000 = n*1000
if all1000>kingaku:
    print(-1,-1,-1)
    exit()
x = 0
y = 0
z = n
for i in range(n+1):
    z=n-i
    x=i
    for j in range(n+1):
        z=n-(i+j)
        y=j
        if z<0:
            break
        money = x*10000 + y*5000 + z*1000
        if money == kingaku:
            print(x,y,z)
            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-a):
    c = N - a - b
    if 10000 * a + 5000 * b + 1000 * c == Y:
      print(a,b,c)
      exit()
        
print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
y //= 1000
for i in range(n+1):
    p,q = divmod(y-n-i,4)
    if q == 0 and i <= p-i <= n:
        print(i,p-2*i, n-p+i)
        exit()
print("-1 "*3)

Solution (Python):
n,y=map(int,input().split())
y //= 1000
for i in range(n+1):
    for j in range(n-i+1):
        if 9*i + 4*j + n == y:
            print(i,j,n-i-j)
            exit()
print("-1 "*3)

Solution (Python):
N, Y = map(int, input().split())
a = 0
b = 0
c = 0
for i in range(N+1):
    for j in range(N+1):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y and N-i-j>=0:
            a = i
            b = j
            c = N-i-j
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())
for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - x - y
        if x * 10000 + y * 5000 + z * 1000 == 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-i+1):
    k = N-i-j
    if i*10000+j*5000+k*1000 == Y:
      print(i, j, k)
      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):
        if 10000*x + 5000*y + 1000*(N-(x+y)) == Y and N-(x+y) >= 0:
            print(x, y, N-(x+y))
            exit()
 
print(-1,-1,-1)

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    def check(n, y):
        for a in range(n + 1):
            for b in range(n - a + 1):
                c = n - (a + b)
                if 10 * a + 5 * b + c == y:
                    return (a, b, c)
        return (-1, -1, -1)


    n, y = mi()
    if y % 1000 != 0:
        print("-1 -1 -1")
    else:
        y //= 1000
        
        print("{} {} {}".format(*check(n, y)))


if __name__ == "__main__":
    main()

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

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

print(-1,-1,-1)

Solution (Python):
from itertools import permutations
num, target = map(int, input().split(" "))
coin = [1000, 5000, 10000]
for i in range(num + 1):
    for j in range(num + 1 - i):
        k = num - i - j
        if target == (1000 * k + 5000 * j + 10000 * i):
            print(i, j, k)
            exit()
else:
    print(-1, -1, -1)

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

Solution (Python):
import sys
N,Y = map(int,input().split())
        
for A in range(N+1)[::-1]:
  for B in range(N-A+1)[::-1]:
    C=N-A-B
    if (10000*A+5000*B+1000*C==Y):
      print(A,B,C)        
      sys.exit()
print(-1,-1,-1)

Solution (Python):
def main():
    n, sum = list(map(int,input().split()))
    x_max = sum // 10000
    for x in reversed(range(0, x_max + 1)):
        y_max = (sum - x * 10000) // 5000
        for y in reversed(range(0, min(n - x + 1, y_max + 1))):
            z = n - x - y
            if 10000 * x + 5000 * y + 1000 * z == sum:
                    print(x, y, z)
                    return 0
    print('-1 -1 -1')
    return 0

main()

Solution (Python):
def main():
    n, sum = list(map(int,input().split()))
    x_max = sum // 10000
    for x in reversed(range(0, x_max + 1)):
        for y in range(n - x + 1):
            z = n - x - y
            if 10000 * x + 5000 * y + 1000 * z == sum:
                    print(x, y, z)
                    return 0
    print('-1 -1 -1')
    return 0

main()

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

m_x, m_y, m_z = (-1, -1, -1)
for x in range(Y // 10000 + 1):
    for y in range(N - x + 1):
        z = N - x - y
        total = 10000 * x + 5000 * y + 1000 * z
        if total == Y:
            m_x, m_y, m_z = (x, y, z)
            break
        else:
            if total > Y:
                break
            else:
                continue

print(m_x, m_y, m_z)

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

for A in range(N+1):
  for B in range(N-A+1):
    C=N-A-B
    if (10000*A+5000*B+1000*C==Y):
      print(A,B,C)        
      sys.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 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())
ans = [-1,-1,-1]
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: 
      ans[0]= x
      ans[1]= y
      ans[2]= z
      break
    else: continue

if ans[0]==-1:print("-1 -1 -1")
else:
  print("{} {} {}".format(ans[0],ans[1],ans[2]))

Solution (Python):
def main():
    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:
                if 10000 * a + 5000 * b + 1000 * c == y:
                    print(a, b, c)
                    exit()
                else:
                    pass
            else:
                break
    print("-1 -1 -1")



if __name__ == "__main__":
    main()

Solution (Python):
N,Y=map(int,input().split())
Y/=1000
for i in range(0,N+1):
    for j in range(0,N-i+1):
        if(10*i+5*j+N-i-j==Y):
            print(str(i)+" "+str(j)+" "+str(N-i-j))
            exit()
print("-1 -1 -1")

Solution (Python):
N,Y = (int(x) for x in input().split())
y = Y // 1000
for i in range(N+1):
    for j in range(N+1-i):
        if 10*i + 5*j + (N-i-j) == y:
            print(i,j,N-i-j)
            break
    else:
        continue
    break
else:
    n = -1
    print(n,n,n)

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

maxy = int(Y /5000)
if maxy >= N:
    maxy = N

flag = False

for x in range(N+1):
    for y in range(maxy+1):
        if N - x - y < 0:
            break
        else:
            z = N - x -y
        if Y == 10000*x + 5000*y + 1000*z:
            print("{} {} {}".format(x,y,z))
            flag = True
            break
    if flag:
        break

if flag == False:
    print("-1 -1 -1")

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

for i in range(N+1):
    if count==0:
        pass
    else:
        break
    for j in range(N-i+1):
        if 10000*i+5000*j+1000*(N-i-j)==Y:
            print(i,j,N-i-j)
            count+=1
            break
        else:
            pass
if count==0:
    print(-1,-1,-1)
else:
    pass

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())

flg = False


for i in range(n + 1):
    for j in range(n + 1 - i):
        k = (y - 10000 * i - 5000 * j) // 1000
        if i + j + k == n and not flg:
            flg = True
            print(i, j, k)
            break
    else:
        continue
    break

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

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

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

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

for i in range(y//10000 + 1):
    for j in range((y - i*10000)//5000 + 1):
        k = (y - 10000*i - 5000*j)//1000        
        if i + j + k == n:
            print(i,j,k)
            flag = False
            break
    if flag:
        continue
    else:
        break            
else:
    print("-1 -1 -1")

Solution (Python):
import sys
num, price = map(int,sys.stdin.readline().rstrip().split())
for x in range(num+1):
  for y in range(num-x+1):
    sum = x *1000 + y * 5000 + (num-x-y) * 10000
    if sum == price:
      print(num-x-y,y,x)
      sys.exit()
print(-1,-1,-1)

Solution (Python):
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

n,y = imap()
b = (2*n + 7*y)%9
a,mod = divmod(y - 1000*n - 4000*b, 9000)
c = n - b - a
ans = [a,b,c] if all([i>=0 for i in [a,c]]) and mod==0 else [-1,-1,-1]
print(*ans)

Solution (Python):


N,Y = map(int, input().split())
ans= [-1, -1, -1]

for x in range(N+1):
    for y in range(N-x+1):
        price = x*10000 + y*5000 + int(N-x-y)*1000

        if price == Y:
            ans = [x,y,N-x-y]
            break
            
    if price == Y: 
        break

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

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

for x in range(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)
            exit()

print(-1, -1, -1)

Solution (Python):
N, Y = map(int, input().split())
ans = [-1, -1, -1]

for x in range(N+1):
    for y in range(0, N-x+1):
        z = N - (x + y)
        if 10000*x + 5000*y + 1000*z == Y:
            ans[0] = x
            ans[1] = y
            ans[2] = z
            break

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

Solution (Python):
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

n,y = imap()
ans = [-1,-1,-1]
for a in range(n+1):
    for b in range(n-a+1):
        c = n - a - b
        if 10000*a + 5000*b + 1000*c == y:
            ans = [a,b,c]; break

print(*ans)

Solution (Python):
N, Y = map(int, input().split())
for i in range(N + 1):
    for j in range(N + 1 - i):
        if N - i - j < 0:
            break
        if 9000 * i + 4000 * j == Y - 1000 * N:
            print(i, j, N - i - j)
            exit()
print(-1, -1, -1)

Solution (Python):
n, y = map(int, input().split())
n_1000 = 0
n_5000 = 0
n_10000 = 0
key = 0
for i in range(n+1):
    for j in range(n+1-i):
        total = 1000*i + 5000*j + 10000*(n-i-j)
        if total == y:
            key = 1
            n_1000 = i
            n_5000 = j
            break
        else:
            continue
if key == 1:
    print(n-n_1000-n_5000, n_5000, n_1000, sep=' ')
else:
    print(('-1 -1 -1'))

Solution (Python):
n,y = map(int,input().split())
ans = [-1,-1,-1]
cnt = 0

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

Solution (Python):
n,y = map(int,input().split())
ans = [-1,-1,-1]
cnt = 0

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

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N, Y = map(int, input().split())
    for i in range(N+1):
        for j in range(N+1-i):
            if i*10000 + j*5000 + (N-i-j)*1000 == Y:
                print(i, j, N-i-j)
                break
        else:
            continue
        break
    else:
        print(-1,-1,-1)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

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

    summary = 0
    for i in range(n+1):
        for j in range(n+1):
            if i+j > n:
                continue
            summary = 10000*i+5000*j+1000*(n-i-j)
            if summary == y:
                print(i,j,n-i-j)
                return
    print(-1,-1,-1)


if __name__ == '__main__':
    main()

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

Solution (Python):
N, Y =map(int, input().split())
X = [-1,-1,-1]
for i in range(2001):
  y = (Y-1000*N-9000*i)/4000
  if not float.is_integer(y):
    continue
  if 0<= N-i-y <= 2000 and 0<= y <= 2000:
    X=[i, y, N-i-y]
    X=list(map(int, X))
    break
print(*X)

Solution (Python):
n,y=(int(x) for x in input().split())
flag = False
n=n+1
for i in reversed(range(n)):
  for j in reversed(range(n-i)):
    k=n-i-j-1
    if 10000*i+5000*j+1000*k == y :
      print(i,j,k)
      flag = True
      break
  if flag:
    break
  
if not flag :
  print(-1,-1,-1)

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

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



m = Y / 1000
for a in range(N+1):
    z = m - 10*a
    if z < 0:
        break
    for b in range(N-a+1):
        y = z - 5*b
        if y < 0:
            break
        if y == N-a-b:
            print(a,b,N-a-b)
            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):
        x=i
        y=j
        z=n-i-j
        if 10000*x + 5000*y + 1000*z == Y:
            print(x,y,z)
            exit()
print(-1,-1,-1)

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

for x in range(n+1):
    for y in range(n+1-x):
        tmp = n-x-y
        if (x*10000+y*5000+tmp*1000) == s:
            print('{} {} {}'.format(x,y,tmp))
            exit(0)

print('-1 -1 -1')

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline

def main():
    n,y = map(int,read().split())
    for i in range(n+1):
        for j in range(n-i+1):
            if i*1000 + j*5000 + (n-i-j)*10000 == y:
                print("{} {} {}".format(n-i-j,j,i))
                return
    print("-1 -1 -1")
if __name__ == '__main__':
    main()

Solution (Python):
def judge(N,Y):
    a,b,c = 10000,5000,1000
    if Y % c != 0 or Y < c or N*a < Y:
        return (-1,-1,-1)
    else:
        a,b,c,Y = a//1000,b//1000,c//1000,Y//1000
        for s in range(N+1):
            for t in range(N-s+1):
                u = N-s-t
                if a*s + b*t + c*u == Y:
                    return (s,t,u)
        return (-1,-1,-1)

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

    ans = judge(N,Y)
    print(" ".join(map(str,ans)))

if __name__ == "__main__":
    main()

Solution (Python):
def judge(N,Y):
    a,b,c = 10000,5000,1000
    if Y % c != 0 or Y < c or N*a < Y:
        return (-1,-1,-1)
    else:
        a,b,c,Y = a//1000,b//1000,c//1000,Y//1000
        for s in range(N+1):
            for t in range(N-s+1):
                u = N-s-t
                if a*s + b*t + c*u == Y:
                    return (s,t,u)
        return (-1,-1,-1)

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

    ans = judge(N,Y)
    print(" ".join(map(str,ans)))

if __name__ == "__main__":
    main()

Solution (Python):
N, Y = map(int, input().split())
 
ans10000, ans5000, ans1000 = -1, -1, -1
for i in range(0, N+1):
    for j in range(0, (N+1)-i):
        k = N - (i + j)
        if k >= 0:
            o = 10000*i + 5000*j + 1000*k
            if o == Y:
                ans10000 = i
                ans5000 = j
                ans1000 = k
                
print(ans10000, ans5000, ans1000)

Solution (Python):
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

def main():
    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
            if 10000*i + 5000*j + 1000*k == y:
                return i,j,k
                
    return -1,-1,-1

if __name__=='__main__':
    print(*main())

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

for i in range(N+1):
  y1 = 10000 * i
  for j in range(N+1-i):
    y2 = 5000 * j
    if y1 + y2 > Y:
      break
    
    k = (Y - y1 - y2) // 1000
    if i + j + k == N:
      print(i, j, k)
      quit()

print(-1, -1, -1)

Solution (Python):
N,Y=map(int, input().split())
flag=0
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)
      flag=1
      break
  else:
    continue
  break
if flag==0:
  print('-1 -1 -1')

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

for x in range(N+1):
    for y in range(N-x+1):
        z = N-x-y
        if x*1000+y*5000+z*10000 == Y:
            print(z,y,x)
            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):
        k = N-i-j
        if i * 10000 + j *5000 + k *1000 ==Y:
            print(str(i)+" "+str(j)+" "+str(k))
            exit()
print("-1 -1 -1")

Solution (Python):
def solve(n, y):

    a = 0
    ans = "-1 -1 -1"
    while a <= n :
        
        c = (y - 5000*(a+n)) // (-4000) if (y - 5000*(a+n)) % (-4000) == 0 else -1
        
        b = n - a - c
        if b >= 0 and c >= 0:
            ans = "{0} {1} {2}".format(a, b, c)
            break
        else:
            a += 1

    return ans

if __name__ == "__main__":
    n,y = [int(i) for i in input().split()]
    print(solve(n, y))

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 x*10000 + y*5000 + z*1000 == Y:
            answer = x, y, z
            break
    else:
        continue
    break

print(*answer)

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  10000*x+5000*y+1000*z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

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

ok = False
ans = (-1,-1,-1)
for i in range(N+1):
  for j in range(N-i+1):
    k = N - i - j
    t = 10000 * i + 5000 * j + 1000 * k
    if Y == t:
      ok = True
      ans = (i,j,k)
      break
  if ok:
    break

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

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

finded = False
for sen in range(n+1):
    for gosen in range(n+1-sen):
        if 1000*sen + 5000*gosen + 10000*(n-sen-gosen) == y:
            print(n-sen-gosen,gosen,sen,sep=' ')
            finded = True
            break
    if finded:
        break

if not finded:
    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):
        z = N-x-y
        if 0<=z<=2000 and x*10000+y*5000+z*1000 == Y:
            print(x,y,z)
            exit()
print(-1,-1,-1)

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

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

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

for a in range(N+1):
    for b in range(N-a+1):
        c = N - a - b
        total = 10000 * a + 5000 * b + 1000 * c
        if Y == total:
            x = a
            y = b
            z = c

print(str(x)+" "+str(y)+" "+str(z))

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

c = 0

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

Solution (Python):
N, Y = map(int, input().split())        
Anser = [-1, -1, -1]

flag = False

for i in range(N+1):
    if flag == True: break
    for j in range(N+1-i):
        if flag == True: break
        if Y == 10000*i + 5000*j +1000*(N-i-j): 
            Anser =[i, j, N-i-j]
            flag = True

print(*Anser)

Solution (Python):
def f04():
    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
        
    print(*answer)

f04()

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 = [int(x) for x in input().split(' ')]

def solve(n,y):
    for a in range(n+1):
        for b in range(n+1):
            c = n - a - b
            if c >= 0:
                current = 10000*a + 5000*b + 1000*c
                if current == y:
                    print(a,b,c)
                    return
    
    print(-1, -1, -1)

solve(n,y)

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):
vals=input().split(' ')
N=int(vals[0])
Y=int(vals[1])

for s in range(N,-1,-1):
  for m in range(N-s,-1,-1):
    l=N-s-m
    if l*10000+5000*m+1000*s == Y:
      print (l,m,s)
      exit()
print (-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())
ans = (-1, -1, -1)
for x in range(N + 1):
    xm = 10000 * x
    if xm > Y:
        break
    for y in range(N - x + 1):
        z = N - x - y
        if xm + 5000 * y + 1000 * z == Y:
            ans = (x, y, z)
            break
    else:
        continue
    break

print(*ans)

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

print(*ans)

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

print(*ans)

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

print(*ans)