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 <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<vector<vector<int> > > VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int n_max = 20;
const int k_max = 10;
const int s_max = 155;

void make_table(VVVI &table) {
    for (int i = 1; i <= n_max; i++) {
        for (int j = 1; j <= i; j++) {
            table[i - 1][0][j - 1] = 1;
        }
    }

    for (int b = 2; b <= k_max; b++) {
        for (int a = b; a <= n_max; a++) {
            int max = ((a * (a + 1)) - ((a - b) * (a - b + 1))) / 2;
            int min = (b * (b + 1)) / 2;
            for (int c = min; c <= max; c++) {
                if (c - a >= 1) {
                    table[a - 1][b - 1][c - 1] = table[a - 2][b - 1][c - 1] + table[a - 2][b - 2][c - a - 1];
                } else {
                    table[a - 1][b - 1][c - 1] = table[a - 2][b - 1][c - 1];
                }
            }
        }
    }
}

int main(void) {
    VVVI table(n_max, vector<vector<int> >(k_max, vector<int>(s_max, 0)));
    make_table(table);
    /*
       for (int j = 0; j < k_max; j++) {
       cout << "K = " << j + 1 <<  endl;
       for (int i = 0; i < n_max; i++) {
       cout << "N = " << i + 1<<  endl;
       for (int k = 0; k < s_max; k++) {
       cout << table[i][j][k] << " ";
       }
       cout << endl;
       }
       cout << endl;
       }
     */

    while (1) {
        int n;
        int k;
        int s;
        cin >> n >> k >> s;
        if (n == 0 && k == 0 && s == 0) {
            break;
        }
        int max = ((n * (n + 1)) - ((n - k) * (n - k + 1))) / 2;
        int min = (k * (k + 1)) / 2;
        if (s > max || s < min) {
            cout << 0 << endl; 
            continue;
        } else {
            cout << table[n - 1][k - 1][s - 1] << endl;
            continue;
        }
    }
    return 0;
}

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

int solve(int n, int k, int s) {
    function<int(int, int, int)> dfs = [&](int i, int p, int t) {
        if (i == k) return int(t == 0);
        int cnt = 0;
        for (int e = p + 1, u = min(n, t); e <= u; ++e) cnt += dfs(i + 1, e, t - e);
        return cnt;
    };
    return dfs(0, 0, s);
}

int main() {
    for (int n, k, s; cin >> n >> k >> s, n | k | s;) cout << solve(n, k, s) << endl;
}

C++: #include <iostream>
#define N 20
using namespace std;
int n,k,s,C;
void Ess(int,int,int);
int main(){
  bool r;
  while(1){
    cin >> n >> k >> s;
    if(n==0&&k==0&&s==0) break;
    C=0;
    Ess(0,0,0);
    cout << C << endl;
  }
  return 0;
}
void Ess(int x,int sum,int cnt){
  if(n==x){
    if(cnt==k&&sum==s) C++;
    return ;
  }
  Ess(x+1,sum,cnt);
  Ess(x+1,sum+x+1,cnt+1);
}

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

#define int long long

int N, K, S;
int dp[21][11][156];

int dfs(int p, int k, int s) {
  if ( k == K ) {
    if ( s == S ) return 1;
    else return 0;
  }
  if ( dp[p][k][s] >= 0 ) return dp[p][k][s];

  int ret = 0;
  for ( int i = p+1; i <= N; i++ ) {
    ret += dfs(i, k+1, s+i);    
  }

  return dp[p][k][s] = ret;
}

signed main() {
  while ( cin >> N >> K >> S, N ) {
    fill_n(**dp, 21*11*156, -1);
    cout << dfs(0, 0, 0) << endl;    
  }
  return 0;
}

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

typedef long long ll;

int n, k, s;
ll cnt;
//x:ここから使える sum:これまでの合計 dep:残り深さ
void solve(int x, int sum, int dep){
  if(dep==0){
    if(s==sum)cnt++;
    return;
  }
  if(s<sum)return;
  for(int i=x; i<=n; i++){
    solve(i+1, sum+i, dep-1);
  }
}

int main(){
  while(true){
    cin>>n>>k>>s;
    if(n==0&&k==0&&s==0)break;
    cnt=0;
    solve(1, 0, k);
    cout<<cnt<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n, k, s;
    cin >> n >> k >> s;
    if (n == 0 && k == 0 && s == 0){
      break;
    }
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(k + 1, vector<int>(s + 1, 0)));
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++){
      for (int j = 0; j <= k; j++){
        for (int l = 0; l <= s; l++){
          dp[i + 1][j][l] += dp[i][j][l];
          if (l + i + 1 <= s && j < k){
            dp[i + 1][j + 1][l + i + 1] += dp[i][j][l];
          }
        }
      }
    }
    cout << dp[n][k][s] << endl;
  }
}

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

using namespace std;

int main(){
  int ans[21][11][156] = {0};
  int n, k, s;
  
  for(int i=1; i<(1<<20); i++){
    bitset<20> foo(i);
    if(foo.count() <= 10){
      int sum = 0;
      for(int j=0; j<20; j++)
	if(foo[j]==1)
	  sum+=(j+1);
      if(sum <= 155){
	int j = 19;
	while(foo[j] != 1){
	  j--;
	}
	ans[j+1][foo.count()][sum]++;
      }
    }
  }

  while(cin >> n >> k >> s && n)
    cout << ans[n][k][s] << endl;   
  
  return 0;
}