arr1, arr2 = [], []
x = 0
while true
    y = x ** 3
    arr1 << y if y <= 151200
    break if y > 151200
    x += 1
end
x = 0
while true
    y = x * (x + 1) * (x + 2) / 6
    arr2 << y if y <= 151200
    break if y > 151200
    x += 1
end

while true
    x = gets.to_i
    break if x == 0
    max = 0
    arr1.each{|a|
        arr2.each{|b|
            z = a + b
            break if z > x
            max = z if max < z
        }
    }
    puts max
end
