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>
using namespace std;
#define N 1000010

int t1[200];
int t2[200];
int dp1[N] = {0};
int dp2[N] = {0};

int main(){
	int i,j,k=2,s;
	
	t1[1] = 1; t2[1] = 1;
	for(i = 2; i < N; i++){
		t1[i] = t1[i-1] * (i+2) / (i-1);
		if(t1[i] > N) break;
		dp1[t1[i]] = 1;
		if(t1[i]%2){ dp2[t1[i]] = 1; t2[k++] = t1[i];}
	}

	for(i = 2, dp1[1] = dp2[1] = 1; i <= N; i++){
		if(dp2[i]) continue;
		for(j = 1; t2[j] < i; j++){
			if(!dp2[i] || (1 + dp2[i-t2[j]]) < (dp2[i])){
				dp2[i] = 1 + dp2[i-t2[j]];
			}
		}
		if(dp1[i]) continue;
		for(j = 1; t1[j] < i; j++){
			if(!dp1[i] || (1 + dp1[i-t1[j]]) < (dp1[i])){
				dp1[i] = 1 + dp1[i-t1[j]];
			}
		}
	}

	while(cin >> s, s)
		cout << dp1[s] << " " << dp2[s] << endl;

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int x[200][1000000], n, z[1000], y[1000], p, MAX;
int main() {
	z[0] = 0; for (int i = 1; i < 200; i++) { z[i] = z[i - 1] + (i + 1)*i / 2;}
	for (int i = 1; i < 200; i++) { if (z[i] % 2 == 1) { p++; y[p] = z[i]; } }
	while (true) {
		MAX = 2147483647; p = 0;
		cin >> n;
		if (n == 0) {
			break;
		}
		memset(x, 127, sizeof(x));
		x[0][0] = 0;
		for (int i = 1; i < 200; i++) {
			for (int j = 0; j < n; j++) {
				if (x[i - 1][j] < 2000000000) {
					for (int k = 0; k <= (n - j) / z[i]; k++) {
						x[i][j + z[i] * k] = min(x[i][j + z[i] * k], x[i - 1][j] + k);
					}
				}
			}
		}
		for (int i = 0; i < 50; i++) {
			if (MAX > x[i][n]) { p = i; MAX = x[i][n]; }
		}
		cout << MAX << ' ';
		MAX = 2147483647;
		memset(x, 127, sizeof(x));
		x[0][0] = 0;
		for (int i = 1; i < 50; i++) {
			for (int j = 0; j < n; j++) {
				if (x[i - 1][j] < 2000000000) {
					for (int k = 0; k <= (n - j) / y[i]; k++) {
						x[i][j + y[i] * k] = min(x[i][j + y[i] * k], x[i - 1][j] + k);
					}
				}
			}
		}
		for (int i = 0; i < 50; i++) {
			if (MAX > x[i][n]) { p = i; MAX = x[i][n]; }
		}
		cout << MAX << endl;
	}
}

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

using namespace std;

#define N 1000000

int main() {
	vector<int> tn;
	for(int i = 1; i < 100; i++) {
		tn.push_back(i*(i+1)*(i+2)/6);
	}

	int dp[N] = {0};
	int dp_odd[N] = {0};

	for(int i = 0; i < N; i++) {
		dp[i] = -1;
		dp_odd[i] = -1;
	}
	for(int t:tn) {
		dp[t] = 1;
		if(t%2 == 1)
			dp_odd[t] = 1;
	}

	reverse(tn.begin(), tn.end());

	for(int t:tn) {
		for(int i = N-1; i >= 1; i--) {
			if(dp[i] == -1) continue;
			for(int j = 1; i+j*t < N && dp[i+j*t] == -1; j++) {
				if(dp[i+j*t] == -1) dp[i+j*t] = dp[i]+j;
				else dp[i+j*t] = min(dp[i+j*t], dp[i]+j);
			}

			if(t%2 == 1) {
				if(dp_odd[i] == -1) continue;
				for(int j = 1; i+j*t < N && dp_odd[i+j*t] == -1; j++) {
					if(dp_odd[i+j*t] == -1) dp_odd[i+j*t] = dp_odd[i]+j;
					else dp_odd[i+j*t] = min(dp_odd[i+j*t], dp_odd[i]+j);
				}
			}
		}

	}

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


	return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	vi three;
	int num = 1, tmp = 0;
	while(tmp <= 100000) {
		tmp += num;
		three.push_back(tmp);
		num++;
	}

	vi four;
	tmp = 0;
	int pos = 0;
	while(tmp <= 100000) {
		tmp += three[pos];
		four.push_back(tmp);
		pos++;
	}
	int fsize = four.size();

	int n;
	while(cin >> n, n) {
		vi dp(n+1, INF);
		vi dpk(n+1, INF);
		dp[0] = dpk[0] = 0;

		FOR(i, 1, n) {
			REP(j, fsize) {
				if(i-four[j] >= 0) {
					dp[i] = min(dp[i-four[j]]+1, dp[i]);
					if(four[j]%2) {
						dpk[i] = min(dpk[i-four[j]]+1, dpk[i]);
					}
				} else {
					break;
				}
			}
		}

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

	return 0;
}