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 <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll dp[11][156][22];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	while (kkt) {
		int n, K, s; scanf("%d %d %d", &n, &K, &s); if (n == 0 && K == 0 && s == 0) break;
		for (int i = 0; i <= 10; i++)for (int j = 0; j <= 155; j++) for (int k = 0; k <= 21; k++) dp[i][j][k] = 0;
		dp[0][0][n + 1] = 1;
		for (int i = 0; i < K; i++) {
			for (int j = 0; j <= 155; j++) {
				for (int k = 1; k <= n + 1; k++) {
					if (dp[i][j][k] == 0) continue;
					if (k == n + 1 && i != 0) continue;
					for (int l = 1; l < k; l++) {
						if (j + l <= 155) {
							dp[i + 1][j + l][l] += dp[i][j][k];
						}
					}
				}
			}
		}
		ll res = 0;
		for (int i = 0; i <= n; i++) res += dp[K][s][i];
		cout << res << "\n";
	}
	return 0;

}

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

// DP (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 == 0) return s == 0 ? 1 : 0; // 0 by 0?
  if(dp[n][k][s] >= 0) return dp[n][k][s];
  int cnt = 0;
  if(n > k) {
    // using n, or not using n
    cnt = rec(n-1, k-1, s-n) + rec(n-1, k, s);
  } else if(n == k) {
    if( s == n * (n+1) / 2 ) cnt = 1;
  }
  dp[n][k][s] = cnt;
  return cnt;
}
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 <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  int nks[32][16][256];
  REP(i,32) REP(j,16) REP(k,256) nks[i][j][k]=0;
  REP(i,32) nks[i][0][0]=1;
  REP(n,32) FOR(i,1,n+1){
    for(int j=9;j>=0;--j)
      REP(k,160)
	nks[n][j+1][k+i]+=nks[n][j][k];
  }
  for(;;){
    int n,k,s;
    cin >> n >> k >> s;
    if(!n&&!k&&!s) return 0;
    cout << nks[n][k][s] << endl;
  }
}

C++: #include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e8;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, k, s;
  while (cin >> n >> k >> s) {
    if (n == 0 && k == 0 && s == 0) break;
    int ans = 0;
    loop(i, 1, (1 << n)) {
      int sum = 0, bit = 0;
      loop(j, 1, n + 1) {
        if (i & (1 << (j - 1))) {
          bit++;
          sum += j;
        }
      }
      if (bit != k) continue;
      if (sum == s) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long



signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,k,s;
  while(1){
    cin>>n>>k>>s;
    if(n==0 && k==0 && s==0) break;
    int dp[25][25][160]={0};
    dp[0][0][0]=1;
    repi(i,1,n+1){
      rep(j,k+1){
	rep(l,s+1){
	  if(l-i >= 0 && j!=0) dp[i][j][l]+=dp[i-1][j-1][l-i];
	  dp[i][j][l]+=dp[i-1][j][l];
	}
      }
    }
    cout<<dp[n][k][s]<<endl;
  }
      
    

  return 0;
}

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

using namespace std;

int main(){
    int n,k,s;
    while(cin >> n >> k >> s, n){
        vector<int> v(n);
        for(int i = 0 ; i < n ; i++){
            v[i] = i+1;
        }
        int cnt = 0;
        for(int i = 0 ; i < (1<<n) ; i++){
            int sum = 0;
            if(__builtin_popcount(i) != k) continue;
            for(int j = 0 ; j < n ; j++){
                if(i >> j & 1){
                    sum += v[j];
                }
            }
            if(sum == s) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}