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 <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main() {
    int n;
    int a[1000];
    int b[1000];
    int dp1[1000000];
    int dp2[1000000];
    while(cin >> n) {
        if(n == 0) break;
        rep(i,0,1000) {
            a[i] = 0;
            b[i] = 0;
        }

        int cnt = 0;
        for(int i = 1; i * (i+1) * (i+2) / 6 <= n; i++) {
            a[i-1] = i * (i+1) * (i+2) / 6;

            if(i * (i+1) * (i+2) / 6 % 2 == 1) {
                b[cnt] = i * (i+1) * (i+2) / 6;
                cnt++;
            }
        }

/*
        for(int i = 1; i * (i+1) * (i+2) / 6 <= n; i++) {
            cout << a[i-1] << endl;
        }

        cout << endl;

        for(int i = 0; b[i] != 0; i++) {
            cout << b[i] << endl;
        }
*/

        rep(i,0,1000000) {
            dp1[i] = i;
            dp2[i] = i;
        }

        int k = 0;
        while(a[k] != 0) {
            rep(j,0,1000000-a[k]+1) {
                dp1[j+a[k]] = min(dp1[j+a[k]], dp1[j] + 1);
            }
            k++;
        }

        k = 0;
        while(b[k] != 0) {
            rep(j,0,1000000-b[k]+1) {
                dp2[j+b[k]] = min(dp2[j+b[k]], dp2[j] + 1);
            }
            k++;
        }

        cout << dp1[n] << " "<< dp2[n] << endl;
    }
    return 0;
}

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

int p[1000001];
int memo[1000001];
int memo2[1000001];

int solve(int n, int count){
  
  if(!n) return 0;
  if(n <= 0 || !count) return INF;
  if(memo[n]) return memo[n];
  
  int ans = INF;
  for(int i=0;p[i]<=n; i++) ans = min(ans, solve(n-p[i], count-1)+1);
  
  return memo[n] = 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++) solve(i, 5), solve2(i);
  
  while(cin >> n, n) cout << solve(n, 5) << " " << solve2(n) << endl;
}

C++: #include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

int dp1[1000000+1], dp2[1000000+1][5]; // 奇数　そうでない
int main() {

  memset(dp1, -1, sizeof(dp1));
  memset(dp2, -1, sizeof(dp2));
  vector <int> memo;
  int cnt = 0;
  for (ll i = 1; i*(i+1)*(i+2)/6 <= 1000000; i++) {
    int val = i*(i+1)*(i+2)/6;
    memo.push_back(i*(i+1)*(i+2)/6);
    if (val%2) {
      cnt++;
    }
  }

  for (int i = 0; i < memo.size(); i++) {
    if (memo[i]%2) {
      dp1[memo[i]] = 1;
    }
    dp2[memo[i]][0] = 1;
  }


  for (int i = 1; i <= 1000000; i++) {
    for (int j = 0; j < memo.size() && memo[j] < i; j++) {
      if (memo[j]%2) {
	if (dp1[i-memo[j]] != -1) {
	  if (dp1[i] == -1) {
	    dp1[i] = dp1[i-memo[j]]+1;
	  }else {
	    dp1[i] = min(dp1[i], dp1[i-memo[j]]+1);
	  }
	}
      }

      for (int k = 1; k < 5; k++) {
	if (dp2[i-memo[j]][k-1] != -1) {
	  if (dp2[i][k] == -1) {
	    dp2[i][k] = dp2[i-memo[j]][k-1]+1;
	  }else {
	    dp2[i][k] = min(dp2[i][k], dp2[i-memo[j]][k-1]+1);
	  }
	}
      }
    }
  }

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

    int ans2;
    ans2 = 10000000;
    for (int i = 0; i < 5; i++) {
      if (dp2[n][i] != -1) {
	ans2 = min(ans2, dp2[n][i]);
      }
    }

    std::cout << ans2 << " " << dp1[n] << std::endl;
  }
}

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

int dp1[1000001];
int dp2[1000001];

int main() {
	int N = 1000000;

	vector<int> v1,v2;
	int n = 1;
	while(n*(n+1)*(n+2)/6<=N) {
		int p = n*(n+1)*(n+2) / 6;
		v1.push_back(p);
		if(p%2==1)
			v2.push_back(p);
		n++;
	}

	for(int i = 0;i < N+1;i++) {
		dp1[i] = i;
		dp2[i] = i;
	}
	//cout << v1.size() << " " << v2.size() << endl;
	for(auto v : v1) {
		for(int j = v;j < N + 1;j++) {
			dp1[j] = min(dp1[j],dp1[j - v] + 1);
		}
	}
	for(auto v : v2) {
		for(int j = v;j < N + 1;j++) {
			dp2[j] = min(dp2[j],dp2[j - v] + 1);
		}
	}

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

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

constexpr int LIMIT = 1000000;
int dp1[LIMIT], dp2[LIMIT];

void solve() {
  std::fill(dp1, dp1 + LIMIT, 100);
  std::fill(dp2, dp2 + LIMIT, 100);
  dp1[0] = dp2[0] = 0;
  for (int n = 1; n < 200; ++n) {
    int const tet = n * (n + 1) * (n + 2) / 6;
    for (int i = 0; i + tet < LIMIT; ++i) {
      dp1[i + tet] = std::min(dp1[i + tet], dp1[i] + 1);
      if (tet % 2) {
        dp2[i + tet] = std::min(dp2[i + tet], dp2[i] + 1);
      }
    }
  }
}

int main() {
  solve();
  int N;
  while (std::cin >> N && N) {
    std::cout << dp1[N] << " " << dp2[N] << std::endl;
  }
  return 0;
}