#include <stdio.h>

int main()
{
	int maxCap = 0, targetCap = 0, cubicCount = 0, cubicSize = 0, tetrahedralCount = 0, tetrahedralSize = 0, tmpCap = 0;
	for (; scanf("%d", &targetCap) && targetCap != 0; printf("%d\n", maxCap))
	{
		maxCap = 0, cubicCount = 0, cubicSize = 0, tetrahedralCount = 0, tetrahedralSize = 0, tmpCap = 0;
		for (;
			 cubicCount * cubicCount * cubicCount <= targetCap;
			 cubicCount++)
			maxCap = cubicCount * cubicCount * cubicCount;
		cubicCount--;
		if (maxCap == targetCap)
			continue;
		for (; cubicCount >= 0; cubicCount--)
		{
			for (cubicSize = cubicCount * cubicCount * cubicCount;
				 cubicSize + tetrahedralCount * (tetrahedralCount + 1) * (tetrahedralCount + 2) / 6 <= targetCap;
				 tetrahedralCount++)
				tetrahedralSize = tetrahedralCount * (tetrahedralCount + 1) * (tetrahedralCount + 2) / 6;
			tmpCap = cubicSize + tetrahedralSize;
			if (tmpCap > maxCap)
				maxCap = tmpCap;
			if (maxCap == targetCap)
				break;
		}
	}
	return 0;
}
