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())
s = (-1,-1,-1)
for i in range(n+1):
  m = n-i
  for j in range(m+1):
    k = m-j
    if i*10000+j*5000+k*1000 ==y:
      s = (i,j,k)
      break
print(s[0],s[1],s[2])

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

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

Solution (Python):
import sys
input=sys.stdin.readline
n,y=map(int,input().split())
y10,y5,y1=0,0,0
for i in range(n+1):
    for j in range(n+1):
        k=n-i-j
        if 10000*i+5000*j+1000*k==y and k>=0:
            print(i,j,k)
            exit(0)
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())

tf = False

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)
            tf = True
            break
    else:
        continue
    break

if tf is False:
    print(-1,-1,-1)

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

for m10 in range(N + 1):
    for m5 in range(N + 1 - m10):
        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, Y = map(int,input().split())

def answer():
    for n_10000 in range(N+1):
        for n_5000 in range(N+1):
            n_1000 = N - n_10000 - n_5000
            if n_1000 < 0:
                continue
            if n_10000 * 10000 + n_5000 * 5000 + n_1000 * 1000 == Y:
                return (n_10000, n_5000, n_1000)
    return (-1, -1, -1)
                
print(" ".join(list(map(str,answer()))))

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

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

res10000 =res5000 = res1000 = -1

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:
            res10000 = x
            res5000 = y
            res1000 = z

print(res10000, res5000, res1000)

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

