#include <stdio.h>

int m, n;
int sq, ttry;
int max;

void kan()
{
    max = 0;
    for (n = 0; n * n * n <= m; n++)
    {
        sq = n * n * n;
        for (int i = 0; sq + i * (i - 1) * (i - 2) / 6 <= m; i++)
        {
            ttry = i * (i - 1) * (i - 2) / 6;
            if (max < sq + ttry)
            {
                max = sq + ttry;
            }
        }
    }
    printf("%d\n", max);
}

int main()
{
    for (;;)
    {
        scanf("%d", &m);
        if (m == 0)
            return 0;
        kan();
    }
}
