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 <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;

typedef long long int lli;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)

//FILE *in = freopen("C", "r", stdin);

int data[] = {1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364, 455, 560, 680, 816, 969, 1140, 1330, 1540, 1771, 2024, 2300, 2600, 2925, 3276, 3654, 4060, 4495, 4960, 5456, 5984, 6545, 7140, 7770, 8436, 9139, 9880, 10660, 11480, 12341, 13244, 14190, 15180, 16215, 17296, 18424, 19600, 20825, 22100, 23426, 24804, 26235, 27720, 29260, 30856, 32509, 34220, 35990, 37820, 39711, 41664, 43680, 45760, 47905, 50116, 52394, 54740, 57155, 59640, 62196, 64824, 67525, 70300, 73150, 76076, 79079, 82160, 85320, 88560, 91881, 95284, 98770, 102340, 105995, 109736, 113564, 117480, 121485, 125580, 129766, 134044, 138415, 142880, 147440, 152096, 156849, 161700, 166650, 171700, 176851, 182104, 187460, 192920, 198485, 204156, 209934, 215820, 221815, 227920, 234136, 240464, 246905, 253460, 260130, 266916, 273819, 280840, 287980, 295240, 302621, 310124, 317750, 325500, 333375, 341376, 349504, 357760, 366145, 374660, 383306, 392084, 400995, 410040, 419220, 428536, 437989, 447580, 457310, 467180, 477191, 487344, 497640, 508080, 518665, 529396, 540274, 551300, 562475, 573800, 585276, 596904, 608685, 620620, 632710, 644956, 657359, 669920, 682640, 695520, 708561, 721764, 735130, 748660, 762355, 776216, 790244, 804440, 818805, 833340, 848046, 862924, 877975, 893200, 908600, 924176, 939929, 955860, 971970, 988260, 1004731};
int data2[] = {1, 35, 165, 455, 969, 1771, 2925, 4495, 6545, 9139, 12341, 16215, 20825, 26235, 32509, 39711, 47905, 57155, 67525, 79079, 91881, 105995, 121485, 138415, 156849, 176851, 198485, 221815, 246905, 273819, 302621, 333375, 366145, 400995, 437989, 477191, 518665, 562475, 608685, 657359, 708561, 762355, 818805, 877975, 939929, 1004731};

int n;
int d1[1000010];
int d2[1000010];

void process() {
	fill(d1, d1 + n + 1 , -1);
	fill(d2, d2 + n + 1 , -1);
	d1[0] = 0;
	d2[0] = 0;
	for(int i = 0; i < 181; i++) {
		for(int j = data[i]; j <= n; j++) {
			if(d1[j - data[i]] != -1) {
				if(d1[j] == -1 || d1[j] > d1[j-data[i]] + 1) {
					d1[j] = d1[j-data[i]] + 1;
				}
			}
		}
	}
	for(int i = 0; i < 46; i++) {
		for(int j = data2[i]; j <= n; j++) {
			if(d2[j - data2[i]] != -1) {
				if(d2[j] == -1 || d2[j] > d2[j-data2[i]] + 1) {
					d2[j] = d2[j-data2[i]] + 1;
				}
			}
		}
	}

	printf("%d %d\n", d1[n], d2[n]);
}

int main() {
	while(true) {
		scanf("%d", &n);
		if(n == 0) break;
		process();
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <iterator>

using namespace std;

int N;

int L[200];
int M[200];
int M_max;

void init() {
    for (int i = 1; i <= 200; i++) {
        L[i - 1] = (i * (i + 1) * (i + 2)) / 6;
    }

    int j = 0;
    for (int i = 0; i < 200; i++) {
        if (L[i] % 2 == 1) {
            M[j++] = L[i];
        }
    }
    M_max = j;
}

int f(int nth, int s) {
    int r = N - s;
    int start = distance(L, upper_bound(L, L + 200, r)) - 1;

    int m = 100;
    for (int i = start; i >= 0 && r <= (5 - nth) * L[i]; i--) {
        if (r == L[i]) {
            return nth + 1;
        }

        m = min(m, f(nth + 1, s + L[i]));
    }

    return m;
}

int g(int nth, int s) {
    int r = N - s;
    int start = distance(M, upper_bound(M, M + M_max, r)) - 1;

    int m = 100;
    for (int i = start; i >= 0; i--) {
        if (r == M[i]) {
            return nth + 1;
        }

        m = min(m, g(nth + 1, s + M[i]));
    }

    return m;
}

void solve() {
    printf("%d %d\n", f(0, 0), g(0, 0));
}

int main() {
    init();
    while (true) {
        cin >> N;
        if (!N) {
            break;
        }
        solve();
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

const int INF = 1e9;
const int MAX_N = 1e6;
int dp[MAX_N + 1], dp_odd[MAX_N + 1];

void Init()
{
    int nth = 1;
    int tetra = 0;
    for (int i = 1; i <= MAX_N; ++i)
        dp[i] = dp_odd[i] = INF;

    while (tetra <= MAX_N) {
        tetra = (nth * (nth + 1) * (nth + 2)) / 6;
        if (tetra % 2 == 0) {
            for (int i = 0; i + tetra <= MAX_N; ++i)
                dp[i + tetra] = min(dp[i + tetra], dp[i] + 1);
        }
        else {
            for (int i = 0; i + tetra <= MAX_N; ++i) {
                dp[i + tetra] = min(dp[i + tetra], dp[i] + 1);
                dp_odd[i + tetra] = min(dp_odd[i + tetra], dp_odd[i] + 1);
            }
        }

        nth++;
    }
}

int main()
{
    Init();

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

    return 0;
}