Starship Hakodate-maru

No attempts yetTime limit1sMemory limit128 MB

Problem

The surveyor starship Hakodate-maru is famous for her two fuel containers of unbounded capacity. Both hold the same kind of atomic fuel ball.

There is one inconvenience. Fuel container #1 is cubic and fuel container #2 is a regular tetrahedron. Each container has to be either completely empty or filled to match its shape. Otherwise the fuel balls turn extremely unstable and may explode inside the container. The number of fuel balls in container #1 therefore has to be a cubic number, n3n^3 for some n=0,1,2,3,n = 0, 1, 2, 3, \dots, and the number in container #2 has to be a tetrahedral number, n(n+1)(n+2)/6n(n+1)(n+2)/6 for some n=0,1,2,3,n = 0, 1, 2, 3, \dots.

Hakodate-maru is docked at the star base Goryokaku, preparing for her next mission, which is to chart stars and interstellar matter in precise detail. Both fuel containers are empty. Commander Parus of Goryokaku will soon tell Captain Future of Hakodate-maru how many fuel balls Goryokaku can supply. Captain Future has to answer with the number she requests, quickly, before her ship leaves Goryokaku. She and her officers want as many fuel balls as possible.

Suppose Commander Parus offers 151200 fuel balls. With only container #1 available, at most 148877 fuel balls fit, since 53×53×53=148877<151200<54×54×5453 \times 53 \times 53 = 148877 < 151200 < 54 \times 54 \times 54. With only container #2 available, at most 147440 fit, since 95×96×97/6=147440<151200<96×97×98/695 \times 96 \times 97 / 6 = 147440 < 151200 < 96 \times 97 \times 98 / 6. Using both containers, all 151200 fit, since 151200=39×39×39+81×82×83/6151200 = 39 \times 39 \times 39 + 81 \times 82 \times 83 / 6. Captain Future's answer in this case is 151200.

Commander Parus cannot offer more than 151200, because that is what the fuel storage of Goryokaku holds. Captain Future and her officers know this well.

You are a fuel engineer assigned to Hakodate-maru. Your job today is to compute the number of fuel balls Captain Future should request.

Input

The input is a sequence of at most 1024 positive integers, one per line. A zero follows the sequence to mark the end of the data, and that zero is not part of the input to process. None of the input integers is greater than 151200.

Output

Print one integer per line, one line for each input value. Each printed integer is the greatest integer that is the sum of a nonnegative cubic number and a nonnegative tetrahedral number and that does not exceed the corresponding input value. Print no other characters.