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 <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
static const int N = 1000005;

int n;
ll K;
int dp[N],dpo[N];
ll pollock[N];
ll pmax;
int cmax;
int a;

int pol()
{
	scanf("%d",&n);
	if(n==0)return -1;
	if(cmax>=n){
		a = dpo[n];
		return dp[n];
	}
	while(pollock[pmax]<=n){
		pmax++;
		pollock[pmax] = pmax*(pmax+1)*(pmax+2)/6;
	}
	int j=1,s=1,f=1;
	for(int i=cmax+1;i<=n;i++){
		while(pollock[j]<=i)j++;
		if(j<=2)dp[i]=dp[i-pollock[j-1]]+1;
		else dp[i] = min(dp[i-pollock[j-1]],dp[i-pollock[j-2]])+1;


		f = j-1;
		while(pollock[f]%2==0)f--;
		s = f;
		if(f>2)s--;
		while(pollock[s]%2==0)s--;
		dpo[i] = min(dpo[i-pollock[f]],dpo[i-pollock[s]])+1;
	}
	cmax=n;
	a = dpo[n];
	return dp[n];
}
int main(){
	pmax=0;
	cmax=0;
	dp[0]=0;
	dpo[0]=0;
	pollock[0]=0;
	while(1){
		int p = pol();
		if(p==-1)return 0;
		printf("%d %d\n",p,a);
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define MAX 1000000
int main(){
  int a[MAX + 1],b[MAX + 1];
  a[0] = b[0] = 0;
  for(int i = 1; i < MAX + 1; i++){
    a[i] = b[i] = i;
    for(int j = 1;  ; j++ ){
      int java = j * (j + 1) * (j + 2) / 6;
      if(i - java < 0) break;
      a[i] = min( a[i], a[i - java] + 1);
      if(java & 1) b[i] = min( b[i], b[i - java] + 1);
    }
  }
  int n;
  while(cin >> n, n){
    cout << a[n] << " " << b[n] << endl;
  }
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

ll dp[1000001];

const ll MAX=LONG_MAX;

ll pol(ll n){
	return n*(n+1)*(n+2)/6;
}

ll dfs(ll n,bool odd){
	if(dp[n]!=MAX){
		return dp[n];
	}
	if(n==0){
		return 0;
	}
	ll ret=MAX;
	for(ll j=1,i=pol(j);i<=n;j++,i=pol(j)){
		if(odd&&(!(i&1)))continue;
		ret=min(ret,dfs(n-i,odd)+1);
	}
	return dp[n]=ret;
}

int main(){
	ll n;
	while(cin>>n,n){
		REP(i,1000001){
			dp[i]=MAX;
		}
		cout<<dfs(n,false);
		REP(i,1000001){
			dp[i]=MAX;
		}
		cout<<" "<<dfs(n,true)<<endl;
	}
	
}

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

using namespace std;

int main(){
    int n;
    vector<int>v;
    for(int i=1;(i*(i+1)*(i+2))/6 < 1e6;++i){
        v.push_back((i*(i+1)*(i+2))/6);
    }
    while(cin>>n,n){
        vector<int>dp(1e6,1e9);
        vector<int>dp1(1e6,1e9);
        dp[0]=0;
        dp1[0]=0;
        for(int i=0;i<=n;++i){
            for(int j=0;i+v[j]<1e6 && j<v.size();++j){
                dp[i+v[j]]=min(dp[i]+1,dp[i+v[j]]);
                if(v[j]%2==0)continue;
                dp1[i+v[j]]=min(dp1[i]+1,dp1[i+v[j]]);
            }
        }
        cout<<dp[n]<<" "<<dp1[n]<<endl;
    }
}

C++: #include<bits/stdc++.h>
#define dump(a) cout << #a << "=" << a << endl
using namespace std;


struct Point {
	int w;
	int h;
	int taikaku;

	bool operator<( const Point &right ) const {
		if (taikaku == right.taikaku) {
			return h < right.h;
		}
		else {
			return taikaku < right.taikaku;
		}
	}
};

vector<Point> points;

int main() {
	int H,W;

	for(int y = 0; y < 150; y++) {
		for(int x = 0; x < 150; x++) {
			int xx = x+1;
			int yy = y+1;
			//dump(xx);
			//dump(yy);
			if (xx > yy) {
				Point p;
				p.w = xx;
				p.h = yy;
				p.taikaku = xx*xx + yy*yy;
				points.push_back(p);
			}
		}
	}
	//dump(points.size());

	sort(points.begin(), points.end());
	/*
	for(int i = 0; i < points.size(); i++) {
		cout << points[i].taikaku << " ";
	}
	cout << endl;
	*/

	while(cin >> H >> W) {
		if (H == 0 && W == 0) { break; }
		Point ans_p;
		int taikaku = H*H+W*W;
		//dump(points.size());

		for(int i = 0; i < points.size(); i++)
		{
			//cout << points[i].h << " " << points[i].w << endl;
			if (points[i].w == W && points[i].h == H) {
				ans_p = points[i+1];
				break;
			}
		}
		cout << ans_p.h << " " << ans_p.w << endl;
	}

	return EXIT_SUCCESS;
}