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



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

    a, b, c = -1, -1, -1
    loop_max = int(y / 10000)
    for ia in range(loop_max + 1):
        if ia * 10000 > y:
            continue

        second_loop_max = min(int(y - (ia * 10000) / 5000), n - ia)
        for ib in range(second_loop_max + 1):
            ic = n - ia - ib
            total = ia * 10000 + ib * 5000 + ic * 1000
            if total == y and (ia + ib + ic) == n:
                a = ia
                b = ib
                c = ic
                break

    print(" ".join(map(str, (a, b, c))))


if __name__ == '__main__':
    main()

Solution (Python):



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

    a, b, c = -1, -1, -1
    loop_max = int(y / 10000)
    for ia in range(loop_max + 1):
        if ia * 10000 > y:
            continue

        for ib in range(n - ia + 1):
            ic = n - ia - ib
            total = ia * 10000 + ib * 5000 + ic * 1000
            if total == y and (ia + ib + ic) == n:
                a = ia
                b = ib
                c = ic
                break

    print(" ".join(map(str, (a, b, c))))


if __name__ == '__main__':
    main()

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

Solution (Python):
n,y = [int(i)  for i in input().split()]
for i in range(2001):
  for j in range(0,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):



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

    a, b, c = -1, -1, -1
    for ia in range(n + 1):
        for ib in range(n - ia + 1):
            ic = n - ia - ib
            total = ia * 10000 + ib * 5000 + ic * 1000
            if total == y and (ia + ib + ic) == n:
                a = ia
                b = ib
                c = ic
                break

    print(" ".join(map(str, (a, b, c))))


if __name__ == '__main__':
    main()

Solution (Python):
N, Y = [int(n) for n in input().split(' ')]

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

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:
            x = a
            y = b
            z = c

print(x, y, z)

Solution (Python):
import sys

