n = gets.to_i 1.upto(n / 3) do |a| 1.upto((n - a) / 2) do |b| c = n - a - b if a <= b && b <= c puts "#{a} #{b} #{c}" end end end