#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i=(a); i<(n); ++i)
#define rrep(i,a,n) for(ll i=(a); i>(n); --i)
#define erep(i,a,n) for(ll i=(a); i<=(n); ++i)
#define rerep(i,a,n) for(ll i=(a); i>=(n); --i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int) x.size())
#define print(X) cout << (X) << endl
#define _ << " " <<
static const int INF = 1e+9+7;
ll n,m,l;
str s,t;
int A[100000];

int calc1(int n){
    int i;
    for (i = 0; i*i*i<=n; ++i){}
    --i;
    return (i*i*i);
}

int calc2(int n){
    int i;
    for(i=0; i*(i+1)*(i+2)/6<=n; ++i){}
    --i;
    return (i*(i+1)*(i+2)/6);
}

int calc3(int n){
    int res = 0;
    for(int i=0; i*i*i<=n; ++i){
        res = max(res, i*i*i+calc2(n-i*i*i));
    }
    return res;
}


int main(){
    vi vc;
    rep(i,0,1024){
        int x;
        cin >> x;
        if (x == 0) break;
        vc.pb(x);
    }

    rep(i,0,sz(vc)){
        int large = max(calc1(vc[i]),calc2(vc[i]));
        large = max(large, calc3(vc[i]));
        print(large);
    }



  return 0;
}




