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 "algorithm"
#include "cmath"
#include "iostream"
#include "map"
#include "string"
#include "unordered_map"
#include "vector"
constexpr int MOD = 1000000007;
constexpr int INF = 1000000000;
using namespace std; // std::を省略して書くことができる

int dp[1000001][2];
int main() {
  for (int i = 0; i < 1e6; i++) {
    dp[i][0] = INF;
    dp[i][1] = INF;
  }
  vector<int> list;
  vector<int> list_odd;
  for (int i = 1; i < INF; i++) {
    int SUM = i * (i + 1) * (i + 2) / 6;
    if (SUM <= 1e6) {
      list.push_back(SUM);
      if (SUM % 2 == 1)
        list_odd.push_back(SUM);
    } else {
      break;
    }
  }
  dp[0][0] = 0;
  dp[0][1] = 0;
  for (int i = 0; i < 1e6 + 1; i++) {
    for (int j = 0; j < 179; j++) {
      for (int k = 1; k < 10; k++) {
        if (i + list[j] * k < 1e6 + 1) {
          dp[i + list[j] * k][0] = min(dp[i + list[j] * k][0], dp[i][0] + k);
        } else {
          break;
        }
      }
    }

    for (int j = 0; j < 44; j++) {
      for (int k = 1; k < 10; k++) {
        if (i + list_odd[j] * k < 1e6 + 1) {
          dp[i + list_odd[j] * k][1] =
              min(dp[i + list_odd[j] * k][1], dp[i][1] + k);
        } else {
          break;
        }
      }
    }
  }

  int n;
  cin >> n;
  while (n != 0) {
    cout << dp[n][0] << " " << dp[n][1] << endl;
    cin >> n;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int dp1[1000005], dp2[1000005];
void makeDP(){
  vector<int> v1;
  vector<int> v2;
  int tn = 1;
  while(1){
      int tmp = tn*(tn+1)*(tn+2)/6;
      if(tmp < 1000000){
        v1.push_back(tmp);
        if(tmp % 2 != 0) v2.push_back(tmp);
      }else{
        break;
      }
      tn++;
  }
  REP(i,0,1000005) dp1[i] = i, dp2[i] = i;
  REP(i,1,180){
    REP(j,0,1000005){
      if(j-v1[i] >= 0) dp1[j] = min(dp1[j], dp1[j-v1[i]] + 1);
    }
  }
  REP(i,1,45){
    REP(j,0,1000005){
      if(j-v2[i] >= 0) dp2[j] = min(dp2[j], dp2[j-v2[i]] + 1);
    }
  }
}

int main() {

  makeDP();

  int N;
  while(1){
    cin>>N;
    if(N==0) break;
    cout<<dp1[N]<<" "<<dp2[N]<<endl;
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int tbl1[1000001];
int tbl2[1000001];
int tet(int x){ return x*(x+1)*(x+2)/6; }
int solve1(int n){
  if(n<0) return 1000;
  if(n==0) return 0;
  if(tbl1[n]) return tbl1[n];
  int ret = 1000;
  for(int i=1;tet(i)<=n;++i)
    ret = min(ret,1+solve1(n-tet(i)));
  return tbl1[n] = ret;
}
int solve2(int n){
  if(n<0) return 1000;
  if(n==0) return 0;
  if(tbl2[n]) return tbl2[n];
  int ret = 1000;
  for(int i=1;tet(i)<=n;++i)
    if(tet(i)%2)
      ret = min(ret,1+solve2(n-tet(i)));
  return tbl2[n] = ret;
}

int main(){
  int n;
  while(cin>>n,n){
    cout << solve1(n) << " " << solve2(n) << endl;
  }
  return 0;
}

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

const int MAX_NUM = 1000000;
const int INF = 100000000;

int table[2][MAX_NUM];
int tet[2][1000];

int calc(int num,int m)
{
    if(table[m][num]==INF) {
        for(int i=1; tet[m][i]<num; i++) {
            table[m][num]=min(table[m][num],calc(num-tet[m][i],m)+1);
        }
    }
    return table[m][num];
}

int main()
{
    for(int i=0; i<MAX_NUM; i++) {
        table[0][i] = INF;
        table[1][i] = INF;
    }

    for(int i=1; i*(i+1)*(i+2)/6<MAX_NUM; i++) {
        int t=i*(i+1)*(i+2)/6;
        table[0][t] = 1;
        tet[0][i] = t;

        if(t%2 == 1) {
            table[1][t] = 1;
            tet[1][i] = t;
        }
    }

    int in;
    while(cin>>in && in) {
        cout<<calc(in,0)<<" "<<calc(in,1)<<endl;
    }

    return 0;
}