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 <queue>
using namespace std;

struct P{
  int sum;
  char k,n;
  P(){}
  P(int S,int K,int N){ sum=S;k=K;n=N; }
};

int a[200];

int main(){
  int n, ans1,ans2;
  queue<P> q;
  P p;

  for( int i=1;i<200 ; i++ )
    if( (a[i]=i*(i+1)*(i+2)/6)>1000000 )
      break;

  int size,n2;
  while( cin>>n && n ){

    ans1=0;
    while( !q.empty() ) q.pop();
    for( int i=1;i<200;i++ ){
      if( a[i]==n ){
	ans1=1; size=i+1;
	break;
      }
      if( a[i]<n ) q.push( P(a[i],i,1) );
      else{
	size=i; break;
      }
    }
    while( !ans1 ){
      p=q.front(); q.pop();
      n2=p.n+1;
      for( int i=p.k,j;i<size;i++ ){
	j=p.sum+a[i];
	if( j==n ){
	  ans1=n2; break;
	}
	q.push( P(j,i,n2) );
      }
    }

    ans2=0;
    while( !q.empty() ) q.pop();
    for( int i=1;i<size;i++ ){
      if( a[i]%2==1 ){
	if( a[i]==n ){ ans2=1; break; }
	q.push( P(a[i],i,1) );
      }
    }
    while( !ans2 ){
      p=q.front(); q.pop();
      n2=p.n+1;
      for( int i=p.k,j;i<size;i++ ){
	if( a[i]%2==1 ){
	  j=p.sum+a[i];
	  if( j==n ){
	    ans2=n2; break;
	  }
	  q.push( P(j,i,n2) );
	}
      }
    }
    
    cout << ans1 << " " << ans2 << endl;
  }
    
  return 0;
}

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

int p[1000001];
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;p[i]<=n; i++) ans = min(ans, solve(n-p[i], 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;p[i]<=n; i++){
    if(!(p[i]%2)) continue;
    ans = min(ans, solve2(n-p[i])+1);
  }
  
  return memo2[n] = ans;
}

int main(){
  
  int n;
  
  for(int i=0;i<=1000000;i++) p[i] = i*(i+1)*(i+2)/6;
  for(int i=1;i<=1000000;i++)  solve2(i);
  
  while(cin >> n, n) cout << solve(n, 5) << " " << solve2(n) << endl;
}

C++: #include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int SIZE = 181 + 1;
const int MAX = 1000000;

int T[SIZE];
int cost1[MAX], cost2[MAX];

int main( void )
{	
	for(int i=0; i < SIZE; ++i) T[i] = i * (i + 1) * (i + 2) / 6;

	fill(cost1, cost1+MAX, MAX);
	fill(cost2, cost1+MAX, MAX);
	cost1[0] = cost2[0] = 0;
	for(int i=0; i < MAX; ++i) {
		//if(cost1[i] < 6) {
			for(int j=0; j < SIZE; ++j) {
				if(i + T[j] < MAX && cost1[i] < 5)
					cost1[i + T[j]] = min(cost1[i + T[j]], cost1[i] + 1);
				if(T[j] & 1) {
					if(i + T[j] < MAX)
						cost2[i + T[j]] = min(cost2[i + T[j]], cost2[i] + 1);
				}
			}
	}
	int n;
	while(cin >> n, n) {
		cout << cost1[n] << ' ' << cost2[n] << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iterator>

using namespace std;

int N;

int L[200];
int M[200];
int M_max;

void init() {
    for (int i = 1; i <= 200; i++) {
        L[i - 1] = (i * (i + 1) * (i + 2)) / 6;
    }

    int j = 0;
    for (int i = 0; i < 200; i++) {
        if (L[i] % 2 == 1) {
            M[j++] = L[i];
        }
    }
    M_max = j;
}

int f(int nth, int s) {
    int r = N - s;
    int start = distance(L, upper_bound(L, L + 200, r)) - 1;

    int m = 100;
    for (int i = start; i >= 0 && r <= (5 - nth) * L[i]; i--) {
        if (r == L[i]) {
            return nth + 1;
        }

        m = min(m, f(nth + 1, s + L[i]));
        break;
    }

    return m;
}

int g(int nth, int s) {
    int r = N - s;
    int start = distance(M, upper_bound(M, M + M_max, r)) - 1;

    int m = 100;
    for (int i = start; i >= 0; i--) {
        if (r == M[i]) {
            return nth + 1;
        }

        m = min(m, g(nth + 1, s + M[i]));
        break;
    }

    return m;
}

void solve() {
    printf("%d %d\n", f(0, 0), g(0, 0));
}

int main() {
    init();
    while (true) {
        scanf("%d", &N);
        if (!N) {
            break;
        }
        solve();
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAX_N = 1000001;
const int INF = 1<<27;
vector<int> N3, N4;
int T[MAX_N];

void makeN3() {
  N3.push_back(0);
  for(int i = 1, s = 1; s <= MAX_N; s += ++i) {
    N3.push_back(s);
  }
}

void makeN4() {
  N4.push_back(0);
  for(int i = 1, s = N3[1];
      i < N3.size() && s <= MAX_N; s += N3[++i]) {
    N4.push_back(s);
  }
}

int solve(int N, bool oddOnly) {
  fill(T, T+N+1, INF);
  T[0] = 0;
  for(int i = 1; i <= N; ++i) {
    for(int j = 1; j < N4.size() && N4[j] <= i; ++j) {
      if(oddOnly && N4[j]%2 == 0) continue;
      T[i] = min(T[i], T[i-N4[j]] + 1);
    }
  }
  return T[N];
}

int main() {
  int N;
  makeN3();
  makeN4();
  while(cin >> N && N) {
    cout << solve(N,false) << " " << solve(N,true) << endl;
  }
  return 0;
}