main :: IO ()
main = do
  [n,y] <- map (read :: String -> Int) . words <$> getLine
  print $ ans n y

ans :: Int -> Int -> (Int,Int,Int)
ans n y = foldl func (-1,-1,-1) (allComb n) where
  func acc k@(a,b,c)
    | acc /= (-1,-1,-1) = acc
    | y == a*10000+b*5000+c*1000 = k
    | otherwise = acc

allComb :: Int -> [(Int,Int,Int)]
allComb n = concat $ map func [0..n] where
  func k = map (\(a,b) -> (k,a,b)) $ allPair (n-k)
  allPair m = zip [0..m] [m,m-1..0]