n = gets.not_nil!.to_i k = ((Math.sqrt(1 + 8 * n) - 1) / 2).to_i tris = [] of Int32 1.upto(k) do |i| tris << i * (i + 1) / 2 end if tris.includes? n p 1 else ok = false Array(Int32).product(tris, tris).each do |elm| a, b = elm ok = ok || (a + b) == n end p ok ? 2 : 3 end