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>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define itrep(it, a) for(it = (a).begin(); it != (a).end(); it++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

int dp1[2000050];
int dp2[2000050];

void solve(){
    vector<int> va;
    vector<int> vb;
    int i = 1;
    while(i * (i + 1) * (i + 2) / 6 <= 1000000){
        int a = i * (i + 1) * (i + 2) / 6;
        va.push_back(a);
        if(a % 2 == 1) vb.push_back(a);
        i++;
    }
    rep(i,1000005){
        dp1[i] = INF;
        dp2[i] = INF;
    }
    dp1[0] = dp2[0] = 0;

    for(int j = va.size() - 1; j >= 0; j--){
        rep(i, 1000000){
            if(dp1[i] != INF && dp1[i + va[j]] == INF){
                dp1[i + va[j]] = dp1[i] + 1;
            }
        }
    }
    for(int j = vb.size(); j >= 0; j--){
        rep(i, 1000000){
            if(dp2[i] != INF && dp2[i + vb[j]] == INF){
                dp2[i + vb[j]] = dp2[i] + 1;
            }
        }
    }
}

int main(){
    int n;
    solve();
    while(cin >> n, n){
        cout << dp1[n] << ' ' << dp2[n] << endl;
    }
}

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

using namespace std;

#define N 1000000

int main() {
	int dp[N] = {0}, dp_odd[N] = {0};

	for(int i = 1; i < N; i++)
		dp[i] = dp_odd[i] = N;

	for(int i = 1; i < N; i++) {
		int t = i*(i+1)*(i+2)/6;
		if(t > N) break;
		for(int j = t; j < N; j++) dp[j] = min(dp[j], dp[j-t]+1);
		if(t%2 == 1) for(int j = t; j < N; j++) dp_odd[j] = min(dp_odd[j], dp_odd[j-t]+1);
	}

	int n;
	while(cin >> n && n) {
		cout << dp[n] << " " << dp_odd[n] << endl;
	}


	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;

const int INF = 100000000;

int main(){

	int n;
//	int dp[1000001];
	vector<int> dp(1000001,0);
	vector<int> dp2(1000001,0);
		vector<int> triNum;
		int sum = 1;
		int idx = 2;
		int allSum = 0;
		while(sum <= 1000000){
			allSum += sum;
			triNum.push_back(allSum);
			sum += idx;
			idx++;
		}
		fill(dp.begin(),dp.end(),INF);
		fill(dp2.begin(),dp2.end(),INF);
		dp[1] = 1;
		dp[2] = 2;
		dp[3] = 3;
		dp[0] = 0;

		dp2[1] = 1;
		dp2[2] = 2;
		dp2[3] = 3;
		dp2[0] = 0;


		for(int i = 4; i <= 1000001; i++){
			for(int j = 0; j < triNum.size(); j++){
				if(i - triNum[j] == 0){
					if(triNum[j] % 2)
						dp2[i] = 1;
					break;
				}
				else if(i - triNum[j] < 0){
					break;
				}
				if(triNum[j] % 2)
					dp2[i] = min(dp2[i],dp2[i-triNum[j]]+1);
			}

			for(int j = 0; j < triNum.size(); j++){
				if(i - triNum[j] == 0){
					dp[i] = 1;
					break;
				}
				else if(i - triNum[j] < 0){
					break;
				}
				dp[i] = min(dp[i],dp[i-triNum[j]]+1);
			}
		}

	while(cin >> n && n != 0){

		cout << dp[n] << " " << dp2[n] << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int DP1[1000001];
int DP2[1000001];

int main() {
    vector<int> oldarr, newarr;
    for(int i=1;i<200;++i){
        if(i*(i+1)/2*(i+2)/3>1000000) break;
        DP1[i*(i+1)/2*(i+2)/3] = 1;
        oldarr.push_back(i*(i+1)/2*(i+2)/3);
    }
    for(int i=2;i<6;++i){
        newarr.clear();
        for(int j=0;j<oldarr.size();++j){
            for(int k=1;k<200;++k){
                if(oldarr[j]+k*(k+1)/2*(k+2)/3>1000000) break;
                if(DP1[oldarr[j]+k*(k+1)/2*(k+2)/3]==0){
                    DP1[oldarr[j]+k*(k+1)/2*(k+2)/3] = i;
                    newarr.push_back(oldarr[j]+k*(k+1)/2*(k+2)/3);
                }
            }
        }
        oldarr = newarr;
    }

    oldarr.clear();
    for(int i=1;i<200;++i){
        if(i*(i+1)/2*(i+2)/3>1000000) break;
        if((i*(i+1)/2*(i+2)/3) % 2 == 1){
            DP2[i*(i+1)/2*(i+2)/3] = 1;
            oldarr.push_back(i*(i+1)/2*(i+2)/3);
        }
    }
    bool ans = true;
    while(ans){
        ans = false;
        newarr.clear();
        for(int j=0;j<oldarr.size();++j){
            for(int k=1;k<200;++k){
                if(oldarr[j]+k*(k+1)/2*(k+2)/3>1000000) break;
                if((k*(k+1)/2*(k+2)/3) % 2 == 1){
                    if(DP2[oldarr[j]+k*(k+1)/2*(k+2)/3]==0){
                        ans = true;
                        DP2[oldarr[j]+k*(k+1)/2*(k+2)/3] = DP2[oldarr[j]] + 1;
                        newarr.push_back(oldarr[j]+k*(k+1)/2*(k+2)/3);
                    }
                }
            }
        }
        oldarr = newarr;
    }
    int tmp;
    while(true){
        cin>>tmp;
        if(tmp==0) break;
        cout<<DP1[tmp]<<" "<<DP2[tmp]<<endl;
    }
}