#include "bits/stdc++.h"
/*
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
*/
#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("Yes\n")
#define no printf("No\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using ull=unsigned long long;
using vi=vector<int>;
using pint=pair<int,int>;

const int INF=1LL<<55;

int tf;
int ans=0;

void solve(){
    ans = 0;
    int t;
    int i=1;
    while(true){
        t=pow(i,3);
        if(t>tf) break;
        ans=max(ans,t);
        i++;
    }
    int maxA=i;
    i=1;
    while(true){
        t=i*(i+1)*(i+2)/6;
        if(t>tf) break;
        ans=max(ans,t);
        i++;
    }
    int maxB=i;
    rep(i,maxA){
        rep(j,maxB){
            t=pow(i,3)+j*(j+1)*(j+2)/6;
            if(t>tf) break;
            ans=max(ans,t);
        }
    }
    cout<<ans<<endl;
    return;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int i=1;
    int t;
    
    while(cin>>tf,tf){
        solve();
    }

    return 0;
}
