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 <algorithm>
#include <cstdio>
using namespace std;

int coin[100000];
int coin_ki[100000];
int dp[100000]={1000000};
int dp2[100000];

int main(void)
{

  int count=0;
  int count_ki=0;
  int tmp;
  int ans_tmp=0;
  int ans2_tmp=0;
    
   
  int tmp2=0;

  for(int i=1;i<100000;i++){
      tmp=i*(i+1)*(i+2)/6;
      if(tmp>1000000)break;
      coin[i-1]=tmp;
      count=i;
      if(coin[i-1]%2==1){
	coin_ki[tmp2++]=coin[i-1];
	count_ki=tmp2;
      }
    }

  for(;;){
    int x;
    cin >> x;

    if(x==0)
      break;

   
  
    
    
    
    for(int i=0;i<100000;i++)
      dp[i]=100000;

    dp[0]=0;
    for(int i = 0;i<x;i++){
      for(int j=0;j<count;j++){
	if(i+coin[j]<=x){
	  dp[i+coin[j]]=min(dp[i+coin[j]],dp[i]+1);
	  //printf("dp[%d]=%d\n",i+coin[j],dp[i+coin[j]]);
	}
      }
    }


    int ans1=dp[x];

    
    
    for(int i=0;i<100000;i++)
      dp2[i]=100000;
      

    

    dp2[0]=0;
    for(int i = 0;i<x;i++){
      for(int j=0;j<count_ki;j++){
	if(i+coin_ki[j]<=x){
	  ans2_tmp=min(dp2[i+coin_ki[j]],dp2[i]+1);
	  dp2[i+coin_ki[j]]=ans2_tmp;
	  //printf("dp2[%d]=%d\n",i+coin_ki[j],dp[i+coin_ki[j]]);
	}
      }
    }
   
    
    int ans2=dp2[x];
    

    //for(int i=0;i<count;i++)
      //printf("coin[%d]=%d\n",i,coin[i]);
      //for(int i=0;i<count_ki;i++)
      //printf("coin_ki[%d]=%d\n",i,coin_ki[i]);


    printf("%d %d\n",ans1,ans2);
  }
  return 0;
}

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

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){
	long long mo=modpow(10,6,inf);
	vector<long long> simen,kisu;
	long long hoge=1;
	while(hoge*(hoge+1)*(hoge+2)/6<=mo){
		simen.push_back(hoge*(hoge+1)*(hoge+2)/6);
		if(hoge*(hoge+1)*(hoge+2)/6%2==1) kisu.push_back(hoge*(hoge+1)*(hoge+2)/6);
		hoge++;
	}

	vector<long long> dp(mo+1,inf),kdp=dp;
	dp.at(0)=0;
	kdp.at(0)=0;

	for(long long i=0;i<=mo;i++){
		for(auto a:simen){
			if(i+a<=mo){
				dp.at(i+a)=min(dp.at(i+a),dp.at(i)+1);
			}
		}
		for(auto a:kisu){
			if(i+a<=mo){
				kdp.at(i+a)=min(kdp.at(i+a),kdp.at(i)+1);
			}
		}
	}

	long long n;
	cin>>n;
	while(n>0){
		cout<<dp.at(n)<<" "<<kdp.at(n)<<endl;
		cin>>n;
	}

	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 1000000;

int N;

int dp[MAX_N + 1], dp_odd[MAX_N + 1];

int main() {
    vector<int> tetra, tetra_odd;
    for (int i = 1; i <= 200; i++) {
        int a = i * (i+1) * (i+2) / 6;
        tetra.PB(a);
        if (a % 2 == 1) tetra_odd.PB(a);
    }

    REP(i, MAX_N + 1) {
        dp[i] = MOD;
        dp_odd[i] = MOD;
    }
    dp[0] = 0;
    dp_odd[0] = 0;

    REP(i, MAX_N) {
        REP(j, tetra.size()) {
            if (i + tetra[j] <= MAX_N) dp[i + tetra[j]] = min(dp[i + tetra[j]], dp[i] + 1);
        }
        REP(j, tetra_odd.size()) {
            if (i + tetra_odd[j] <= MAX_N) dp_odd[i + tetra_odd[j]] = min(dp_odd[i + tetra_odd[j]], dp_odd[i] + 1);
        }
    }
    
    while (true) {
        cin >> N;
        if (N == 0) break;
        printf("%d %d\n", dp[N], dp_odd[N]);
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#define INF 1<<28
using namespace std;

int memo[1000001][6];
int memo2[1000001];

int solve(int n, int count){

  if(!n) return 0;
  if(n <= 0 || !count) return INF;
  if(memo[n][count]) return memo[n][count];

  int ans = INF;
  for(int i=0,k=0; k=i*(i+1)*(i+2)/6, k<=n; i++){
    ans = min(ans, solve(n-k, count-1)+1);
  }

  return memo[n][count] = ans;
}

int solve2(int n){
  
  if(!n) return 0;
  if(n<0) return INF;
  if(memo2[n]) return memo2[n];

  int ans = INF;
  for(int i=0,k=0;k=i*(i+1)*(i+2)/6, k<=n; i++){
    if(!(k%2)) continue;
    ans = min(ans, solve2(n-k)+1);
  }

  return memo2[n] = ans;
}

int main(){
  
  int n;
  for(int i=1;i<=1000000;i++) solve2(i);

  while(cin >> n, n)
    cout << solve(n, 5) << " " << solve2(n) << endl;
}

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

int main() {
  int const M = 1e6+10;
  // Mより小さい正四面体数を求める。
  vector<int> tet[2];
  for (int i=1; i<M; i++) {
    int t = i * (i+1) * (i+2) / 6;
    if (t >= M) break;
    tet[0].push_back(t);
    if (t % 2 == 1) {
      tet[1].push_back(t);
    }
  }
  int ans[2][M];
  for (int i=0; i<=1; i++) { // 両方並行して行う。
    ans[i][0] = 0;
    for (int j=1; j<M; j++) {
      int min = M;
      for (unsigned int k=0; k<tet[i].size(); k++) {
	if (tet[i][k] > j) break;
	if (min > ans[i][j-tet[i][k]] + 1) {
	  min = ans[i][j-tet[i][k]] + 1;
	}
      }
      ans[i][j] = min;
    }
  }
  int N;
  while (scanf("%d", &N) != EOF && N) {
    printf("%d %d\n", ans[0][N], ans[1][N]);
  }
}