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(" "))
ans=0
a=(-1)
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)
            ans=1
            exit()
if ans==0:
    print(a,a,a)

Solution (Python):
a,b=map(int,input().split())
c=(b-1000*a)//1000
f=True
for i in range(a+1):
    d=c-9*i
    if d>=0 and d%4==0 and i+d//4<=a:
        print(i,d//4,a-i-d//4)
        f=False
        break
if f:print("-1 -1 -1")

Solution (Python):
def solve():
    n, y = map(int, input().split())
    y = y // 1000
    for nogu in range(n+1):
        for higu in range(n + 1 - nogu):
            yuki = n - higu - nogu
            total = yuki*10 + higu*5 + nogu
            if total == y:
                print(yuki, higu, nogu)
                return
    print("-1 -1 -1")

solve()

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(0, N + 1) :
    for j in range(0, N + 1 - i) :
        if i * 10000 + j * 5000 + (N - i - j) * 1000 == Y :
            print(i, j, N - i - j)
            flg = True
            break
            
    if flg == True :
        break
if flg == False :
    print(-1, -1, -1)

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

flag = False
for i in range(n+1):
    for j in range(n-i+1):
        sum = 10000*i + 5000*j + 1000*(n-i-j)
        if sum == y:
            flag = True
            print('{} {} {}'.format(i,j,n-i-j))
            break
    if flag:
        break

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

Solution (Python):


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

def solve():
    if y%1000 != 0:
        return -1,-1,-1
    for i in range(y//10000+1)[::-1]:
        for j in range((y-10000*i)//5000+1)[::-1]:
            k = n - i - j
            sum = 10000*i + 5000*j + 1000*k
            if sum == y:
                return i,j,k
    return -1,-1,-1

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

Solution (Python):

import itertools

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

    
    money_flag = 0

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

    
    if money_flag == 0:
        print(-1, -1, -1)

if __name__ == '__main__':
    main()

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

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

print("-1 -1 -1")

Solution (Python):
N, Y = map(int,input().split())
for i in range(2001):
    for j in range(2001):
        k = N - i -j
        if (k < 0):
            break
        if (10000 * i + 5000 * j + 1000 * k == Y):
            print(str(i) + ' ' + str(j) + ' ' + str(k))
            quit()
print("-1 -1 -1")

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

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

Solution (Python):
def search(N,Y):
    exist = False
    
    yukichi_max = Y//10000
    for yukichi in range(yukichi_max+1):
        ichiyo_max = (Y-yukichi*10000)//5000
        for ichiyo in range(ichiyo_max+1):
            hideyo = N-yukichi-ichiyo
            
            if (yukichi*10000 + ichiyo*5000 + hideyo*1000) == Y:
                return yukichi, ichiyo, hideyo
                
                
    if not exist:
        return (-1,-1,-1)

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

    
print(*search(N,Y))

Solution (Python):
N,Y = map(int,input().split())
Y = int(Y/1000)
a = b = c = 0
flag = True
for a in range(int(Y//10)+1):
  for b in range(int((Y-10*a)//5)+1):
    c = Y-10*a-5*b
    if a+b+c == N and flag:
      flag = False
      print(a,b,c)
if flag:
  print(-1,-1,-1)

Solution (Python):
N, Y  = map( int, input().split())
Y = Y/1000
ichiman = -1
gosen = -1
sen = -1
Flag = False
if N*10 < Y:
    Flag = True
for i in range(N+1):
    for j in range(N-i+1):
        if i*10 + j*5 + (N-i-j) == Y:
            ichiman = i
            gosen = j
            sen = N-i-j
            Flag = True
            break
    if Flag:
        break

print('{} ' '{} ' '{}'.format(ichiman, gosen, sen))

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 i in range(N+1):
  for j in range(i,N+1):
    if 10000*i + 5000*(j-i) + 1000*(N-j) == Y:
      ans = " ".join(list(map(str,[i,j-i,N-j])))
      
print(ans)

Solution (Python):
N, Y = list(map(lambda x: int(x), input().split(" ")))
flag = False
ans = []

for a in range(2001):
  for b in range(2001):
    if 9000 * a + 4000 * b == (Y - 1000 * N) and a + b <= N:
      flag = True
      ans.append((a, b, (N-a-b)))

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

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

Solution (Python):
n, y = [int(i) for i in input().split()]

for a in range(n + 1):
    if 10000 * a <= y:
        tmp_a = y - 10000 * a

        for b in range(n + 1 - a):
            if 5000 * b <= tmp_a:
                tmp_b = tmp_a - 5000 * b

                c = n - a - b
                if 1000 * c <= tmp_b:
                    tmp_c = tmp_b - 1000 * c
                    if tmp_c == 0:
                        print("%d %d %d" % (a , b, c))
                        exit(0)

print("-1 -1 -1")

Solution (Python):
n,y=map(int,input().split())
a=0
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:
            a+=1
        else:
            pass
        if a == 1:
            print(i,j,k)
            break
        else:
            pass
    if a >= 1:
        break
if a ==0:
    print(-1, -1, -1)
else:
    pass

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

YUKICHI = 10000
ICHIYO = 5000
HIDEYO = 1000

def conf_N(N,Y):
    yukichi = Y//YUKICHI
    
    for y in range(yukichi+1):
        ichiyo = (Y-y*YUKICHI)//5000
        for i in range(ichiyo+1):
            hideyo = (Y-y*YUKICHI-i*ICHIYO)//1000
            
            if y+i+hideyo == N:
                return [y,i,hideyo]
    
    return [-1,-1,-1]


ans = conf_N(N,Y)
print(*ans)

Solution (Python):

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


def greedy(Y):
    res = Y
    yukichi = 0
    ichiyo = 0
    hideyo = 0
    while res >= 10000:
        res -= 10000
        yukichi += 1
        
    while res >= 5000:
        res -= 5000
        ichiyo += 1
        
    while res > 0:
        res -= 1000
        hideyo += 1
        
    return yukichi, ichiyo, hideyo
    

def confirm_N(N,Y,yukichi,ichiyo,hideyo):
    bill = yukichi+ichiyo+hideyo
    if N<bill:
        return [-1,-1,-1]
    elif N == bill:
        return [yukichi, ichiyo, hideyo]
    
    while yukichi >= 0:
        if bill == N:
            return [yukichi, ichiyo, hideyo]
        
        while ichiyo > 0:
            bill += 4
            hideyo += 5
            ichiyo -= 1
            if bill == N:
                return [yukichi, ichiyo, hideyo]
        
        yukichi -= 1
        ichiyo = (Y-yukichi*10000) // 5000
        hideyo = (Y-yukichi*10000-ichiyo*5000) // 1000
        
        bill = yukichi+ichiyo+hideyo
    
    return [-1,-1,-1]



yukichi, ichiyo, hideyo = greedy(Y)

bill = yukichi+ichiyo+hideyo

ans_lst = confirm_N(N, Y, yukichi, ichiyo, hideyo)

print(*ans_lst)

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
		result = 10000 * i + 5000 * j + 1000 * k
		if (result == Y):
			print('{} {} {}'.format(i, j, k))
			exit()

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):
        x=10000*i+5000*j+1000*(n-i-j)
        if x==y:
            flag=1
            res=(i,j,n-i-j)
if flag==0:
    print(-1,-1,-1)
else:
    print(res[0],res[1],res[2])

Solution (Python):
r = []
A = input().split(" ")
N,Y = map(int,A)
a = -1
b = -1
d = -1
for i in range(N+1):
    for j in range(N+1):
        c = (N-i)-j
        if c >= 0 and Y == 10000*i+5000*j+1000*c:
            a = i
            b= j
            d = c
print("{0} {1} {2}".format(a,b,d))

Solution (Python):
n,y = map(int,input().split())
man, gosen, sen =-1,-1,-1
for i in range(n+1):
    for j in range(n+1-i):
        if 1e+4*i+5e+3*j+1e+3*(n-i-j)==y:
            man, gosen, sen = i, j, n-i-j
            break
print(man, gosen, sen)

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

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

print('-1 -1 -1')

Solution (Python):
if __name__ == '__main__':
    N, Y = list(map(int, input().split()))

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

Solution (Python):
if __name__ == '__main__':
    N, Y = list(map(int, input().split()))

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

Solution (Python):
n,y=map(int,input().split())
for a in range(n+1):
    for b in range(n-a+1):
        c=n-a-b
        if 10*a+5*b+c==y/1e3:
            print(a,b,c)
            exit()
print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split(" "))
found = False
for x in range(N + 1):
    if 10000 * x + 5000 * (N - x) + 1000 * (N - x) < Y:
        continue
    for y in range(N - x + 1):
        if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y:
            print("{} {} {}".format(x,y,N - x - y))
            found = True
            break
        if found:
            break
    if found:
        break
else:
    print("-1 -1 -1")

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

a = 10000
b = 5000
c = 1000

flg_exists = False 

for i in range(N + 1) :
    for j in range(N - i + 1) :
        k = N - i - j
        
        if a * i + b * j + c * k == Y and i + j + k == N :
            print(i, j, k)
            flg_exists = True
            break
    if flg_exists == True :
        break
            
if flg_exists == False :
    print(-1, -1, -1)

Solution (Python):


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


def solve(n, y):
    for a in range(n + 1):
        rest = y - 10000 * a
        if rest < 0:
            break
        if rest == 0 and a == n:
            return a, 0, 0

        bc = n - a
        all_c = 1000 * bc
        rest = rest - all_c
        if rest >= 0 and rest % 4000 == 0:
            b = rest // 4000
            c = bc - b
            if b >= 0 and c >= 0:
                return a, b, c

    return -1, -1, -1


result = solve(N, Y)
print(str(result[0]) + ' ' + str(result[1]) + ' ' + str(result[2]))

Solution (Python):

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

    for i in range(n+1):
        y1 = 10 * i
        for j in range(n-i+1):
            y2 = 5 * j
            if y < y1 + y2:
                break
            
            if y == y1 + y2 + (n-j-i):
                print(i, j, n-j-i)
                return

    print(-1, -1, -1)

if __name__ == '__main__':
    main()

Solution (Python):
N,Y = map(int,input().split())
def otoshidamaBomb():
    global N, Y
    for i in range(N + 1)[::-1]:
        
        intX = i * 10000
        
        if intX > Y:
            continue

        
        for j in range(N - i + 1)[::-1]:
            
            intY = j * 5000
            
            intZ = (N - i - j) * 1000
            
            if intX + intY + intZ == Y:
                return i, j, N - i - j

    
    return -1, -1, -1

x,y,z = otoshidamaBomb()
print("{0} {1} {2}".format(x, y, z))

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

s1, s2, s3 = 10, 5, 1
ok_flg = False

if Y % 1000 != 0 :
    print("-1 -1 -1")    
else :
    y_small = int(Y / 1000)
    for i in range(N + 1) :
        if y_small - i * s1 <= (N - i) * s2 :
            for j in range(N - i + 1) :
                if i + j <= N and i*s1 + j*s2 + (N - i - j)*s3 == y_small :
                    print(i, j, N - i - j)
                    ok_flg = True
                    break
                if ok_flg == True :
                    break
            if ok_flg == True :
                break
    if ok_flg == False :
        print("-1 -1 -1")

Solution (Python):
n, y = tuple(map(int , input().split(" ")))
cnt = 0

for idx in range(n + 1):
    for jdx in range(n + 1 - idx):
        kdx = n - idx - jdx
        if (kdx * 10000 + jdx * 5000 + idx * 1000 == y):
            print(kdx, jdx, idx)
            exit(0)
print('-1 -1 -1')

Solution (Python):
def solve(N,Y):
    Y //= 1000
    for i in range(Y//10+1):

        if (Y - N -9*i)%4==0:
            b = (Y-N-9*i)//4
            if N-i-b >= 0 and b >=0:
                return [i,b,N-i-b]
    
    return [-1,-1,-1]


N,Y=[int(i) for i in input().split()]

lis = solve(N,Y)

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

Solution (Python):
def calculate_money():
    input_list = input().split()
    N = int(input_list[0])
    Y = int(input_list[1])

    for x_num in range(0, N + 1):
        for y_num in range(0, N + 1 - x_num):
            z_num = N - x_num - y_num
            if 10000 * x_num + 5000 * y_num + 1000 * z_num == Y:
                print(x_num, " ", y_num, " ", z_num)
                return
    print("-1 -1 -1")


if __name__ == '__main__':
    calculate_money()

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




for x in range(2001):
    y = (Y - 1000 * N - 9000 * x) // 4000
    z = N - x - y
    if y>=0 and z>=0 and (Y-1000*N- 9000*x)%4000==0:
        z = N-x-y
        print(x,y,z)
        exit()

print(-1,-1,-1)

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

satu10000 = -1
satu5000 = -1
satu1000 = -1

i = 0
flag = 0
while(i <= n):
  j = 0
  while(i+j <= n):
    k = n - i - j
    if 10000*i + 5000*j + 1000*k == y:
      satu10000 = i
      satu5000 = j
      satu1000 = k
      flag = 1
      break
    j += 1
  if flag == 1:
    break
  i += 1

print(str(satu10000) + ' ' + str(satu5000) + ' ' + str(satu1000))

Solution (Python):
N, Y = map(int, input().split())
a = 0
k = 0
while a <= N:
  j = 0
  while j <= N-a:
    if 10000*a+5000*j+1000*(N-a-j) == Y:
      s = str(a)+' '+str(j)+' '+str(N-a-j)
      print(s)
      k += 1
      break
    elif k == 0:
      j += 1
    else:
      break
  if k == 0:
    a += 1
  else:
    break
if k == 0:
  print('-1 -1 -1')
else:
  pass

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

r = m-n




for c_9 in range(r//9 +1):
    for c_4 in range(r//4 +1):
        if c_9*9 + c_4*4 == r:
            if m-c_9*10-c_4*5>=0:
                print('{} {} {}'.format(c_9, c_4, m-c_9*10-c_4*5))
                sys.exit()
            
print('{0} {0} {0}'.format(-1))

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

ans = "-1 -1 -1"
for man in range(Y // 10000 + 1):
    for gosen in range(Y // 5000 + 1):
        hoge = Y - man * 10000 - gosen * 5000
        if hoge >= 0 and hoge % 1000 == 0:
            sen = hoge // 1000
            if man + gosen + sen == N:
                ans = " ".join(map(str, [man, gosen, sen]))
                break

print(ans)

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

print("-1 -1 -1")

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

Solution (Python):
import sys

if __name__ == '__main__':
    N, Y = list(map(int, sys.stdin.readline().split()))

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

Solution (Python):
import sys

n, y = [int(m) for m in input().split(" ")]

for i in range(n+1):
	bill_10000 = 10000 * i
	for j in range(n-i+1):
		bill_5000 = 5000 * j
		k = n-i-j
		bill_1000 = 1000 * k
		
		sum_price = bill_10000 + bill_5000 + bill_1000
		
		
		if y == sum_price:
			print(i, j, k)
			sys.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+1-i):
        x = i
        y = j
        z = N - i - j
        if (10000*x + 5000*y + 1000*z) == Y:
            print("{} {} {}".format(x,y,z))
            sys.exit()

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

Solution (Python):
N,Y = (int(i) for i in input().split())

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

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

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

Solution (Python):
N,Y = map(int,input().split())
Y //= 1000
t = Y-N
for i in range(t+1):
    if i % 4 == 0 and (t-i)%9 == 0:
        a,b = (t-i)//9,i//4
        c = N-a-b
        if c >= 0:
            print(a,b,c)
            exit()
print(-1,-1,-1)

Solution (Python):
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
            elif i+j+k != N:
                continue
            if i*10000 + j*5000 + k*1000 == Y:
                print(i,j,k)
                return 0
    print(-1, -1, -1)

if __name__ == '__main__':
    main()

Solution (Python):
a,b=[int(x) for x in str(input()).split()]
b/=1000
e=int(b//10)
x=-1
y=-1
z=-1

for i in range(0,e+1):
  q=(b-a-9*i)/4

  if q==int(q):
    if q>=0:
      r=(10*a-b-5*q)/9

      if r==int(r):
        if r>=0:
          if (i+int(q+r))==a:
            if int(10*i+5*q+r)==b:

              x,y,z=i,int(q),int(r)
              break

print(x,y,z)

Solution (Python):
a,b=[int(x) for x in str(input()).split()]
b/=1000
e=int(b//10)
x=-1
y=-1
z=-1

for i in range(0,e+1):
  q=(b-a-9*i)/4

  if q==int(q):
    if q>=0:
      r=(10*a-b-5*q)/9

      if r==int(r):
        if r>=0:
          if (i+int(q+r))==a:
            if int(10*i+5*q+r)==b:

              x,y,z=i,int(q),int(r)
              break

print(x,y,z)

Solution (Python):

"""
Created on Tue Jun 19 03:01:30 2018

@author: ashida
"""

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

flag = -1

for n_10k in range(N+1):
    for n_5k in range(N+1-n_10k):
        n_1k = N-n_10k-n_5k
        if 10000*n_10k + 5000*n_5k + 1000*n_1k == Y:
            flag = 1
            ans = [n_10k, n_5k, n_1k]
                
if flag == -1:
    ans = [-1, -1, -1]

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

Solution (Python):
INPUT = input()

N = int(INPUT.split( )[0])
Y = int(INPUT.split( )[1]) / 1000

Y_mod5 = int(Y % 5)

for hideyo in range(Y_mod5, N + 1, 5):
    if (Y - hideyo > (N - hideyo) * 10) or (Y - hideyo < (N - hideyo) * 5):
        continue
    else:
        print("{} {} {}".format(int((Y - 5 * N + 4 * hideyo) / 5), int((10 * N - Y - 9 * hideyo) / 5), hideyo))
        break
        
if (Y - hideyo > (N - hideyo) * 10) or (Y - hideyo < (N - hideyo) * 5):
    print("-1 -1 -1")

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

all1000s = y // 1000
x = all1000s - n

for a in range(0, x+1, 4):
    nines = (x - a) // 9
    fours = a // 4
    ones = n - nines - fours
    if (x - a) % 9 == 0 and all(x >= 0 for x in (nines, fours, ones)):
        print("{} {} {}".format(nines, fours, ones))
        break
else:
    print("-1 -1 -1")

Solution (Python):
a = '2000 20000000'
a = input()
d = a.split()
n = int(d[0])
y = int(d[1])

a = -1
b = -1
c = -1
for k in range(0,n+1):
    for j in range(0,n+1):
        i = n - k - j
        if(i<0):
            break
        sum_ = 10000 * i + 5000 * j + 1000 * k
        if(sum_<y):
            break
        if(sum_==y):
            a = i
            b = j
            c = k
            break

print(("%d %d %d") %(a,b,c))

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

Solution (Python):
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	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 0 <= (n - i - j):
				print(" ".join([str(i), str(j), str(n - i - j)]))
				exit()
	print("-1 -1 -1")

if __name__ == '__main__':
	main()

Solution (Python):
N,Y = map(int, input().split())
A,B,C = -1,-1,-1
for a in range(N+1):
    for b in range(N-a+1):
        c = N-a-b
        T = 10000*a + 5000*b + 1000*c
        if T == Y:
            A = a
            B = b
            C = c
print("{} {} {}".format(A,B,C))

Solution (Python):
import sys

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

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

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

print(a, b, c)

Solution (Python):
import sys
n,yen = map(int,input().split())

for i in range(n + 1):
    for j in range(n + 1):
        k = n - (i + j)
        if 10000 * i + 5000 * j + 1000 * k == yen and k >= 0:
            print("{} {} {}".format(i,j,k))
            sys.exit()
print("-1 -1 -1")

Solution (Python):
import sys
n,yen = map(int,input().split())

for i in range(n + 1):
    for j in range(n + 1):
        k = n - (i + j)
        if 10000 * i + 5000 * j + 1000 * k == yen:
            if k < 0:
                continue
            print("{} {} {}".format(i,j,k))
            sys.exit()
print("-1 -1 -1")

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

n1000 = Y % 5000 // 1000
n5000 = N - n1000
n10000 = 0

while True:
    tot = n10000 * 10000 + n5000 * 5000 + n1000 * 1000
    if tot == Y:
        print(n10000, n5000, n1000)
        break

    if n5000 <= 0:
        print(-1, -1, -1)
        break

    if tot > Y:
        n5000 -= 5
        n1000 += 5
    else:
        n5000 -= 1
        n10000 += 1

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

try:
 for i in range(N+1):
   for j in range(N-i+1):
     sum=i*10000+j*5000+(N-i-j)*1000
     if sum==Y:
       raise Exception
except Exception:
  print(i,j,N-i-j)
else:
  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):
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	n, y = map(int, re.split(" +", input()))
	flag = False
	for i in range(0, n + 1):
		if flag is True:
			break
		for j in range(0, n + 1):
			if y == 10000 * i + 5000 * j + 1000 * (n - i - j) and n - i - j >= 0:
				print("{} {} {}".format(i, j, n - i - j))
				flag = True

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

if __name__ == '__main__':
	main()

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

ans = '-1 -1 -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:
            ans = '{} {} {}'.format(x, y, z)
            break
print(ans)

Solution (Python):
N, Y = (int(i) for i in input().split())




a = 0
b = 0
c = 0
sum = 0
list = []

for a in range(N+1):
    b = 0
    for b in range(N - a + 1):
        c = N - a - b
        sum = 10000*a + 5000*b + 1000*c
        if(sum == Y):
            list = list + [a, b, c]

if(list == []):
    print(-1, -1, -1)
else:
    print(list[0], list[1], list[2])

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
k = min((Y - N) // 4, Y // 5)
if 9 * k >= 2 * (Y - N):
    x = (Y - N) - 4 * k
    y = 9 * k - 2 * (Y - N)
    z = Y - 5 * k
    print(x, y, z)
else:
    print(-1, -1, -1)

Solution (Python):
N,Y = list(map(int, input().split()))
answer = "-1 -1 -1"
for a in range(0,N+1):
    for b in range(0,N-a+1):
        c = N-a-b
        sum = a*10000 + b*5000 + c*1000
        if Y == sum:
            answer = "%s %s %s"%(a,b,c)
print(answer)

Solution (Python):
input = [int(i) for i in input().split()]
 
N = input[0]
Y = input[1]
 
ans = False
total = 0
 
for i in range(0,N+1):
    for j in range(0,(N+1-i)):
        total = 10000 * i + 5000 * j + (N-i-j) * 1000
        if Y == total:
            print(i,j,(N-i-j))
            ans = True
            break
    else:
        continue
    break
if ans == False:
 
    print(-1,-1,-1)

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


def judge():
    for i in range(N + 1):
        for j in range(N + 1 - i):
            if i * 10000 + j * 5000 + (N - i - j) * 1000 == Y:
                return "{} {} {}".format(i, j, N - i - j)
    return "-1 -1 -1"


print(judge())

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

Solution (Python):
def getinputdata():

    
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()


n = int(arr_data[0][0])

y = int(arr_data[0][1])

chkflg = False

for i in range(0, n+1):

    for j in range(0, n+1):

        if (n-i-j) >= 0 and 10000 * i + 5000 * j + 1000 * (n-i-j) == y:

            print(i,j,(n-i-j))
            chkflg = True
            break
            
    if chkflg:
        
        break

if chkflg == False:
    
    print(-1, -1, -1)

Solution (Python):
input_list = list(input().split())
bill_num = int(input_list[0])
total_price = int(input_list[1])

yen_10000 = 10000
yen_5000 = 5000
yen_1000 = 1000
bill_num_list = []

for i in range(bill_num + 1):
    for j in range(bill_num - i + 1):
        k = 0
        k = bill_num - i - j
        total = i * yen_10000 + j * yen_5000 + k * yen_1000
        if  (i + j + k == bill_num) and (k >= 0) and (total == total_price):
            bill_num_list = [i, j, k]
            bill_num_list_str = list(map(str, bill_num_list))
            break

if bill_num_list == []:
    print('-1 -1 -1')
else:
    print(' '.join(bill_num_list_str))