from collections import Counter

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

    s10, s5, s1 = -1, -1, -1
    for i_s10 in range((y // 10) + 1):
        for i_s5 in range(((y - i_s10 * 10) // 5) + 1):
            if (n - i_s10 - i_s5) == y - i_s10 * 10 - i_s5 * 5:
                s10, s5, s1 = i_s10, i_s5, n - i_s10 - i_s5
    print(s10, s5, s1)


if __name__ == '__main__':
    main()

Solution (Python):










import math
import numpy as np
import statistics
import string
import sys
from array import array
from collections import deque
from functools import wraps
import time

def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

N,Y = splitintinput()

time_sta = time.perf_counter()

for i in range(N+1):
    if 10000 * i > Y:
        break
    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')


time_end = time.perf_counter()

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

for i in range(N+1):
    for j in range(N+1):
        num = Y - i * 10000 - j * 5000
        
        if num % 1000 == 0 and N == i + j + num//1000 and num >= 0:
            print(i,j,num//1000)
            quit()
            
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 i in range(N+1):
    for j in range(N-i+1):
        if Y == 10000 * i + 5000 * j + 1000 * (N - i - j):
            ans = [i, j, (N-i-j)]
print(*ans)

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

Solution (Python):
bill_count, total_money = map(int, input().split())

def calc(total_money, bill_count):
  x_high_bound = int(total_money / 10000) if int(total_money / 10000) < bill_count else bill_count
  for x in range(x_high_bound + 1):
    hoge = bill_count - x
    if 10000 * x + 5000 * hoge < total_money: continue
    if 10000 * x + 1000 * hoge > total_money: continue
    for y in range(hoge + 1):
      for z in [bill_count - x - y]:
        if 10000 * x + 5000 * y + 1000 * z == total_money:
          return "{} {} {}".format(x, y, z)
  return '-1 -1 -1'

print(calc(total_money, bill_count))

Solution (Python):
li = input().split()
count = int(li[0])
price = int(li[1]) / 1000
errorText = '-1 -1 -1'
ans = True
flag = False
for a in range(count+1):
    for b in range(count+1 - a):
        c = count - a-b
        fee = a*10 + b*5 + c*1
        if fee == price and a+b+c == count:
            print(str(a) + " " + str(b) + " " + str(c))
            ans = False
            flag = True
            break
    if flag:
        break

if ans is not False:
    print(errorText)

Solution (Python):
def solve():
    n, y = map(int, input().split())
    r = range(n+1)

    ans = "-1 -1 -1"
    for i in r:
        for j in r:
            k = (y-(10000*i+5000*j))//1000
            if k >= 0 and 10000*i+5000*j+1000*k == y and i+j+k == n:
                ans = "{} {} {}".format(i, j, k)
                print(ans)
                return

    print(ans)


if __name__ == "__main__":
    solve()

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 10000*x + 5000*y + 1000*z == Y and (0<= z <= N):
            ans = [x, y, z]
            break
print(*ans)

Solution (Python):
N, Y = map(int, input().split())
A, B, C = 10000, 5000, 1000
yen = mai = 0
for a in range(N+1):
  yen, mai = A * a, a
  for b in range(N+1-mai):
    yen, mai = A * a + B * b, a + b
    for c in range(N-mai, N+1-mai):
      yen, mai = A * a + B * b + C * c, a + b + c
      if mai == N and yen == Y: break
    if mai == N and yen == Y: break
  if mai == N and yen == Y: break
else:
  a = b = c = -1
print('{} {} {}'.format(a, b, c))

Solution (Python):
import sys
list = input().split(" ")
N = int(list[0])
Y = int(list[1])

for yukichi in range(0,N+1):
    for ichiyo in range(0,N - yukichi + 1):
        hideyo = N - yukichi - ichiyo
        if 10000*yukichi + 5000*ichiyo + 1000*hideyo == Y:
            print(yukichi,ichiyo,hideyo)
            sys.exit()
 
print(-1,-1,-1)

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

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

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

for x in range(2001):
    for y in range(2001):
        z = N - x - y
        if 10000*x + 5000*y + 1000*z == Y and z >= 0:
            print(x,y,z)
            f = 1
            loop = 1
            break
    if loop == 1:
        break
if f == 0:
    print('-1','-1','-1')

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

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

if found:
    print('{} {} {}'.format(x, y, N-x-y))
else:
    print('-1 -1 -1')

Solution (Python):
n, y = map(int, input().split())
t = 0
for i in range(n+1):
    if t == 1:
        break
    for j in range(n+1):
        if (i+j) <= n:

            if i * 1000 + j * 5000 + (n - i - j) * 10000 == y:
                print((n - i - j), j, i)
                t = 1
                break


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

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

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

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

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

arr = []

for i in range(N+1):
    for j in range(N+1):
        k = N-i-j
        if i*10000+j*5000+k*1000 == Y and k>=0:
            arr.append([i,j,k])
if len(arr) >0:
    print(arr[0][0],arr[0][1],arr[0][2])
else:
    print(-1,-1,-1)

Solution (Python):
bill_count, total_money = map(int, input().split())

def search_pattern(bill_count, total_money):
  for x in range(bill_count + 1):
    for y in range(bill_count - x + 1):
      z = bill_count - x - y
      t = 10000 * x + 5000 * y + 1000 * z
      if t != total_money:
        continue
      return (x, y, z)
  return (-1, -1, -1)

answer = search_pattern(bill_count, total_money)
print(" ".join(map(str, answer)))

Solution (Python):
bill_count, total_money = map(int, input().split())
patterns = [
  (x, y, bill_count - x - y) 
    for x in range(bill_count + 1) 
      for y in range(bill_count - x + 1) 
    if 10000*x + 5000*y + 1000*(bill_count - x - y) == total_money
]
print(" ".join(map(str, patterns[0])) if len(patterns) > 0 else '-1 -1 -1')

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

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

Solution (Python):
n,y=map(int,input().split())
an=-1,-1,-1
for m in range(n+1):
    for g in range(n+1):
        s=n-m-g
        if m+g >n:
            break
        if m+g+s == n and 10000*m+5000*g+1000*s ==y:
            print(m,g,s)
            exit(0)

print(*an)

Solution (Python):
import sys
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)
            sys.exit(0)

print("-1 -1 -1")

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

Solution (Python):

import sys 
def main():
    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))
            if k <= 0:
                k = 0
            total = (10000*i) + (5000*j) + (1000*k)
            if total == y :
                print(str(i)+' '+str(j)+ ' '+str(k))
                sys.exit()

    print(str(-1)+' '+str(-1)+ ' '+str(-1))
             



if __name__ == '__main__' :
    main()

Solution (Python):
n,y = map(int,input().split())
s=[-1,-1,-1]
if n*10000<y:
    pass
elif n*10000==y:
    s=[n,0,0]
else:
    m=1
    x_0=n*10000
    while m<=n:
        for i in range(m+1):
            x= x_0-9000*(m-i)-5000*i
            if x == y:
                s=[n-m,i,m-i]
                break
        if x==y:
            break
        m=m+1
print(*s)

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



print(-1,-1,-1)

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

break_loop=False
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)
            break_loop=True
            break
    if break_loop:
        break
    else:
        continue
else:
    print(-1,-1,-1)

Solution (Python):
N, Y = tmp = list(map(int,input().split()))
ans = [-1]*3
for i in range(Y // 10000 + 1):
    tmp = Y - 10000 * i
    for j in range(tmp // 5000 + 1):
        if i + j <= N:
            if 10000 * i + 5000 * j + 1000 * (N - i - j) == Y:
                ans = [i, j, N - i - j]
print(ans[0], ans[1], ans[2])

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

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

YH = -1
IH = -1
HN = -1
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:
            YH = a
            IH = b
            HN = c

print(YH, IH, HN)

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):
from itertools import combinations


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

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

print(-1, -1, -1)

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


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

if possible:
    print(*ans, sep=" ")
else:
    print(-1,-1,-1)

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

ans = [str(-1), str(-1), str(-1)]

for v in range(n+1):
    for i in range(n+1):
        m = 10000 * v + 5000 * i + 1000 * (n - v - i)
        if m == y:
            t = n - v - i
            if t < 0:
                break
            ans = [str(v),  str(i), str(t)]
            break
ans = " ".join(ans)

print(ans)

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



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


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

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:
            list = [x,y,z]
            if Y == 10000*list[0]+5000*list[1]+1000*list[2]:
                ans = list
                break
print(ans[0],ans[1],ans[2])

Solution (Python):
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n + 1 - i):
        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]
