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;
int main(int argc, char *argv[])
{
  for(;;) {
    int n, k, s;
    cin >> n >> k >> s;
    if(n == 0 && k == 0 && s == 0) break;
    int cnt = 0;
    for(int i = 0; i < 1<<n; i++) {
      int c = 0, ss = 0;
	  while(i != 0) {
		int x = i & -i;
		i ^= x;
		ss += __builtin_ffs(x);
		c++;
	  }
      if(c == k && s == ss) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;
int ans = 0;
int n, k, s;

void DFS(int num, int use, int sum)
{
	if (use > k || num > n + 1)
	{
		return;
	}
	if (use == k)
	{
		if (sum == s)
		{
			++ans;
		}
		return;
	}
	DFS(num + 1, use + 1, sum + num);
	DFS(num + 1, use, sum);
}

void solve()
{
	while (cin >> n >> k >> s, n || k || s)
	{
		ans = 0;
		DFS(1, 0, 0);
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
// #include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dfs(int k, int n, int pn, int d){
  if (d == 0) {
    // if(k == 0) {
    //   for(auto aa:a) LOG("%2d ", aa);
    //   LOG("\n");
    // }
    return (k == 0) & 1;
  }
  int res = 0;
  FOR(i, pn + 1, n + 1){
    int nk = k - i;
    if(nk < 0) continue;
    res += dfs(nk, n, i, d - 1);
  }
  return res;
}

int main() {
  int n, s, k;
  while(cin >> n >> s >> k, n | s | k) {

    cout << dfs(k, n, 0, s) << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ans;
void solve(int n,int k,int s){
	if(s<0||k<0||n<0) return;
	if(k==0&&s==0){
		ans++;
		return;
	}
	solve(n-1,k-1,s-n);
	solve(n-1,k,s);
}
int main(){
	int n,k,s;
	while(1){
		cin >> n >> k >> s;
		if(n==0&&k==0&&s==0) break;
		ans = 0;
		solve(n,k,s);
		cout << ans << endl;
	}
}

C++: //Name: Equal Sum Sets
//Level: 2
//Category: 数論,分割数,探索,メモ化,Memoize
//Note:

/**
 * 「n以下の数をk個使ってsを作る場合の数」を返す関数を考えると、状態数は NKS 個で抑えられる。
 * したがって、メモ化再帰の形で書き下せばよい。
 *
 * オーダーは O(N^2KS)。
 */
#include <iostream>
#include <array>

using namespace std;

int memo[21][11][156];
int dfs(int n, int k, int s) {
    if(s < 0) return 0;
    if(k == 0 && s == 0) return 1;
    if(n == 0) return 0;
    if(memo[n][k][s] != -1) return memo[n][k][s];
    memo[n][k][s] = 0;
    for(int i = n; i >= 1; --i) {
        memo[n][k][s] += dfs(i-1, k-1, s-i);
    }
    return memo[n][k][s];
}

bool solve() {
    int N, K, S;
    if(!(cin >> N >> K >> S)) return false;
    if(!N && !K && !S) return false;

    cout << dfs(N, K, S) << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    for (int n = 0; n < 21; n++) {
        for (int k = 0; k < 11; k++) {
            for (int s = 0; s < 156; s++) {
                memo[n][k][s] = -1;
            }
        }
    }
    while(solve()) ;
    return 0;
}

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

long long n, k, s;
long long ans = 0;

void dfs (long long cnt, long long min, long long left, vector<long long> st){
	//cout<<"cnt: "<<cnt<<", st.size(): "<<st.size()<<endl;
	
	if (cnt > k || left < 0) {
		return;
	}
	if (left == 0 && cnt == k) {
		/*
	    for(auto itr = st.begin(); itr != st.end();) {
	        cout<<(*itr)<<", ";
	        itr++;
	    }
	    cout<<endl;
	    */
		
		ans++;
		return;
	}
	for(long long i=min; i<=n; i++){
		st.push_back(i);
		dfs(cnt+1, i+1, left-i, st);
		st.pop_back();
	}
	
	return;
}

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

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

int main(void) {

    int n, k, s;
    while (cin >> n >> k >> s, n&&k&&s) {
        int ans = 0;
        for (unsigned int bit = 0; bit < (1<<n); ++bit) {
            if (__builtin_popcount(bit) != k) continue;

            int sum = 0;
            for (int i = 0; i < n; i++) {
                if (1<<i & bit) {
                    sum += (i+1);
                }
            }
            if (sum == s) ans++;
        }

        cout << ans << endl;
    }

    return 0;
}