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>
using namespace std;

long dp[25][200][30]; //dp[何個目まで足したか][残ってる数]
int n, k;

long rec(int a, int b, int c){ //a番目,残りb,前に足した数c
	if(dp[a][b][c]>=0) return dp[a][b][c];
	
	long ret=0;
	if(a==k && b>=0){
		if(b==0) ret=1;
		else ret=0;	
	}
	else if(b<0) ret=0;
	else{
		for(int i=c-1; i>0; --i) ret+=rec(a+1, b-i, i);
		//printf("%d %d = %ld\n", a, b, ret);
	}
	//printf("ret dp[%d][%d] = %ld\n", a, b, ret);
	return dp[a][b][c]=ret;
}

int main(){
	while(1){
		int s;
		scanf(" %d %d %d", &n, &k, &s);
		if(n==0) break;	
		
		memset(dp, -1, sizeof(dp));
		printf("%ld\n", rec(0, s, n+1) );
	}
	return 0;
}

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

int main(){
    int n,k,s,i,c,res;
    while(1){
        scanf("%d",&n);
        scanf("%d",&k);
        scanf("%d",&s);
        if(!n && !k && !s){break;}
        vector<int> t(n,0);
        vector<int> cd(n);
        iota(cd.begin(),cd.end(),1);
        for(i=0;i<k;i++){t[n-i-1]=1;}    
        res=0;
        do{
            c=0;
            for(i=0;i<n;i++){c+=(t[i]*cd[i]);}
            if(c==s){res++;}
        } while(next_permutation(t.begin(),t.end()));
        printf("%d\n",res);
    }
    return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, k, s;
  while (cin >> n >> k >> s, n) {
    int c = 0;
    rep(i, 1 << n) {
      if (bitset<32>(i).count() != k) continue;
      int x = 0;
      rep(j, n) if (i >> j & 1) x += j + 1;
      c += x == s;
    }
    cout << c << endl;
  }
}

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


int dp[30][20][300];


int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
  dp[0][0][0] = 1;
  for (int i = 0; i < 20; ++i) {
    for (int j = 0; j <= 10; ++j) {
      for (int k = 0; k < 159; ++k) {
        dp[i + 1][j][k] += dp[i][j][k];
        dp[i + 1][j + 1][k + (i + 1)] += dp[i][j][k];
      }
    }
  }
  int n, k, s; 
  while (cin >> n >> k >> s and n) {
    cout << dp[n][k][s] << '\n';
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
 
using namespace std;

int main()
{

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

		long long res=0;
		for(long long bit=0;bit<(1<<n);bit++){
			int sum=0,cnt=0;
			for(int i=0;i<n;i++){
				if(bit&(1<<i)){
					sum+=i+1;
					cnt++;
				}
			}
			if(cnt==k && s==sum) res++;
		}

		cout<<res<<endl;

	}

	return 0;
}

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

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

using namespace std;

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

  int n,k,s;
  while(true){
      cin>>n>>k>>s;
      if(n==0) break;
      int res=0;
      for(int i=0;i<(1<<n);i++){
          int tmp=i;
          int sum=0,cnt=0;
          for(int j=0;j<n;j++){
              if(tmp%2){
                  cnt++;
                  sum+=(j+1);
              }
               tmp/=2;
          }
          if(cnt==k && sum==s) res++;
      }
      cout<<res<<endl;
  }
}

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

int dfs(int n, int k, int s, int now) {
  if (s < 0) return 0;
  if (s == 0) {
    if (k == 0) return 1;
    return 0;
  }
  if (now == n + 1) {
    if (s == 0) return 1;
    return 0;
  }
  return dfs(n, k - 1, s - now, now + 1) + dfs(n, k, s, now + 1);
}

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

    int count = dfs(n, k, s, 1);
    cout << count << endl;
  }
}