c = 0
for i in range(n + 1):
    if c == 1:
        break
    for j in range(n + 1 - i):
        yu = i
        hi = j
        no = n - i - j
        if no * 1000 + hi * 5000 + yu * 10000 == y:
            ans = [yu, hi, no]
            c = 1
print(" ".join(map(str, ans)))

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 (10000*i + 5000*j + 1000*(N-i-j)) == Y:
            A,B,C=i,j,(N-i-j)
print(A,B,C)

Solution (Python):
import sys

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

for j in range(N+1):
    for k in range(N+1):
        if N-j-k<0:
            continue
        Total=10**4*(N-j-k)+5000*j+10**3*k
        if Total==Y:
            print("{} {} {}".format(N-j-k,j,k))
            sys.exit()
        
print("-1 -1 -1")

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

for i in range(n+1) :
    for j in range(n+1) :
        if n - (i + j) < 0 :
            continue
        nokori = y - i*10000 - j*5000
        if nokori % 1000 == 0:
            k = int(nokori / 1000)
            if n == i + j + k :
                print(i,j,k)
                sys.exit()
print(-1,-1,-1)

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

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

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

Solution (Python):
N,Y=map(int,input().split())
a=Y//10000
flag=0
for i in range(a+1):
  for j in range(N-i+1):
    if Y==i*10000+j*5000+(N-i-j)*1000:
      if flag==0:
        print(i,j,(N-i-j))
        flag=1
if flag==0:
  print("-1 -1 -1")

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

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

