Time limit
2s
Memory limit
128 MB
Captain Dasom keeps many cannonballs on a pirate ship for attacking enemies. Because Dasom has a strong sense of aesthetics, the cannonballs must be stacked as tetrahedrons.
A pile of size N is built by placing an equilateral triangular layer with side length N on the bottom, then a layer with side length N-1 on top of it, and so on until the top layer has side length 1.
A pile of size 3 looks like this.
X
X X X
X X XX X XThe numbers of cannonballs in the triangular layers are 1, 3, 6, 10, ... . Therefore, a completed tetrahedron contains 1, 4, 10, 20, ... cannonballs.
There are N cannonballs on the ship. Dasom asks Youngsik to use them to build tetrahedral piles. Youngsik wants to build as few tetrahedrons as possible. Find the minimum number of tetrahedrons that can be made while using all N cannonballs.
The first line contains a natural number N. N is at most 300,000.
Print the minimum number of tetrahedrons that can be made while using all N cannonballs.
X
X X X
X X XX X X