### constant

MAX_F = 151200

### main

cubes = []
for k in (0...MAX_F)
  c = k * k * k
  break if c > MAX_F
  cubes << c
end
#p cubes

tetras = []
for k in (0...MAX_F)
  t = k * (k + 1) * (k + 2) / 6
  break if t > MAX_F
  tetras << t
end
#p tetras

loop do
  n = gets.to_i
  break if n == 0

  max_sum = 0
  i = tetras.length - 1

  for c in cubes
    while i >= 0 && c + tetras[i] > n
      i -= 1
    end
    break if i < 0

    sum = c + tetras[i]
    if max_sum < sum
      #p [n, c, tetras[i]]
      max_sum = sum 
    end
  end

  puts max_sum
end