def measure(object, weight, result = [])
  return result.join(" ") if weight.zero?
  result.unshift(weight) if (object / weight).nonzero?
  measure(object % weight, weight / 2, result)
end

$<.readlines.map(&:to_i).each {|ob| puts measure(ob, 512)}