Solution (Python):
n,y=map(int,input().split())
for i in range(2001):
    if ((y//1000 - n - 4*i)/9) % 1 == 0 and (y//1000 - n - 4*i)/9>=0 and n-(y//1000 - n - 4*i)/9-i>=0:
        print(int((y//1000 - n - 4*i)/9),i,int(n-(y//1000 - n - 4*i)/9-i))
        exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int,input().split())
y = Y/1000
ans_a = -1
ans_b = -1
for i in range(N+1):
    for j in range(N-i+1):
        if i*9 + j*4 + N == y:
            ans_a = i
            ans_b = j
if ans_a == -1:
    N = -3
print(str(ans_a)+' '+str(ans_b)+' '+str(N-ans_a-ans_b))

Solution (Python):
n , y = map(int,input().split())
y = y//1000
for i in range(y//10+1):
    y1 = y-10*i - n +i
    if y1 >=0 and y1%4 == 0 and n-i-y1//4>=0:
        print(i,y1//4,n-i-y1//4)
        exit()
print('-1 -1 -1')

Solution (Python):


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




i=0
j=0
k=0

ans="-1 -1 -1"
sum=0

for i in range(N+1):
    for j in range(N-i+1):
        k=N-i-j
        sum = 10000*i + 5000*j + 1000*k
        if sum==Y:
            ans = str(i) + " " + str(j) + " " + str(k)
            break

print(ans)

Solution (Python):
import sys

n_bills, sum_ = map(int, sys.stdin.readline().split())

sum_k = sum_ // 1000
max_n_10k = sum_k // 10
max_n_5k = sum_k // 5

found = True
for n_10k in range(max_n_10k + 1):
  for n_5k in range(min(max_n_5k + 1, n_bills - n_10k + 1)):
    if sum_k == n_10k * 10 + n_5k * 5 + (n_bills - n_10k - n_5k):
      print(n_10k, n_5k, n_bills - n_10k - n_5k)
      break
  else:
    continue
  break
else:
  found = False
  
if not found:
  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_m = Y-(10000*x+5000*y)
        z_n = N-x-y
        if z_m >=0 and z_m//1000 == z_n:
            print(x,y,z_n)
            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())
for i in range(n+1):
     for j in range(n+1-i):
        z_m=y-(10000*i+5000*j)
        z_n=n-(i+j)
        if z_m>=0 and z_m//1000==z_n:
          print(i,j,z_n)
          exit()
print(-1,-1,-1)

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

def solver(n,yen):
  for x in range(n+1):
    for y in range(n-x+1):
      z=n-x-y
      if x*10000+y*5000+z*1000 == yen:
        return x,y,z
  return -1,-1,-1
print(*solver(N,Yen))

Solution (Python):
import math
n,y = map(int,input().split())
y = y//1000
k = math.ceil(2*(y-n)/9)
if k*4 <= (y-n) and 5*k <= y:
  print(-4*k+y-n,9*k-2*(y-n),y-5*k)
else:
  print(-1,-1,-1)

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

cnt = 0

if not(y // 10 <= n <= y):
    print(-1, -1, -1)
else:
    for i in range(y+2):
        for j in range(y//5+2):
            if (y-i-5*j)==(n-i-j)*10 and n-i-j>=0:
                print(n-i-j, j, i)
                break
        else:
            continue
        break
    else:
        print(-1, -1, -1)

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

Solution (Python):
line = input().split()
sheet = int(line[0])
total = int(line[1])
out =[0,0,0]

cnt =0

  
for x in range(1,int(total/10000)+1):
  if (int((total/1000))-sheet-9*x) %4 ==0:
    y =int((int(total/1000)-sheet-9*x)/4)
    z =sheet - y - x
    if x + y + z ==sheet and z>=0 and y>=0 and cnt ==0:
      cnt +=1
      print(x,y,z)
  
for y in range(1,int(total/5000)+1):
  z =int(total/1000)-5*y
  if z>=0 and   y + z ==sheet and cnt==0:
    cnt +=1
    print(0,y,z)
if total/1000 ==sheet and cnt==0:
  cnt +=1
  print(0,0,int(total/1000))

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

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

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

    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:
                print(i, j, N-i-j)
                exit()
    print("-1 -1 -1")
if __name__ ==  "__main__":
    main()

Solution (Python):
def f(n, y):
    for i in range(n+1):
        for j in range(n-i+1):
            k = n - i - j
            if k >= 0:
                if y == i*10000 + j*5000 + k*1000:
                    print(i, j, k)
                    return
    print(-1, -1, -1)

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

Solution (Python):
N,Y = map(int, input().split())
"""多分n**2で間に合う"""
f = False
for i in range(N+1):
    for j in range(N+1-i):
        if (Y-(10000*i + 5000*j))//1000 ==N-(i+j) and (Y-(10000*i + 5000*j))>=0:
            f = True
            anls = [i,j,N-(i+j)]

if f:
    print(anls[0],anls[1],anls[2])
else:
    print(-1,-1,-1)

Solution (Python):



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

    
    ans_list = []
    for i in range(n + 1):
        if len(ans_list) > 0:
            break
        for j in range(n + 1 - i):
            k = n - i - j
            _sum = 10000 * i + 5000 * j + 1000 * k
            if _sum == y:
                ans_list.append(i)
                ans_list.append(j)
                ans_list.append(k)
                break

    if len(ans_list) == 0:
        print("-1 -1 -1")
    else:
        st = str(ans_list[0]) + " " + str(ans_list[1]) + " " + str(ans_list[2])
        print(st)


main()

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









l1, r1 = -((N-Y)//5), Y//5
l2, r2 = -((2*N-Y)//4), (Y-N)//4
l3, r3 = -((2*(N-Y))//9), (2*Y-N)//9
b1 = r2 < l1 or r1 < l2
b2 = r3 < l2 or r2 < l3
b3 = r1 < l3 or r3 < l1
if b1 or b2 or b3:
  print(-1, -1, -1)
else:
  k = max(l1, l2, l3)
  x, y = - 4 * k + Y - N, 9 * k - 2 * (Y - N)
  z = N - x - y
  print(x, y, z)

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

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

ans = [-1,-1,-1]
for i in range(0,n+1):
  for j in range(0,n+1):
    if i*10000 + j*5000 + (n-i-j)*1000 == y and n-i-j>=0:
      ans = [i,j,n-i-j]
      
print(ans[0],ans[1],ans[2])

Solution (Python):
def isValidNumOfBill(x, y, z, N):
    return x + y + z == N

def isValidSumOfMoney(x, y, z, Y):
    return 10000 * x + 5000 * y + 1000 * z == Y

def outputResult(x, y, z):
    print('{x:d} {y:d} {z:d}'.format(x=x, y=y, z=z))

def outputFailure():
    print('-1 -1 -1')

def searchA(N, Y):
    
    xlim = range(0, Y // 10000 + 1)
    ylim = range(0, Y // 5000 + 1)
    zlim = range(0, Y // 1000 + 1)

    for x in xlim:
        for y in ylim:
            for z in zlim:
                
                if not isValidNumOfBill(x, y, z, N):
                    continue
                if isValidSumOfMoney(x, y, z, Y):
                    return (x, y, z)

def searchB(N, Y):
    
    calcX = lambda Y: Y // 10000
    calcY = lambda x, Y: (Y - 10000 * x) // 5000
    calcZ = lambda x, y, Y: (Y - 10000 * x - 5000 * y) // 1000
    x = calcX(Y)
    y = calcY(x, Y)
    z = calcZ(x, y, Y)

    while x >= 0:
        while y >= 0:
            
            if sum((x, y, z)) == N:
                return (x, y, z)
            y -= 1
            z = calcZ(x, y, Y)
        x -= 1
        y = calcY(x, Y)
        z = calcZ(x, y, Y)

def main():
    
    args = input().split(" ")
    N = int(args[0])
    Y = int(args[1]) 

    
    
    result = searchB(N, Y)
    if result is not None:
        x, y, z = result
        outputResult(x, y, z)
    else:
        outputFailure()

if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, y = map(int, read().split())
for xx in range(n + 1):
    for yy in range(n + 1):
        v = 9 * xx + 4 * yy
        if v == y // 1000 - n:
            if n - xx - yy >= 0:
                print(xx, yy, n - xx - yy)
                exit()
print(-1, -1, -1)

Solution (Python):
import sys
inf = 10**15
mod = 10**9+7
n, y = map(int, input().split())
ans=0
A = y//10000
for i in range(A+1):
    restY = y-i*10000
    restN = n-i
    if restY >= 0 and restN >= 0:
        B = restY//5000
        for j in range(B+1):
            restYY = restY-j*5000
            restNN = restN-j
            if restNN>=0 and restYY == restNN*1000:
                print('{} {} {}'.format(i,j,restNN))
                sys.exit()
print('{} {} {}'.format(-1,-1,-1))

Solution (Python):
data = input().split(' ')
n = int(data[0])
y = int(data[1])
 
for cnt_10000 in range(n + 1):
    for cnt_5000 in range(n - cnt_10000 + 1):
        cnt_1000 = n - cnt_10000 - cnt_5000
        if 10000 * cnt_10000 + 5000 * cnt_5000 + 1000 * cnt_1000 == y:
            print('{} {} {}'.format(cnt_10000, cnt_5000, cnt_1000))
            exit(0)
print('{} {} {}'.format(-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)
5

Solution (Python):
import sys
def myAnswer(N:int,Y:int) -> None:
   for i in range(N+1):
      for j in range(N+1-i):
         if(10000*i + 5000*j + 1000*(N-i-j)==Y):
            print(i,j,(N-i-j))
            sys.exit()
   print(-1,-1,-1)

def modelAnswer():
   return
def main():
   N,Y = map(int,input().split())
   myAnswer(N,Y)
if __name__ == '__main__':
   main()

Solution (Python):
import sys


def __find_combination(bill_num, remained_amount) -> tuple:
    return next((
        (n10000, n5000, n1000)
        for n10000 in range(0, bill_num + 1)
        for n5000 in range(0, bill_num - n10000 + 1)
        for n1000 in [bill_num - n10000 - n5000]
        if n10000 * 10000 + n5000 * 5000 + n1000 * 1000 == remained_amount), (-1, -1, -1))


def main():
    input_str = sys.stdin.readline().split(" ")
    bill_num = int(input_str[0])
    total_amount = int(input_str[1])
    combination = __find_combination(bill_num, total_amount)
    print('%d %d %d\n' % combination)



if __name__ == '__main__':
    main()

Solution (Python):
N,X=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==X)and(0<=z)):
            print(x,y,z)
            exit()
print(-1,-1,-1)

Solution (Python):
N,X=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==X)and(0<=z)):
            print(x,y,z)
            exit()
print(-1,-1,-1)

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

yn=""
na=min(y//10000,2000)
nb=min(y//5000,2000)
for a in range(na+1):
    for b in range(nb+1):
        if y==10000*a+5000*b+1000*(n-a-b) and n>=a+b:
            print(a,b,n-a-b)
            yn="YES"
            break
    if yn=="YES":
        break
if yn!="YES":
    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=-1,-1,-1
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:
            ans=i,j,k
print(*ans)

Solution (Python):
N,Y = map(int,input().split())
for i in range(0,N+1):
    for j in range(0,N-i+1):
        k = N - i - j
        cal = 10000*i + 5000*j + 1000*k
        if cal == Y:
            ans = [i,j,k]
            break
    if cal == Y:
        break

if cal != Y:
    ans = [-1,-1,-1]

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

Solution (Python):
import sys
import string
import time


def input():
    return sys.stdin.readline().rstrip()


def I():
    return int(input())


def S():
    return input()


def MI():
    return map(int, input().split())


def MS():
    return map(str, input().split())


def LI():
    return list(map(int, input().split()))


def LI_():
    return [int(i) - 1 for i in input().split()]


def StoI():
    return [ord(i) - 97 for i in input()]


def ItoS(nn):
    return chr(nn + 97)


N = {False: 'No', True: 'Yes'}
MOD = 10 ** 9 + 7
inf = float('inf')
IINF = 10 ** 10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


def main():
    N, Y = MI()
    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('{} {} {}'.format(x, y, z))
                return
    print('-1 -1 -1')


if __name__ == '__main__':
    main()

Solution (Python):
n,y= map(int,input().split())
for i in range(n+1):
    for f in range(n+1):
        s = n-i-f
        if s<0:
            break
        if 10000*i + f*5000 +(n-i-f)*1000==y:
            print("{} {} {}".format(i,f,n-i-f))     
            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):
        if 10000 * x + 5000 * y > Y:break
        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]
ok = False
for x in range(N+1):
    for y in range((N+1)-x):
        if 10000 * x + 5000 * y > Y:break
        z = N - x- y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()
if not ok: print(-1, -1, -1)

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

if z == -1:
    print(-1, -1, -1)
else:
    print(x, y, z)

Solution (Python):
















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

for m1000 in range(0,N+1):
    for m5000 in range(0,N+1-m1000):
        m10000 = N - m1000 - m5000
        if m10000<0:
            continue
        if Y == m10000*10000 + m5000*5000 + m1000*1000:
            print(m10000,m5000,m1000)
            exit()
print(-1,-1,-1)

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

def solve():
  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)

x, y, z = solve()
print(x, y, z)

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(i,j,n-i-j)
            sys.exit()
print("-1 -1 -1")

Solution (Python):
def main():
    n, y = (int(x) for x in input().split())
    y = y//1000

    for i in range(n+1):
        for j in range(n+1):
            k = n - (i + j)
            if k >= 0 and 10*i + 5*j + k == y:
                return [i,j,k]
    return [-1,-1,-1]

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

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

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

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

print(*ans)

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

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

print(*ans)

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-i+1):
            if 10000*i+5000*j+1000*(N-i-j) == Y:
                    a=i
                    b=j
                    c=N-i-j
        
if(a>0)|(b>0)|(c>0):
    print(a,b,c)
elif (a==0)&(b ==0)&(c == 0):
    print(-1,-1,-1)

Solution (Python):
import sys

IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]

DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, y = MII()
    s = y - 1000*n
    for a in range(0,n+1):
        for b in range(0,n-a+1):
            if 9000*a+4000*b == s:
                print(a,b,n-(a+b))
                return None
    print('-1 -1 -1')

if __name__ == '__main__':
    main()

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

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

print(-1,-1,-1)

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

x = 0
flgA = False

while x <= N and flgA == False:
  y = 0
  while x + y <= N:
    z = N - (x + y)
    if Y == 10000*x + 5000*y + 1000*z:
      flgA = True
      print(str(x) + " " + str(y) + " " + str(z))
      break
    y = y + 1
  x = x + 1

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

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

def f():
  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:
        return i,j,k
  return -1,-1,-1

a,b,c = f()
print(a,b,c)

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

Solution (Python):
def solve():
    diff = Y - N
    if diff < 0:
        return -1, -1, -1
    for y in range(diff // 4 + 1):
        tmp = diff - 4 * y
        if tmp < 0:
            break
        if tmp % 9 == 0:
            x = tmp // 9
            if x >= 0 and N - x - y >= 0:
                return x, y, N - x - y
    return -1, -1, -1


N, Y = map(int, input().split())
Y //= 1000
ans = solve()
print(*ans)

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

def otoshidama():
    for i in range(0,n+1):
        for j in range(0,n+1-i):
            k = n-i-j
            if 10000*i + 5000*j + 1000*k == y:
                return i,j,k
    return -1,-1,-1

 
a, b, c = otoshidama()
print(a,b,c)

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

Solution (Python):


import sys

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

	
	N_max_1k = Y // 1000
	N_1k = -1
	N_5k = -1
	N_10k = -1

	if N == N_max_1k:
		
		N_1k = N_max_1k
		N_5k = 0
		N_10k = 0
	elif N < N_max_1k:
		
		
		N_diff = N_max_1k - N
		
		N_5k_values = (
			0,
			7,
			5,
			3,
			1,
			8,
			6,
			4,
			2,
		)
		N_5k = N_5k_values[N_diff % 9]
		N_1k = N_max_1k - N_5k * 5
		if N_1k < 0:
			
			N_1k = -1
			N_5k = -1
		else:
			
			
			
			
			N_10k = (N_diff - N_5k * 4) // 9
			if N_10k < 0:
				N_1k = -1
				N_5k = -1
				N_10k = -1
			else:
				N_1k = N - N_5k - N_10k
				if N_1k < 0:
					N_1k = -1
					N_5k = -1
					N_10k = -1

	print('%d %d %d' % (N_10k, N_5k, N_1k))


if __name__ == '__main__':
	main()

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

Solution (Python):
def main():
    n, yen = map(int,input().split())
    x = 0
    y = 0
    z = 0
    for x in range(n+1):
        for y in range(n+1):
            z = n - x - y
            if z < 0:
                break
            if x * 10000 + y * 5000 + z * 1000 == yen:
                print(x,y,z)
                return

    print(-1,-1,-1)

if __name__ =='__main__':
    main()

Solution (Python):
def main():
    n, yen = map(int,input().split())
    x = 0
    y = 0
    z = 0
    for x in range(n+1):
        for y in range(n+1):
            z = n - x - y
            if z < 0:
                break
            if x * 10000 + y * 5000 + z * 1000 == yen:
                print(x,y,z)
                return

    print(-1,-1,-1)

if __name__ =='__main__':
    main()

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()
else:
    print(-1,-1,-1)

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(0)
print(-1,-1,-1)

Solution (Python):


N, Y = map(int, input().split())
result_10000, result_5000, result_1000 = -1, -1, -1
found = False



for num_10000 in reversed(range(0, Y//10000 + 1)):
    y_10000 = Y - 10000 * num_10000
    n_10000 = N - num_10000
    if y_10000 == 0 and n_10000 == 0:
        result_10000, result_5000, result_1000 = num_10000, 0, 0
        found = True
        break
    else:
        for num_5000 in reversed(range(0, y_10000//5000 + 1)):
            y_5000 = y_10000 - 5000 * num_5000
            n_5000 = n_10000 - num_5000
            if y_5000 < 0 or n_5000 < 0:
                break
            if y_5000 == 0 and n_5000 == 0 and num_10000 + num_5000 == N:
                result_10000, result_5000, result_1000 = num_10000, num_5000, 0
                found = True
                break
            else:
                
                num_1000 = y_5000 // 1000
                y_1000 = y_5000 - 1000 * num_1000
                n_1000 = n_5000 - num_1000
                if y_1000 == 0 and n_1000 == 0 and num_10000 + num_5000 + num_1000 == N:
                    result_10000, result_5000, result_1000 = num_10000, num_5000, num_1000
                    found = True
                    break
            if found:
                break
        if found:
            break
    
print(result_10000, result_5000, result_1000)

Solution (Python):
import sys
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)
      sys.exit(0)
else:
  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):
    k=N-i-j
    if 10000*i+5000*j+1000*k==Y:
      print(i,j,k)
      sys.exit(0)
else:
  print(-1,-1,-1)

Solution (Python):

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

	
	for i in range(Y // 10000 + 1):
		y = Y - i * 10000
		for j in range(y // 5000 + 1):
			k = (y - j * 5000) // 1000
			if i + j + k == N:
				print('%d %d %d' % (i, j, k))
				exit(0)
	print('-1 -1 -1')


if __name__ == '__main__':
	main()

Solution (Python):
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)
      exit()
else:
  print(-1,-1,-1)

Solution (Python):
import sys
input = sys.stdin.readline
n,y = map(int,input().split())
for i in range(y//10000+2):
    for j in range(y//5000+2):
        if 9000*i + 4000*j == y - 1000*n and n-i-j >= 0:
            print(i,j,n-i-j)
            break
    else:
        continue
    break
else:print(-1,-1,-1)

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

change = False

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)
            change = True
            exit()
if change != True:
    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-i+1):
    k = N-i-j
    total = 10000*i + 5000*j + 1000*k
    if total == 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(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(0, N + 1):
    for b in range(0, N - a + 1):
        c = N - a - b
        if (10000 * a + 5000 * b + 1000 * c) == Y:
            print(a, b, c)
            exit()
print(-1, -1, -1)