Go: package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	var nums []int
	for i := 1; i < 2*100+1; i++ {
		nums = append(nums, i*(i+1)*(i+2)/6)
	}
	var ins []int
	N := 0
	for true {
		n := sc.nextInt()
		if n == 0 {
			break
		}
		ins = append(ins, n)
		N = max(N, n)
	}
	dp := make([]int, N+1)
	dp2 := make([]int, N+1)
	for i := 1; i < N+1; i++ {
		dp[i] = INF
		dp2[i] = INF
	}
	for i := 0; i < len(nums); i++ {
		n := nums[i]
		if n > N {
			break
		}
		for j := 0; j < N+1; j++ {
			if j >= n {
				dp[j] = min(dp[j], dp[j-n]+1)
				if n%2 != 0 {
					dp2[j] = min(dp2[j], dp2[j-n]+1)
				}
			}
		}
	}
	for i := 0; i < len(ins); i++ {
		fmt.Fprintln(wtr, dp[ins[i]], dp2[ins[i]])
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define print(a) cout<<a<<endl;
int aaa[200] = {}, bbb[200] = {}, counta=1,countb=1, ansa, ansb, xxx[1100000] = {}, yyy[1100000] = {};

int foo(int n, int x){//cout<<n<<" "<<x<<" "<<xxx[x]<<endl;;
	int mi = 1000000;
	if(xxx[n]) return xxx[n]+x;
	if(x > 5) return mi;
	for(int i = counta-1; i >= 1; i--){
		if(aaa[i] < n){
			mi = min(foo(n-aaa[i],x+1), mi);
		//	if(mi - n == 1)break;
		} //else if(aaa[i] < n/2) break;
	}
	
	xxx[n] = mi;
	return mi;
}
int boo(int n, int x){//cout<<n<<" "<<x<<" "<<yyy[n]<<endl;cin>>ansb;
	int mi = 1000000;
	if(yyy[n]) return yyy[n]+x;
	for(int i = countb-1; i >= 1; i--){
	//	cout<<bbb[i]<<" "<<n<<endl;
		if(bbb[i] < n){
			mi = min(boo(n-bbb[i],x+1), mi);
			//if(mi - n == 1)break;
		}// else if(bbb[i] < n/2) break;
	}
	//cout<<"aaaa "<<n<<" "<<x<<" "<<mi<<endl;
	yyy[n] = mi;
	return mi;
}

int main(){
	int i, n, abc;
	for(i = 1; abc <= 1000000; i++){
		abc = (i*(i+1)*(i+2))/6;
		xxx[abc] = 1;
		if(abc%2 == 1){
			yyy[abc] = 1;
			bbb[countb++] = abc;
		}
		aaa[counta++] = abc;
	//	cout<<counta<<" "<<i<<" "<<abc<<endl;;
	}
	print(1);
	for(i = 1; i <= 100000; i++){
		xxx[i] = foo(i, 0);
		yyy[i] = boo(i, 0);
	}
	print('a');
	while(1){
		cin>>n;
		if(n == 0) break;
		cout<<foo(n,0)<<" "<<boo(n,0)<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

vi all, odd;
vi dpall, dpodd;

void init() {
  int n = 1000000;
  int sz = SZ(all);
  dpall.resize(1000001, INF);
  dpall[0] = 0;
  REP(i, sz) {
    if(all[i] > n) break;
    REP(j, n+1) {
      if(j + all[i] <= n) {
        chmin(dpall[j+all[i]], dpall[j] + 1);
      }
    }
  }

  sz = SZ(odd);
  dpodd.resize(1000001, INF);
  dpodd[0] = 0;
  REP(i, sz) {
    if(odd[i] > n) break;
    REP(j, n+1) {
      if(j + odd[i] <= n) {
        chmin(dpodd[j+odd[i]], dpodd[j] + 1);
      }
    }
  }

}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  REP(i, 1000) {
    int tmp = i * (i + 1) * (i + 2) / 6;
    if(tmp > 1000000) break;
    all.push_back(tmp);
    if(tmp&1) odd.push_back(tmp);
  }

  init();

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    cout << dpall[n] << " " << dpodd[n] << endl;
  }

}

C++: #include <bits/stdc++.h>
using namespace std;

//#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
//const int INF = 1107110711071107;

int dp[200][1000001];
int dp_odd[40][1000001];
int four[210];
int x;

signed main() {
  Rep(i, 210) four[i] = i * (i+1) * (i+2) / 6;
  
  memset(dp, 1e6+1, sizeof(dp));
  Rep(i, 1000001) dp[1][i] = i;
  Rrep(i, 2, 200) {
    Rep(j, 1000001) {
      dp[i][j] = min(dp[i][j], dp[i-1][j]);
      if ( j+four[i] <= 1000000 ) {
	dp[i][j+four[i]] = min(dp[i][j+four[i]], dp[i][j]+1);
      }
    }
  }

  memset(dp_odd, 1e6+1, sizeof(dp_odd));
  Rep(i, 1000001) dp_odd[1][i] = i;
  Rrep(i, 2, 40) {
    Rep(j, 1000001) {
      dp_odd[i][j] = min(dp_odd[i][j], dp_odd[i-1][j]);
      if ( j+four[(i-1)*4+1] <= 1000000 ) {
	dp_odd[i][j+four[(i-1)*4+1]] = min(dp_odd[i][j+four[(i-1)*4+1]], dp_odd[i][j]+1);
      }
    }
  }
 
  while ( cin >> x, x ) {
    cout << dp[199][x] << " " << dp_odd[39][x] << endl;
  }
  return 0;
}