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 <stdio.h>
#include <stdlib.h>

int n;

void solve(int *min,int flag,int c){
	int i;
	static int sum = 0, count = 0;
	if(count + 1 < *min && sum < n){
		for(i = 0;((i + 1) * (i + 2) * (i + 3)) / 6 + sum <= n && i < c;i++);
		while(i > 0){
			if(flag == 1 && i * (i + 1) * (i + 2) / 6 % 2 == 0){
				i--;
				continue;
			}
			sum += i * (i + 1) * (i + 2) / 6;
			count++;
			solve(min,flag,i);
			sum -= i * (i + 1) * (i + 2) / 6;
			count--;
			i--;
		}
	}
	else if(sum == n){
		if(count < *min)
			*min = count;
	}
	return;
}

int main(void){
	int min;
	scanf("%d",&n);
	while(n != 0){
		min = n;
		solve(&min,0,0x7FFFFFFF);
		printf("%d ",min);
		min = n;
		solve(&min,1,0x7FFFFFFF);
		printf("%d\n",min);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll cost[2010100] = {0};
ll cost2[2010100] = {0};
vector<ll> edge, edge2;
struct N {
  ll v, d;
};
ll M = 1000000;
ll INF = 1001010100101010;
bool operator<(const N &l, const N &r) { return l.d > r.d; }
int main() {
  for (int i = 1; i < 10000; i++) {
    ll ne = i * (i + 1) * (i + 2) / 6;
    if (ne > M)
      break;
    edge.push_back(ne);
    if (ne % 2 == 1)
      edge2.push_back(ne);
  }

  priority_queue<N> q, q2;
  for (auto &j : edge)
    q.push(N{j, 1});
  for (auto &j : edge2)
    q2.push(N{j, 1});
  for (int i = 0; i < M; i++)
    cost[i] = cost2[i] = INF;

  while (q.size()) {
    N now = q.top();
    q.pop();
    if (cost[now.v] < now.d)
      continue;
    cost[now.v] = now.d;
    for (auto &j : edge) {
      ll next = now.v + j;
      if (cost[next] < INF || next > M)
        continue;
      cost[next] = now.d + 1;
      q.push(N{next, now.d + 1});
    }
  }

  while (q2.size()) {
    N now = q2.top();
    q2.pop();
    if (cost2[now.v] < now.d)
      continue;
    cost2[now.v] = now.d;
    for (auto &j : edge2) {
      ll next = now.v + j;
      if (cost2[next] < INF || next > M)
        continue;
      cost2[next] = now.d + 1;
      q2.push(N{next, now.d + 1});
    }
  }

  while (true) {
    ll n;
    cin >> n;
    if (n == 0)
      break;
    cout << cost[n] << " " << cost2[n] << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int table[200];
int dp1[1000001];
int dp2[1000001];

int main(){
	for(int i=0;i < 200;i++){
		table[i]=i*(i+1)*(i+2)/6;
	}
	for(int i=0;i < 1000001;i++) dp1[i]=dp2[i]=99999999;
	dp1[0]=dp2[0]=0;
	for(int i=0;i < 1000001;i++){
		for(int j=1;j < 200;j++){
			if(i+table[j] <= 1000000) dp1[i+table[j]] = min(dp1[i+table[j]],dp1[i]+1);
			if(table[j]%2 && i+table[j] <= 1000000) dp2[i+table[j]] = min(dp2[i+table[j]],dp2[i]+1);
		}
	}
	int n;
	while(cin >> n,n){
		cout << dp1[n] << " " << dp2[n] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <cstring>

using namespace std;

int MAX;
vector<int> V;
vector<int> D;
int N;
int M;
bool dp[10][100010] = {0};

void solve(int n) {
	int ans = 1;

	for (int i=0; V[i]<=n; i++)
		dp[0][V[i]] = 1;

	for (int i=1; i<5 && !dp[i-1][n]; i++) {
		ans++;
		for (int j=0; j<=n; j++) {
			if (!dp[i-1][j]) continue;
			for (int k=0; j+V[k]<=n; k++)
				dp[i][j+V[k]] = 1;
			if (dp[i][n]) break;
		}
	}

	cout << ans << " ";

	memset(dp, 0, sizeof(dp));

	ans = 1;

	for (int i=0; D[i]<=n; i++)
		dp[0][D[i]] = 1;

	for (int i=1; i<=100000 && !dp[1-i%2][n]; i++) {
		ans++;
		for (int j=0; j<=n; j++) {
			if (!dp[1-i%2][j]) continue;
			for (int k=0; j+D[k]<=n; k++)
				dp[i%2][j+D[k]] = 1;
			if (dp[i%2][n]) break;
		}
	}

	cout << ans << endl;
}

int main() {
	MAX = (int)pow(10.0, 6);
	for (int i=1; i*(i+1)*(i+2)/6<=MAX; i++) {
		V.push_back(i*(i+1)*(i+2)/6);
		if ( V[i-1]%2==1 ) D.push_back(i*(i+1)*(i+2)/6);
	}
	N = (int)V.size();
	M = (int)D.size();

	int n;
	cin >> n;
	while (n!=0) { 
		solve(n);
		cin >> n;
	}
	return 0;
}

C++: // AOJ 1167
#include<cstdio>
#include<algorithm>
#include<vector>
#define rep(i,a) for( int i = 0; i != (a); ++i )

const int INF = 1<<30;

std::vector<int> tet;
std::vector<int> dp( 1000001, INF ), dpOdd( 1000001, INF );

int main()
{
	for( int i = 1; i*(i+1)*(i+2)/6 <= 1000000; ++i )
		tet.push_back( i*(i+1)*(i+2)/6 );

	dp[0] = dpOdd[0] = 0;
	rep( i, 1000001 )
	{
		rep( j, tet.size() )
		{
			if( i-tet[j] >= 0 )
			{
				dp[i] = std::min( dp[i], dp[i-tet[j]]+1 );
			
				if( tet[j]&1 )
					dpOdd[i] = std::min( dpOdd[i], dpOdd[i-tet[j]]+1 );
			}
		}
	}

	int n;
	while( scanf( "%d", &n ), n )
		printf( "%d %d\n", dp[n], dpOdd[n] );

	return 0;
}