/* ACM ICPC Asia Regional Contest, Hakodate 2001 Problem A: Starship Hakodate-maru by Naoyuki Tamura (tamura@kobe-u.ac.jp) */ import java.io.*; import java.util.*; public class A { static boolean dbg = false; static String infile = "ssh.txt"; static DataInputStream in = new DataInputStream(System.in); static final int N1 = 53; static final int N2 = 95; static int[] cubic = new int[N1+1]; static int[] tetrahedral = new int[N2+1]; static int sum; static void debug(String msg) { if (dbg) System.err.print(msg); } static boolean read() throws Exception { String line = null; debug("# Enter\n"); line = in.readLine(); sum = Integer.parseInt(line); if (sum == 0) return false; return true; } static void init() { for (int n1 = 0; n1 <= N1; n1++) cubic[n1] = n1*n1*n1; for (int n2 = 0; n2 <= N2; n2++) tetrahedral[n2] = n2*(n2+1)*(n2+2)/6; } static int solve() { int max = 0; for (int n1 = 0; n1 <= N1; n1++) { if (cubic[n1] > sum) break; for (int n2 = 0; n2 <= N2; n2++) { int s = cubic[n1] + tetrahedral[n2]; if (s > sum) break; max = Math.max(max, s); } } return max; } public static void main(String args[]) { try { if (args.length > 0) dbg = true; else in = new DataInputStream(new FileInputStream(infile)); init(); while (read()) { int max = solve(); System.out.println(max); } } catch (Exception e) { e.printStackTrace(); } } }