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>
#define INF 1 << 9
using namespace std;

int pollock[200];
int pollock2[200] = {INF};

void calcPollock() {
  for (int i = 0; i < 200; i++) {
    pollock[i] = i * (i + 1) * (i + 2) / 6;
  }
  pollock2[0] = 0;
  int j = 1;
  for (int i = 0; i < 200; i++) {
    if (pollock[i] % 2)
      pollock2[j++] = pollock[i];
  }
}

int countPollock2(int n) {
  int temp, maxp;
  for (int i = 0; i < 200; i++)
    if (pollock2[i] > n) {
      maxp = i - 1;
      break;
    }
  
  int count[maxp + 1] = {0};
  for (int i = maxp; i > 0; i--) {
    temp = n;
    int j = i;
    while (temp > 0) {
      while (temp < pollock2[j]) {
	j--;
      }
      count[i]++;
      temp -= pollock2[j];
    }
  }
  sort(count, count + maxp + 1);
  
  for (int i = 0; i < 200; i++)
    if (count[i] > 0) return count[i];
}


int countPollock(int n) {
  int temp, maxp;
  for (int i = 0; i < 200; i++)
    if (pollock[i] > n) {
      maxp = i - 1;
      break;
    }
  
  int count[maxp + 1] = {0};
  for (int i = maxp; pollock[i] * 5 > pollock[maxp]; i--) {
    temp = n;
    int j = i;
    while (temp > 0) {
      while (temp < pollock[j]) {
	j--;
      }
      count[i]++;
      temp -= pollock[j];
    }
  }
  sort(count, count + maxp + 1);
  for (int i = 0; i < 200; i++)
    if (count[i] > 0) return count[i];
}

int main() {
  calcPollock();

  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;

    int ans = countPollock(n);
    int ans2 = countPollock2(n);

    cout << ans << ' ' << ans2 << endl;
  }
}

C++: #include<iostream>

using namespace std;
#define MAX 1000000
#define INF 1000000000

int dp1[MAX+1],dp2[MAX+2];

int main(){
    for(int i = 1;i <= MAX;i++){
        dp1[i] = INF;
        dp2[i] = INF;
    }

    for(int n = 1;n * (n + 1) * (n + 2) / 6 <= MAX;n++){
        int a = n * (n + 1) * (n + 2) / 6;
        for(int i = a;i <= MAX;i++){
            dp1[i] = min(dp1[i],dp2[i - a] + 1);
        }
        if(a % 2 == 0)continue;
        for(int i = a;i <= MAX;i++){
            dp2[i] = min(dp2[i],dp2[i - a] + 1);
        }
    }

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

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int sum[222];

//int dp[1111111][222];
int dp[2][1111111];

/*
int solve(int s,int i,int f){
  //if(!s) return 0;
  if(i >= m) return s;
  if(dp[s][i])return dp[s][i];

  int ret = 1 << 28;
  if(!((sum[i] + 1) % f)){
    for(int j = 0;s - sum[i] * j >= 0 ; j++){
      ret = min(ret,solve(s - sum[i] * j,i + 1,f) + j);
    }
  }
  ret = min(ret,solve(s,i + 1,f));

  return dp[s][i] = ret;
}
*/
int solve(int s,int f){
  if(!s) return 0;
  if(dp[f-1][s]) return dp[f-1][s];

  int ret = 1 << 28;
  for(int i = 0; s >= sum[i]; i++){
    if(!((sum[i] + 1) % f)){
      ret = min(ret,solve(s - sum[i],f) + 1);
    }
  }
  return dp[f-1][s] = ret;
}

int main(void){
  sum[0] = 1;
  for(int i = 1; sum[i-1] <= 1000000; i++){
    sum[i] = sum[i-1] * (i + 3) / i;
  }
  for(int i = 1; i < 1000000; i++){
    solve(i,1);
    solve(i,2);
  }
  //puts("ok");
  while(1){
    scanf("%d",&n); if(!n) break;
    printf("%d %d\n",dp[0][n],dp[1][n]);
  }
}

C++: #include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,dp[1000001],dp2[1000001];
vector<ll> v,u;
int main(void){
    for(ll i=1;i<1000;i++){
        a+=i*(i+1)/2;
        //cout<<a<<endl;
        if(a<=1000000){
            v.push_back(a);
            if(a%2==1)u.push_back(a);
        }
        else break;
    }
    for(int i=0;i<=1000000;i++)dp[i]=i;
    for(int i=0;i<=1000000;i++)dp2[i]=i;
    for(int i=1;i<v.size();i++){
        for(int j=0;j+v[i]<=1000000;j++){
            dp[j+v[i]]=min(dp[j+v[i]],dp[j]+1);
        }
    }
    for(int i=1;i<u.size();i++){
        for(int j=0;j+u[i]<=1000000;j++){
            dp2[j+u[i]]=min(dp2[j+u[i]],dp2[j]+1);
        }
    }
    while(1){
    cin>>n;
    if(n==0)return 0;
        cout<<dp[n]<<" "<<dp2[n]<<endl;
    }
}

C++: #include<bits/stdc++.h>
const int MAX=1e6+10;
using namespace std;
int main(){
    vector<int>precal;
    vector<int>dp(MAX,MAX);
    vector<bool>flag(MAX+10,false);
    int n;
    precal.push_back(0);
    dp[0]=0;
    for(int i=1;;i++){
        int cnt=((i)*(i+1)*(i+2))/6;
        if(cnt>MAX)break;
        precal.push_back(cnt);
        flag[cnt]=true;
    }
    for(int i=1; i<=MAX-9;i++){
        if(flag[i]){dp[i]=1; continue;}
        int index=(int)(upper_bound(precal.begin(),precal.end(),i)-precal.begin());
        for(int j=0; j<=index;j++)
            dp[i]=min(dp[i],dp[precal[j]]+dp[i-precal[j]]);
    }
    vector<int>oddcal;
    vector<int>odp(MAX,MAX);
    vector<bool>oddflag(MAX+10,false);
    oddcal.push_back(0);
    odp[0]=0;
    for(int i=1;;i++){
        int cnt=(i*(i+1)*(i+2))/6;
        if(cnt>MAX)break;
        if(!(cnt%2))continue;
        oddcal.push_back(cnt);
        oddflag[cnt]=true;
    }
    for(int i=1; i<=MAX-9;i++){
        if(oddflag[i]){odp[i]=1;continue;}
        int index=(int)(upper_bound(oddcal.begin(), oddcal.end(), i)-oddcal.begin());
        for(int j=0;j<=index;j++)
            odp[i]=min(odp[i],odp[oddcal[j]]+odp[i-oddcal[j]]);
        
    }
    while(cin>>n,n){
        cout<<dp[n]<<" "<<odp[n]<<endl;
    }
}