#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int INF = (1 << 21);

int a(int x){
    return x * x * x;
}

int b(int x){
    return (x * (x - 1) * (x - 2)) / 6;
}

int c(int n, int x){
    return n - x;
}

int main(){
    int n;
    while(cin >>n){
        if(n == 0) break;
        int ans = INF, tmp;
        for(int i = 1; i < 100; i++){
            tmp = c(n, a(i));
            if(tmp < 0) break;
            else ans = min(ans, tmp);
            for(int j = 1; j < 100; j++){
                tmp = c(n, a(i) + b(j));
                if(tmp < 0) break;
                else ans = min(ans, tmp);
            }

        }
        for(int i = 1; i < 100; i++){
            tmp = c(n, b(i));
            if(tmp < 0) break;
            else ans = min(ans, tmp);
        }
        cout <<n - ans <<endl;
    }
    return 0;
}