def square(from, max, parent = 0, out = '')
  from.downto(1) do |i|
    if i + parent > max
      next
    elsif i + parent == max
      out << "#{i}\n"
    else
      out << "#{i} "
      square(i, max, parent + i, out)
    end
  end
  out
end

# o = <<EOS
# 5
# 5
# 0
# EOS

# File.open('input.txt', 'w') do |f|
#   f.write(o)
# end

out = ''

File.open('input.txt') do |f|
  while a = f.gets.to_i
    break if a == 0
    out << square(a, a)
  end
end

File.open('output.txt', 'w') do |f|
  f.write(out)
end