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 <string>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <stdlib.h>
using namespace std;
int main(){
	int *a=new int[1000000];
	int *b=new int[1000000];
	for(int i=0;i<1000000;i++){
		a[i]=100000;
		b[i]=100000;
	}
	for(int i=1;i<pow(6000000,0.4)+5;i++){
		int aa=(i*(i+1)*(i+2))/6;
		if(aa<1000000){
			a[aa]=1;
		}
	}
	a[0]=0;
	a[2]=2;
	a[3]=3;
	for(int i=4;i<1000000;i++){
		if(a[i]==1){
			for(int j=1;j<=1000000/i+2;j++){
				for(int k=0;k<2*i;k++){
					if(j*i+k<1000000){
						a[j*i+k]=min(a[j*i+k],j+a[k]);
					}
				}
			}
		}
	}
	for(int i=0;i<pow(6000000,0.4)/4+5;i++){
		int bb=((4*i+1)*(4*i+2)*(4*i+3))/6;
		if(bb<1000000){
			b[bb]=1;
		}
	}
	b[0]=0;
	for(int i=2;i<35;i++){
		b[i]=i;
	}
	for(int i=4;i<1000000;i++){
		if(b[i]==1){
			for(int j=1;j<=1000000/i+2;j++){
				for(int k=0;k<3*i;k++){
					if(j*i+k<1000000){
						b[j*i+k]=min(b[j*i+k],j+b[k]);
					}
				}
			}
		}
	}
	int n;
	while(cin>>n){
		if(n==0) break;
		cout<<a[n]<<" "<<b[n]<<endl;
	}
    return 0;
    delete[] a;
    delete[] b;
}

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

using namespace std;

int dp1[100010]={0};
int dp2[100010]={0};
int List[100];

void setpolloc(){
	int i,j,li;
	for(i=1;i*(i+1)*(i+2)/6<=100000;i++){
/*		List[i]=i*(i+1)*(i+2)/6;
		dp1[i*(i+1)*(i+2)/6]=1;
		if((i*(i+1)*(i+2)/6)%2) dp2[i*(i+1)*(i+2)/6]=1;
*/	}
	List[i]=i*(i+1)*(i+2)/6;
	for(i=1;i<=100000;i++){
		if(dp2[i]) continue;
		for(j=1;List[j]<=i-1;j+=2)if(!dp2[i] || dp2[List[j]]+dp2[i-List[j]] < dp2[i]) dp2[i]=dp2[List[j]]+dp2[i-List[j]];
		if(dp1[i]) continue;
		for(j=1;List[j]<=i-1;j++) if(!dp1[i] || dp1[List[j]]+dp1[i-List[j]] < dp1[i]) dp1[i]=dp1[List[j]]+dp1[i-List[j]];
	}
}


int main(){
	int n;
	setpolloc();
	while(cin>>n,n){
		cout << dp1[n] << ' ' << dp2[n] << endl;
	}
	return 0;
}

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

int dp1[1000001], dp2[1000001];

void num(){
	for(int i = 1; i < 1000001; i++){
		dp1[i] = 1000000;
		dp2[i] = 1000000;
	}
	vector<int> v1, v2;
	for(int i = 1; i < 200; i++){
		int t = (i*i*i+3*i*i+2*i)/6;
		if(t > 1000000) break;
		v1.push_back(t);
		if(t%2) v2.push_back(t);
	}
	for(int i = 1; i < 1000001; i++){
		for(int j = 0; j < v1.size(); j++){
			if(i < v1[j]) break;
			dp1[i] = min(dp1[i],dp1[i-v1[j]]+1);
		}
		for(int j = 0; j < v2.size(); j++){
			if(i < v2[j]) break;
			dp2[i] = min(dp2[i],dp2[i-v2[j]]+1);
		}
	}
}

int main(){
	num();
	int n;
	while(scanf("%d", &n), n) printf("%d %d\n", dp1[n], dp2[n]);
}

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

int p[1111111];
int memo[1111111];
int memo2[1111111];

int solve(int n){
  
  if(!n) return 0;
  if(~memo[n]) return memo[n];

  int ans = INF;
  for(int i=199;i>0;i--) if(n-p[i] >= 0) ans = min(ans, solve(n-p[i])+1);
  
  return memo[n] = ans;
}

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

  int ans = INF;
  for(int i=199;i>0;i--) if(n-p[i] >= 0 && p[i]&1) ans = min(ans, solve2(n-p[i])+1);

  return memo2[n] = ans;
}

int main(){
  
  int n;
  
  memset(memo, -1, sizeof(memo));
  memset(memo2, -1, sizeof(memo2));

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

}

C++: #include <iostream>
using namespace std;
int main(){
  int a[190]={0},b[50]={0},c[1000001]={0,1,2,3},d[1000001],k=0,i,j,n;

  for(i=1;i<190;i++)a[k++]=i*(i+1)*(i+2)/6;

  for(j=k=0;j<i;j++)if(a[j]%2)b[k++]=a[j];

  for(i=1;i<189;i++)for(j=a[i];j<a[i+1];j++)c[j]=c[j-a[i]]+1;

  for(i=0;i<36;i++)d[i]=i;
  for(i=1;i<k-1;i++)for(j=b[i];j<b[i+1];j++)d[j]=d[j-b[i]]+1;

  while(cin>>n,n)cout<<c[n]<<' '<<d[n]<<endl;
}

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

using namespace std;
typedef long long ll;

#define REP_N(i,n,s) for(ll i=0; i<(ll)n; i+=s)
#define REP(i,n) REP_N(i,n,1)

ll table[1000000];
ll pollock[1000001];
ll dp[1000001];

void solution(ll output[1000001], int interval) {
	output[0] = 0;
	ll current_i = 1-interval;
	REP(i, 1000001) if (i != 0) {
		if (table[current_i + interval] == i){
			current_i += interval;
			output[i] = 1;
			continue;
		}
		ll minimum = 1000001;
		REP_N(j, current_i+1, interval) if(j!=0) minimum = min(output[i - table[j]] + 1, minimum);
		output[i] = minimum;

	}
}

int main() {
	{
		ll i = 0;
		table[0] = 0;
		while (1000001 > table[i++]) table[i] = i*(i + 1)*(i + 2) / 6;
	}

	solution(pollock, 1);
	solution(dp, 4);

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

}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    int lim = 1000010;
    vector<int> dp(lim, lim);
    vector<int> oddp(lim, lim);
    vector<int> lis;
    for (int i = 1; ; ++i) {
        int p = i * (i + 1) * (i + 2) / 6;
        if (p > lim) break;
        lis.push_back(p);
    }
    dp[0] = oddp[0] = 0;
    for (int i = 1; i < lim; ++i) {
        for (int j : lis) {
            if (j > i) break;
            dp[i] = min(dp[i], dp[i - j] + 1);
            if (j & 1)
                oddp[i] = min(oddp[i], oddp[i - j] + 1);
        }
    }
    while (1) {
        int n;
        cin >> n;
        if (!n) return 0;

        cout << dp[n] << " " << oddp[n] << "\n";
    }
}