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 <utility>
#include <cctype>
#include <vector>
#include <functional>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n'&&c!=EOF;)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

template <typename T>
using V = vector<T>;

int sum(int n, int k) {
	return (2 * n - k + 1) * k / 2;
}

int main() {
	for (int n, k, s; n = in, k = in, s = in;) {
		V<V<V<int>>> m(k, V<V<int>>(n + 1, V<int>(sum(n, k) + 1, -1)));
		function<int(int, int, int)> f = [&](int i, int j, int a){
			if (i == k)
				return (int) (a == s);
			if (m[i][j][a] >= 0)
				return m[i][j][a];
			int r {};
			for (int l = j; l <= n - k + i + 1; l++)
				r += f(i + 1, l + 1, a + l);
			return m[i][j][a] = r;
		};
		if (sum(n, k) < s)
			outl(0);
		else
			outl(f(0, 1, 0));
	}
}

C++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int dp[1200000];
      
int main(){
  memset(dp,0,sizeof(dp));
  for(int S=0;S<=(1<<20)-1;S++){
    int sum = 0;
    for(int i=0;i<20;i++){
      if(S & (1<<i)){
        sum += (i+1);
      }
    }
    dp[S] = sum;
  }
  int upper,num_of_elements,target_sum;
  while(~scanf("%d %d %d",
               &upper,
               &num_of_elements,
               &target_sum)){
    if(upper == 0 
       && num_of_elements == 0 
       && target_sum == 0) break;

    int res = 0;
    for(int S=0;S<=(1<<upper)-1;S++){
      if(__builtin_popcount(S) != num_of_elements) continue;
      if(dp[S] != target_sum) continue;
      res++;
    }
    printf("%d\n",res);
  }
}

C++: #include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

const int maxn = 22, maxk = 12, maxs = 157;
int dp[maxn][maxk][maxs];

int rec(int n, int k, int s) {
  if (k < 0) return 0;
  if (dp[n][k][s] < 0) {
	int res = 0;
	for (int i = 1; i < n; i++) {
	  res += rec(i, k-1, s-i);
	}
	dp[n][k][s] = res;
  }
  return dp[n][k][s];
}

int main() {
  fill_n(dp[0][0], maxn*maxs*maxk, -1);
  for (int n = 0; n < maxn; n++)
	dp[n][0][0] = 1;
  while (true) {
	int p, q, r;
	cin >> p >> q >> r;
	if (p == 0 && q == 0 && r == 0) break;
	cout << rec(p+1, q, r) << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
/*
n以下の数がちょうどk個であるような集合で、数値の和がsになるのは何通り？
1<=n<=20
1<=k<=10
1<=s<=155
*/
int d[200][200][200];
int dfs(int n,int k,int s){
	if(n<0||k<0||s<0)return 0;
	if(d[n][k][s]!=-1)return d[n][k][s];
	int ans=dfs(n-1,k-1,s-n)+dfs(n-1,k,s);
	return d[n][k][s]=ans;
}
int main(){
	memset(d,-1,sizeof(d));
	d[0][0][0]=1;
	for(int n,k,s;cin>>n>>k>>s,n;)cout<<dfs(n,k,s)<<endl;
}

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

int dfs(int n, int k, int s, int d){
  if(k==1){
    if(d<=s&&s<=n) return 1;
    else return 0;
  }
  int ans = 0;
  for(int i=d;i<=min(n,s);i++){
    ans += dfs(n, k-1, s-i, i+1);
  }
  return ans;
}

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