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 <iostream>
#include <queue>

using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

int main() {
    int table1[100000];
    int max1;
    for (int i = 1; i < 100000; i++) {
        table1[i] = i * (i + 1) * (i + 2) / 6;
        if (table1[i] >= 1000000) {
            max1 = i - 1;
            break;
        }
    }
    int table2[100000];
    int max2;
    for (int i = 1; i < 100000; i++) {
        int n = i;
        do {
            table2[i] = n * (n + 1) * (n + 2) / 6;
            n++;
        } while (table2[i] % 2 == 0);
        if (table2[i] >= 1000000) {
            max2 = i - 1;
            break;
        }
    }

    int m;
    while (cin >> m, m) {
        bool used[1000000];
        fill_n((bool *)used, 1000000, false);
        priority_queue<ppiii, vector<ppiii>, greater<ppiii>> q;
        q.push({{0, 0}, 1});
        while (!q.empty()) {
            ppiii p = q.top(); q.pop();
            int count = p.first.first;
            int total = p.first.second;
            int now = p.second;

            // goal
            if (total == m) {
                cout << count << " ";
                break;
            }

            for (int i = now; i < max1; i++) {
                int sum = table1[i] + total;
                if (sum <= m && !used[sum]) {
                    q.push({{count+1, sum}, i});
                    used[sum] = true;
                }
            }
        }
        while(!q.empty())
            q.pop();
        fill_n((bool *)used, 1000000, false);
        q.push({{0, 0}, 1});
        while (!q.empty()) {
            ppiii p = q.top(); q.pop();
            int count = p.first.first;
            int total = p.first.second;
            int now = p.second;

            // goal
            if (total == m) {
                cout << count << endl;
                break;
            }

            for (int i = now; i < max2; i++) {
                int sum = table2[i] + total;
                if (sum <= m && !used[sum]) {
                    q.push({{count+1, sum}, i});
                    used[sum] = true;
                }
            }
        }
    }
    
    return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;

const int INF = 1000000000;

int main(){
	int ans[1000000];
	int bns[1000000];
	for(int i=0;i<1000000;i++){
		if(i==0){
			ans[i] = 0;
			bns[i] = 0;
			continue;
		}
		ans[i] = INF;
		bns[i] = INF;
		for(int j=0;i-j*(j+1)*(j+2)/6>=0&&j<200;j++){
			ans[i] = min(ans[i],ans[i-j*(j+1)*(j+2)/6]+1);
			if(j*(j+1)*(j+2)/6%2==1) bns[i] = min(bns[i],bns[i-j*(j+1)*(j+2)/6]+1);
		}
	}
	while(true){
		int n;
		scanf("%d",&n);
		if(n==0) break;
		else printf("%d %d\n",ans[n],bns[n]);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_N = 1000000;

int cnt1[MAX_N+1],cnt2[MAX_N+1];

int main()
{
    rep(i,MAX_N){
        cnt1[i] = cnt2[i] = 10*MAX_N;
    }
    cnt1[0] = cnt2[0] = 0;
    for(int j=1;;j++){
        int val = j*(j+1)*(j+2)/6;
        if(val > MAX_N){
            break;
        }
        for(int i=0;i+val<=MAX_N;i++){
            cnt1[i+val] = min(cnt1[i+val],cnt1[i]+1);
        }
        if(val%2){
            for(int i=0;i+val<=MAX_N;i++){
                cnt2[i+val] = min(cnt2[i+val],cnt2[i]+1);
            }
        }
    }
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        cout << cnt1[n] << " " << cnt2[n] << "\n";
    }
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int main(){
    vector<int> v(201);
    for(int i=1; i<=200; i++){
        v[i] = i * (i + 1) * (i + 2) / 6;
    }

    vector<int> dp1(1000010, 1e9);
    dp1[0] = 0;
    auto dp2 = dp1;

    for(int i=1; i<=200; i++){
        for(int j=0; j<=1000005; j++){
            if(j - v[i] >= 0) dp1[j] = min(dp1[j], dp1[j-v[i]] + 1);

            if(v[i] % 2){
                if(j - v[i] >= 0) dp2[j] = min(dp2[j], dp2[j-v[i]] + 1);
            }
        }
    }

    while(1){
        int n; cin>>n;
        if(n == 0) return 0;

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