Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + (i - 1) + i cubes.
Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
Input
The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.
Output
Print the maximum possible height of the pyramid in the single line.
Examples
Input
1
Output
1
Input
25
Output
4
Note
Illustration to the second sample:
问题链接:https://vjudge.net/contest/276590#problem/B
问题分析:第一行有1个正方形,第二行要放1+2=3个,第三行要1+2+3=6个······以此类推,第i行要
1+2+3+4+···+(i-1)+1个,先要求输入总共有n个正方形,输出可以排成几行。
解决方案:定义一个数组a[100]用于存放每行所需的方格数,循环计算从数组第一个数开始算总和,算到当总和大于输入的n(有n个方块)时停止,输出此时求和求的数组下标,即为所需行数。注意如果求和总和sum>n,为i行;sum==n,则为i+1行。
#include <iostream>
using namespace std;
int main()
{
int i, n,sum=0,k=2,s=99;
int a[100];
cin >> n;
for(i=0;i<s;i++)
{
a[0] = 1;
a[i + 1] = a[i] +k;
k++;
}
for(i=0;i<s;i++)
{
sum = sum + a[i];
if (sum < n)continue;
if (sum == n)cout << i+1;
if (sum > n)cout << i ;break;
}
}