Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		N, K, S := io.NextInt(), io.NextInt(), io.NextInt()
		if N == 0 {
			break
		}
		dp := [21][11][156]int{}
		for i := 0; i <= N; i++ {
			dp[i][0][0] = 1
		}
		for i := 1; i <= N; i++ {
			for j := 1; j <= K; j++ {
				for k := 1; k <= S; k++ {
					if k-i >= 0 {
						dp[i][j][k] += dp[i-1][j-1][k-i]
					}
					dp[i][j][k] += dp[i-1][j][k]
				}
			}
		}
		io.Println(dp[N][K][S])
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

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

// DP (simple rec + memo) version
int dp[21][11][156];
void init(){
  // not yet computed
  for(int i = 0; i < 21; i++) {
    for(int j = 0; j < 11; j++) {
      for(int k = 0; k < 156; k++) {
        dp[i][j][k] = -1;
      }
    }
  }
}
int rec(int n, int k, int s)
{
  if(s < 0) return 0;  // no answer
  if(k > n) return 0;  // less elements remain
  if(k == 0) return s == 0 ? 1 : 0; // 0 by 0?
  if(dp[n][k][s] < 0) {
    // using n, or not using n
    dp[n][k][s] = rec(n-1, k-1, s-n) + rec(n-1, k, s);
  }
  return dp[n][k][s];
}
int main(int argc, char *argv[])
{
  init();
  for(;;) {
    int n, k, s;
    cin >> n >> k >> s;
    if(n == 0 && k == 0 && s == 0) break;
    int cnt = 0;
    if(k <= n) {
      cnt = rec(n, k, s);
    }
    cout << cnt << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long int ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back

int n,k,s;
ll ans;

//9 3 23
void dfs(int sum,int floor,int bef){
    if(floor==k-1){
        if(0<s-sum && bef<s-sum && s-sum<=n){ans++;}
        return ;
    }
    for(int i=bef+1;i<=n;i++){
        dfs(sum+i,floor+1,i);
    }
}


int main(){
    
    while(cin>>n>>k>>s){
        ans=0;
        if(n==0 && k==0 && s==0)break;
        dfs(0,0,0);
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;

int main(){
    int n,s,k;
    while(cin>>n>>k>>s && n){
        int ans=0;
        for(int mask=0;mask<(1<<n);mask++){
            int c=0;
            for(int i=0;i<n;i++)c+=(mask>>i&1);
            if(c!=k) continue;
            int ts=0;
            for(int i=0;i<n;i++)ts+=(mask>>i&1)*(i+1);
            if(ts==s)ans++;
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,k,s;
	long a;
	while(cin>>n>>k>>s){
		if(n==0&&k==0&&s==0) break;
		int h[k],t=0;
		h[0]=0;
		for(int i=0;i<k-1;i++){
			h[k-1-i]=n-i;
			t=t+n-i;
		}
		int ct=0;
		do{
			if(s-t<h[1]&&s-t>0){
				ct++;
			}
			for(int i=0;i<k-1;i++){
				if(h[i+1]-h[i]>1){
					h[i+1]--;
					break;
				}
				else if(h[i+1]-h[i]==1&&h[i+2]-h[i+1]>1){
					h[i+2]--;
					for(int j=0;j<i+1;j++){
						h[i+1-j]=h[i+2-j]-1;
					}
					break;
				}
			}
			t=0;
			for(int i=0;i<k-1;i++){
				t=t+h[i+1];
			}
		} while(t>(k-1)*k/2);
		cout<<ct<<endl;
	}
    return 0;
}

C++: // implement 4min
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int memo[22][22][160];
int calc(int n, int m, int s) {
  if (n < 0 || m < 0 || s < 0) { return 0; }
  if (m == 0 && s == 0) { return 1; }
  int &ret = memo[n][m][s];
  if (ret != -1) { return ret; }
  ret = 0;
  ret += calc(n - 1, m, s);
  ret += calc(n - 1, m - 1, s - n);
  return ret;
}

int n, m, s;
int main() {
  MEMSET(memo, -1);
  while (scanf("%d %d %d", &n, &m, &s) > 0 && n) {
    int ans = calc(n, m, s);
    printf("%d\n", ans);
  }
}

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

using namespace std;

#define rep(i,n) for(int i=0;(i)<(n);++i)






int solve(int n,int k,int s){
    if(k==0){
        // cerr << "  "<<n<<" "<<k<<" "<<s<<endl;
        if(s==0)return 1;
        return 0;
    }

    // if(k==1){
    //      cerr << "  "<<n<<" "<<k<<" "<<s<<endl;
    //     if(n>=s)return 1;
    //     return 0;
    // }

    int r=0;
    for(int i=n;i>0;i--){
        if(s-i<0)continue;
        r += solve(i-1,k-1,s-i);
    }
    // cerr << "  "<<n<<" "<<k<<" "<<s<< " = "<<r<<endl;
    return r;
}


int main(){

    for(;;){
        int n,k,s;

        cin >> n >> k >> s;
        if((n|k|s)==0)return 0;

        cout << solve(n,k,s) << endl;
    }
}

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

using namespace std;

int main() {
  int n, k, s;
  while (true) {
    cin >> n >> k >> s;
    if (n == 0) break;

    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++) {
      if (__builtin_popcount(bit) != k) {
        continue;
      }
      int res = 0;
      for (int i = 1; i <= n; i++) {
        if (bit & 1 << (i - 1)) {
          res += i;
        }
      }
      if (res == s) {
        ans++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;int x[100][1000][150],a,b,c,i,j,k,l,sum;
int main(){
	while(true){
		sum=0;
		memset(x,0,sizeof(x));
		cin>>a>>b>>c;if(a==0){break;}
		x[0][0][0]=1;
		for(i=1;i<=b;i++){
			for(j=0;j<=c;j++){
				for(l=0;l<a;l++){
					for(k=l+1;k<=a;k++){
						x[i][j+k][k]+=x[i-1][j][l];
					}
				}
			}
		}
		for(i=0;i<=a;i++){sum+=x[b][c][i];}
		cout<<sum<<endl;
	}
}