Solution (Python):
def main():
  import sys
  input = sys.stdin.readline
  n,y=map(int,input().split())
  for i in range(0,y//10000+1):
    for j in range(0,n-i+1):
      if 10000*i+5000*j+1000*(n-i-j)==y and n-i-j>=0:
        print(str(i)+' '+str(j)+' '+str(n-i-j))
        exit()
  print('-1 -1 -1')  
if __name__=='__main__':
  main()

Solution (Python):

import sys
n , y = map(int,input().split())
a , b , c = -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 == y:
            a,b,c = i , j , n-i-j
            print("{} {} {}".format(a,b,c))
            sys.exit()
            
print("{} {} {}".format(a,b,c))

Solution (Python):
n,y=map(int,input().split())
F=y//10000
H=y//5000
ansF=-1
ansH=-1
ansN=-1
for i in range(F+1):
    tmp1=y-10000*i


    for j in range(H+1):
        if i+j>n:
            break
        tmp2=tmp1-5000*j


        if tmp2<0:
            break
        if tmp2==(n-i-j)*1000:


            ansF=i
            ansH=j
            ansN=n-i-j
            break
    if ansF!=-1:
        break
print("{} {} {}".format(ansF,ansH,ansN))

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

Solution (Python):
n,s = map(int, input().split())
for x in range(0,n+1):
    for y in range(0, n-x+1):
        z = n-x-y
        if 10000*x + 5000*y + 1000*z == s:
            print('{} {} {}'.format(x, y, z))
            break
    else:
        continue
    break
else:
    print('-1 -1 -1')

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

Solution (Python):
def resolve():
    N, Y = map(int, input().split())
 
    resx, resy, resz = (-1, -1, -1)
    for x in range(N+1):
        for y in range(N+1-x):
            z = N - x - y
            total = 10000*x + 5000*y + 1000*z
 
            if total == Y:
                resx, resy, resz = (x, y, z)
                break
    
    print(resx, resy, resz)
    
resolve()

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

resx, resy, resz = (-1, -1, -1)
for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break

print(resx, resy, resz)

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

resx, resy, resz = (-1, -1, -1)
for x in range(N+1):
    for y in range(N-x+1):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break

print(resx, resy, resz)

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

resx, resy, resz = (-1, -1, -1)
for x in range(N+1):
    for y in range(N-x+1):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break
        else:
            continue

print(resx, resy, resz)

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

resx, resy, resz = (-1, -1, -1)
xmax = min(N, Y//10000)
for x in range(xmax+1):
    for y in range(N-x+1):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break
        else:
            continue

print(resx, resy, resz)

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

resx, resy, resz = (-1, -1, -1)
xmax = min(N, Y//10000)
for x in range(xmax+1):
    for y in range(N-x+1):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break

print(resx, resy, resz)

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

resx, resy, resz = (-1, -1, -1)
maxn = min(N, Y//10000)
for x in range(maxn+1):
    for y in range(N+1-x):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break

print(resx, resy, resz)

Solution (Python):
N,Y = map(int,input().split())
flag = False
ans = ""
for x in range(N + 1):
  if flag:
    break
  for y in range(N + 1):
    if x + y > N or flag:
      break
    if x*10000+y*5000+(N-x-y)*1000 == Y:
      ans = str(x) + " " + str(y) + " " + str(N-x-y)
      flag = True
if flag:
  print(ans)
else:
  print("-1 -1 -1")

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

resx, resy, resz = (-1, -1, -1)
xmax = min(N, Y//10000)
for x in range(xmax+1):
    ymax = (Y - 10000*x)//5000
    for y in range(ymax+1):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break
        else:
            continue

print(resx, resy, resz)

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

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

resx, resy, resz = (-1, -1, -1)
for x in range(Y//10000+1):
    for y in range(N+1-x):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break
        else:
            if total > Y:
                break
            else:
                continue

print(resx, resy, resz)

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

resx, resy, resz = (-1, -1, -1)

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

        if total == Y:
            resx, resy, resz = (x, y, z)
            break

print(resx, resy, resz)

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

resx, resy, resz = (-1, -1, -1)
xn = Y//10000
for x in range(xn+1):
    for y in range(N+1-x):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break

print(resx, resy, resz)

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

    resx, resy, resz = (-1, -1, -1)
    for x in range(N+1):
        for y in range(N+1-x):
            z = N - x - y
            total = 10000*x + 5000*y + 1000*z

            if total == Y:
                resx, resy, resz = (x, y, z)
                break
    
    print(resx, resy, resz)
    
resolve()

Solution (Python):
a, b = map(int, input().split())
count = 0
for i in range(a+1):
  for j in range(a+1-i):
    c = (a-i-j)
    s = (10000*i) + (5000*j) + (1000*c)
    if s == b:
      print(i,j,c)
      count += 1
      break
  else:
    continue
  break
  
if count == 0:
  print(-1,-1,-1)

Solution (Python):
a, b = map(int, input().split())
count = 0
for i in range(a+1):
  for j in range(a+1-i):
    c = (a-i-j)
    s = (10000*i) + (5000*j) + (1000*c)
    if s == b:
      print(i,j,(a-i-j))
      count += 1
      break
  else:
    continue
  break
  
if count == 0:
  print(-1,-1,-1)

Solution (Python):
a, b = map(int, input().split())
count = 0
for i in range(a+1):
  for j in range(a+1-i):
    s = (10000*i) + (5000*j) + (1000*(a-i-j))
    if s == b:
      print(i,j,(a-i-j))
      count += 1
      break
  else:
    continue
  break
  
if count == 0:
  print(-1,-1,-1)

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

Solution (Python):



def main():
    n, Y = map(int, input().split())
    ans = [-1, -1, -1]

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

main()

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

ans = [-1, -1, -1]
find = False
for i in range(n + 1):
  if find:
    break
  for j in range(n + 1):
    if i + j > n:
      break
    k = n - (i + j)
    total = 10000 * i + 5000 * j + 1000 * k
    if total == y:
      ans[0] = i
      ans[1] = j
      ans[2] = k
      find = True
      break

print('{0} {1} {2}'.format(ans[0], ans[1], ans[2]))

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

Solution (Python):


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

    print("-1 -1 -1")

if __name__ == '__main__':
    main()

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

f = False
for i in range(N+1):
    if f:
        break
    for j in range(N+1-i):
        k = N-i-j
        if 10000*i+5000*j+1000*k == Y:
            print('{} {} {}'.format(i, j, k))
            f = True
            break
if not f:
    print('-1 -1 -1')

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

for j in reversed(range(0, n+1)):
  if 10000*j <= m:
    for k in reversed(range(0, n+1)):
      if 10000*j + 5000*k + 1000*(n-(j+k)) == m:
        if n-(j+k) >=0:
          print(j,k,n-(j+k))
          exit(0)

print(-1,-1,-1)

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

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