Problem:
Problem A:
Equal Sum Sets
Let us consider sets of positive integers less than or equal to
n
. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set.
Specifying the number of set elements and their sum to be
k
and
s
, respectively, sets satisfying the conditions are limited. When
n
= 9,
k
= 3 and
s
= 23, {6, 8, 9} is the only such set. There may be more than one such set, in general, however. When
n
= 9,
k
= 3 and
s
= 22, both {5, 8, 9} and {6, 7, 9} are possible.
You have to write a program that calculates the number of the sets that satisfy the given conditions.
Input
The input consists of multiple datasets. The number of datasets does not exceed 100.
Each of the datasets has three integers
n
,
k
and
s
in one line, separated by a space. You may assume 1 ≤
n
≤ 20, 1 ≤
k
≤ 10 and 1 ≤
s
≤ 155.
The end of the input is indicated by a line containing three zeros.
Output
The output for each dataset should be a line containing a single integer that gives the number of the sets that satisfy the conditions. No other characters should appear in the output.
You can assume that the number of sets does not exceed 2
31
- 1.
Sample Input
9 3 23
9 3 22
10 3 28
16 10 107
20 8 102
20 10 105
20 10 155
3 4 3
4 2 11
0 0 0
Output for the Sample Input
1
2
0
20
1542
5448
1
0
0

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

ll mod = 998244353;

ifstream in;
ofstream out;

using ld = long double;
const ld eps = 1e-9;
long double calc_inter(array<ld, 3> a, array<ld, 3> b, array<ld, 3> p, ld r) {
    ld x = b[0] - a[0], y = b[1] - a[1], z = b[2] - a[2];
    ld t = -(x * (a[0] - p[0]) + y * (a[1] - p[1]) + z * (a[2] - p[2])) /
           (x * x + y * y + z * z);

    if(t < 0 || t > 1) return false;
    x = p[0] - (a[0] + t * x);
    y = p[1] - (a[1] + t * y);
    z = p[2] - (a[2] + t * z);
    return x * x + y * y + z * z <= r * r + eps;
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if(argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    while(1) {
        ll n, k, s;
        cin >> n >> k >> s;
        if(n == 0) break;
        ll ans = 0;
        for(uint32_t i = 0; i < (1 << n); i++) {
            if(popcount(i) != k) continue;

            ll sum = 0;
            for(int j = 0; j < n; j++) {
                sum += ((i >> j) & 1) * (j + 1);
            }
            ans += sum == s;
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3456
final_rank: 8

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

int solve() {
    int n, k, s;
    std::cin >> n >> k >> s;
    if (n == 0) return 1;

    int ans = 0;
    for (int state = 0; state < (1 << n); state++) {
        int count = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if (state & (1 << i)) {
                count++;
                sum += i + 1;
            }
        }
        if (count == k && sum == s) ans++;
    }
    std::cout << ans << std::endl;
    return 0;
}

int main() {
    while (!solve());
}
accuracy: 1
time_ms: 520
memory_kb: 3120
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define ALL(v) v.begin(),v.end()

int main(void) {
	while (true) {
		int N,K,S;
		cin >> N >> K >> S;
		if (N == 0 && K == 0 && S == 0) break;

		int ans = 0;
		for (int i = 0; i < (1 << N); ++i) {
			vector<int> v;
			for (int j = 0; j < N; ++j) {
				if (i & 1 << j) {
					v.push_back(j + 1);
				}
			}
			if (v.size() != K) continue;
			int sum = accumulate(ALL(v), 0);
			if (sum == S) ++ans;
		}
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 1530
memory_kb: 3336
final_rank: 20

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

void solve(int n, int k, int s) {
  int count = 0;

  int set = (1 << k) - 1;
  while (set < (1 << n)) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (not (set & (1 << i))) continue;
      sum += i + 1;
    }

    if (sum == s) count++;

    int x = set & -set;
    int y = set + x;
    set = ((set & ~y) / x >> 1) | y;
  }

  std::cout << count << std::endl;
}

int main() {
  int n, k, s;
  
  while (std::cin >> n >> k >> s, n) {
    solve(n, k, s);
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3132
final_rank: 2

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

void solve(int n, int k, int s) {
  std::vector< int > ps(n, 1);
  for (int i = 0; i < n - k; i++) ps[i] = 0;

  int count = 0;
  do {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (not ps[i]) continue;
      sum += i + 1;
    }

    if (sum == s) count++;
  } while (std::next_permutation(ps.begin(), ps.end()));

  std::cout << count << std::endl;
}

int main() {
  int n, k, s;
  
  while (std::cin >> n >> k >> s, n) {
    solve(n, k, s);
  }
}
accuracy: 1
time_ms: 30
memory_kb: 3328
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    while(true){
        int n, k, s; cin >> n >> k >> s;
        if(n == 0) break;
        int ans = 0;
        for(int bit = 0; bit < (1 << n); bit++){
            int cnt = 0, sum = 0;
            for(int i = 0; i < n; i++){
                if((bit >> i) & 1){
                    cnt++;
                    sum += i+1;
                }
            }
            if(cnt == k && sum == s) ans++;
        }
        cout << ans << '\n';
    }
    return 0;
}
accuracy: 1
time_ms: 680
memory_kb: 3432
final_rank: 18

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

void solve(int n, int k, int s) {
     int ans = 0;

    for (int bits = 0; bits < (1 << n); bits++) {
        int cnt = 0;
        int sum = 0;

        for (int i = 0; i < n; i++) {
            if(bits & (1 << i)) {
                cnt++;
                sum += (i + 1);
            }
        }

        if(cnt == k && sum == s) ans++;
    }

    cout << ans << endl;
}

int main() {
    while(true) {
        int n, k, s;
        cin >> n >> k >> s;
        if(n == 0)break;
        solve(n,k,s);
    }
}
accuracy: 1
time_ms: 580
memory_kb: 3336
final_rank: 16

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

int ans;
void dfs(int N, int K, int S, vector<int> p) {
    if (p.size() == N + 1) {
        if (accumulate(p.begin(), p.end(), 0) == S)
            ans++;

        return;
    }

    p.emplace_back(p.back());
    while (p.back() < K) {
        p.back()++;
        dfs(N, K, S, p);
    }
}

void solve(int N, int K, int S) {
    ans = 0;
    dfs(K, N, S, vector<int>(1, 0));
    cout << ans << endl;
}

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

    int N, K, S;
    while (cin >> N >> K >> S, N && K && S)
        solve(N, K, S);

    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 3260
final_rank: 11

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

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int MAX = 20;
    int N2 = 1 << MAX;
    vector<vector<int>> g(160);
    rep(b, N2) {
        int s = 0;
        rep(i, MAX) {
            if (b >> i & 1) s += i + 1;
        }
        if (s >= 160) continue;
        g[s].push_back(b);
    }
    int N, K, S;
    while (cin >> N >> K >> S, N) {
        int ans = 0;
        int b2 = 0;
        rep(i, MAX - N) b2 += (1 << (N + i));
        for (auto &b : g[S]) {
            if (b & b2) continue;
            if (__builtin_popcount(b) != K) continue;
            ans++;
        }
        cout << ans << '\n';
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 7868
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

ll an = 0;
ll N, K, S;
void dfs(ll k, ll m, ll s) {
	//if (N * k < s)return;
	//if (m * k > s)return;
	if (k == 0 && s == 0) {
		an++;
		return;
	}
	for (ll i = m + 1; i <= min(N, s); i++) {
		dfs(k - 1, i, s - i);
	}

}


int main() {
	while (1) {
		cin >> N >> K >> S;
		if (N == 0)return 0;
		an = 0;
		dfs(K, 0, S);
		cout << an << endl;
	}


}
accuracy: 1
time_ms: 10
memory_kb: 3044
final_rank: 1

code_snippet: #include <functional>
#include <iostream>

using namespace std;

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

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

    if (n == 0 && k == 0 && s == 0) {
      break;
    }

    int ans = 0;

    function<void(int, int, int)> dfs = [&](int idx, int v, int sum) {
      if (v == n && sum < s) {
        return;
      }
      if (sum > s) {
        return;
      }

      if (idx == k - 1) {
        ans += sum == s;
        return;
      }

      for (int next_v = v + 1; next_v <= n; next_v++) {
        dfs(idx + 1, next_v, sum + next_v);
      }
    };

    for (int x = 1; x <= n; x++) {
      dfs(0, x, x);
    }

    cout << ans << "\n";
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3456
final_rank: 8

code_snippet: #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;
        int res = 0;
        for(int bits = 0; bits < 1<<(n); bits++){
            if( __builtin_popcount(bits) == k){
                int sum = 0;
                for(int i = 0; i < n; i++){
                    if(bits & 1 << i){
                        sum += (i+1);
                    }
                }
                if(sum == s) res++;
            }
        }
        cout << res << endl;
    }
}
accuracy: 1
time_ms: 40
memory_kb: 3316
final_rank: 7

code_snippet: #include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define ls x<<1
#define rs x<<1|1
#define lson x<<1,l,mid
#define rson x<<1|1,mid+1,r
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define cl(x,y) memset(x,y,sizeof(x))
#define nxtp(a,n) next_permutation(a+1,a+n+1)
#define mem(x,y,n) memset(x,y,sizeof(int)*(n+5))
const int N=1e6+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const double pi=acos(-1);
const double INF=1e18;
using namespace std;

int ans,n,k,s,a[N];
void dfs(int x,int p)
{
	int i;
	if(p==k)
	{
		int sum=0;
		for(i=1;i<=k;i++)
			sum+=a[i];
		ans+=(sum==s);
		return ;
	}
	for(i=x+1;i<=n;i++)
	{
		a[p+1]=i;
		dfs(i,p+1);
	}
}
int main()
{
#ifdef ChuTian
	clock_t stTime = clock();
    freopen("in.in","r",stdin);
    freopen("out.out","w",stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	while(cin>>n>>k>>s && n+k+s)
	{
		ans=0;
		dfs(0,0);
		cout<<ans<<endl;
	}
#ifdef ChuTian
	cerr << "Time Used:" << clock() - stTime << "ms" <<endl;
#endif
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3460
final_rank: 10

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

int main(){
  int n,k,s;
  while(cin>>n>>k>>s,n){
    vector<int> v(n);
    REP(i,n)v[i]=i<k;
    sort(ALL(v));
    int ans=0;
    do{
      int sum=0;
      REP(i,n)if(v[i])sum+=i+1;
      ans+=sum==s;
    }while(next_permutation(ALL(v)));
    cout<<ans<<endl;
  }
}
accuracy: 1
time_ms: 40
memory_kb: 3112
final_rank: 3

code_snippet: #ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
 
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
 
#pragma region Macros
// rep macro
#define foa(v, a) for(auto &v : a)
#define REPname(a, b, c, d, e, ...) e
#define REP(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int i = 0; i < (x); ++i)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define REPSname(a, b, c, ...) c
#define REPS(...) REPSname(__VA_ARGS__, REPS1, REPS0)(__VA_ARGS__)
#define REPS0(x) for(int i = 1; i <= (x); ++i)
#define REPS1(i, x) for(int i = 1; i <= (x); ++i)
#define RREPname(a, b, c, d, e, ...) e
#define RREP(...) RREPname(__VA_ARGS__, RREP3, RREP2, RREP1, RREP0)(__VA_ARGS__)
#define RREP0(x) for(int i = (x)-1; i >= 0; --i)
#define RREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define RREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define RREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))
#define RREPSname(a, b, c, ...) c
#define RREPS(...) RREPSname(__VA_ARGS__, RREPS1, RREPS0)(__VA_ARGS__)
#define RREPS0(x) for(int i = (x); i >= 1; --i)
#define RREPS1(i, x) for(int i = (x); i >= 1; --i)
 
// name macro
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
template <class T = int>
using V = std::vector<T>;
template <class T = int>
using VV = std::vector<std::vector<T>>;
template <class T = int>
using VVV = std::vector<std::vector<std::vector<T>>>;
template <class T>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
using ll = long long;
using ld = long double;
using int128 = __int128_t;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using Tp = tuple<ll,ll,ll>;
 
// input macro
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
	for(T &i : v) is >> i;
	return is;
}
std::istream &operator>>(std::istream &is, __int128_t &a) {
	std::string s;
	is >> s;
	__int128_t ret = 0;
	for(int i = 0; i < s.length(); i++)
		if('0' <= s[i] and s[i] <= '9')
			ret = 10 * ret + s[i] - '0';
	a = ret * (s[0] == '-' ? -1 : 1);
	return is;
}
namespace scanner {
void scan(int &a) { std::cin >> a; }
void scan(long long &a) { std::cin >> a; }
void scan(std::string &a) { std::cin >> a; }
void scan(char &a) { std::cin >> a; }
void scan(char a[]) { std::scanf("%s", a); }
void scan(double &a) { std::cin >> a; }
void scan(long double &a) { std::cin >> a; }
template <class T, class U>
void scan(std::pair<T, U> &p) { std::cin >> p; }
template <class T>
void scan(std::vector<T> &a) { std::cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#define VEC(type, name, size)     \
	std::vector<type> name(size); \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                                    \
	std::vector<std::vector<type>> name(h, std::vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)             \
	std::string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
 
// output-macro
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &a) {
	for(int i = 0; i < int(a.size()); ++i) {
		if(i) os << " ";
		os << a[i];
	}
	return os;
}
std::ostream &operator<<(std::ostream &dest, __int128_t &value) {
	std::ostream::sentry s(dest);
	if(s) {
		__uint128_t tmp = value < 0 ? -value : value;
		char buffer[128];
		char *d = std::end(buffer);
		do {
			--d;
			*d = "0123456789"[tmp % 10];
			tmp /= 10;
		} while(tmp != 0);
		if(value < 0) {
			--d;
			*d = '-';
		}
		int len = std::end(buffer) - d;
		if(dest.rdbuf()->sputn(d, len) != len) {
			dest.setstate(std::ios_base::badbit);
		}
	}
	return dest;
}
template <class T>
void print(const T a) { std::cout << a << '\n'; }
template <class Head, class... Tail>
void print(Head H, Tail... T) {
	std::cout << H << ' ';
	print(T...);
}
template <class T>
void printel(const T a) { std::cout << a << '\n'; }
template <class T>
void printel(const std::vector<T> &a) {
	for(const auto &v : a)
		std::cout << v << '\n';
}
template <class Head, class... Tail>
void printel(Head H, Tail... T) {
	std::cout << H << '\n';
	printel(T...);
}
void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); }
void No() { std::cout << "No\n"; }
void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); }
void NO() { std::cout << "No\n"; }
void err(const bool b = true) {
	if(b) {
		std::cout << "-1\n", exit(0);
	}
}
 
//debug macro
namespace debugger {
template <class T>
void view(const std::vector<T> &a) {
	std::cerr << "{ ";
	for(const auto &v : a) {
		std::cerr << v << ", ";
	}
	std::cerr << "\b\b }";
}
template <class T>
void view(const std::vector<std::vector<T>> &a) {
	std::cerr << "{\n";
	for(const auto &v : a) {
		std::cerr << "\t";
		view(v);
		std::cerr << "\n";
	}
	std::cerr << "}";
}
template <class T, class U>
void view(const std::vector<std::pair<T, U>> &a) {
	std::cerr << "{\n";
	for(const auto &p : a) std::cerr << "\t(" << p.first << ", " << p.second << ")\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &p : m) std::cerr << "\t[" << p.first << "] : " << p.second << "\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::pair<T, U> &p) { std::cerr << "(" << p.first << ", " << p.second << ")"; }
template <class T>
void view(const std::set<T> &s) {
	std::cerr << "{ ";
	for(auto &v : s) {
		view(v);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}
 
template <class T>
void view(const T &e) { std::cerr << e; }
}  // namespace debugger
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	debugger::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(false)
#else
#define debug(...) (void(0))
#endif
 
// vector macro
template <class T>
int lb(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x))); }
template <class T>
int ub(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x))); }
template <class T>
void UNIQUE(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<T> press(std::vector<T> &a) {
	auto res = a;
	UNIQUE(res);
	for(auto &v : a)
		v = lb(res, v);
	return res;
}
#define SORTname(a, b, c, ...) c
#define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__)
#define SORT0(a) std::sort((a).begin(), (a).end())
#define SORT1(a, c) std::sort((a).begin(), (a).end(), [](const auto x, const auto y) { return x c y; })
template <class T>
void ADD(std::vector<T> &a, const T x) {
	for(auto &v : a) v += x;
}
template <class T>
void SUB(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v -= x;
}
template <class T>
void MUL(std::vector<T> &a, const T x) {
	for(auto &v : a) v *= x;
}
template <class T>
void DIV(std::vector<T> &a, const T x) {
	for(auto &v : a) v /= x;
}
 
// math macro
template <class T, class U>
inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <class T, class U>
inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <class T>
T divup(T x, T y) { return (x + y - 1) / y; }
template <class T>
T POW(T a, long long n) {
	T ret = 1;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}

template<typename T>
T ADD(T a, T b){
	T res;
	return __builtin_add_overflow(a, b, &res) ? numeric_limits<T>::max() : res;
}

template<typename T>
T MUL(T a, T b){
	T res;
	return __builtin_mul_overflow(a, b, &res) ? numeric_limits<T>::max() : res;
}

// modpow
long long POW(long long a, long long n, const int mod) {
	long long ret = 1;
	while(n) {
		if(n & 1) (ret *= a) %= mod;
		(a *= a) %= mod;
		n >>= 1;
	}
	return ret;
}
 
// others
struct fast_io {
	fast_io() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} fast_io_;

#pragma endregion

using R = long double;
constexpr R EPS=1E-11;

// r の(誤差付きの)符号に従って, -1, 0, 1 を返す.
int sgn(const R& r){ return (r > EPS) - (r < -EPS); }
// a, b の(誤差付きの)大小比較の結果に従って, -1, 0, 1 を返す.
int sgn(const R& a, const R &b){ return sgn(a-b); }
// a > 0 は sgn(a) > 0
// a < b は sgn(a, b) < 0
// a >= b は sgn(a, b) >= 0
// のように書く.
// return s * 10^n

//https://atcoder.jp/contests/abc191/submissions/20028529
long long x10(const string& s, size_t n) {
    if (s.front() == '-') return -x10(s.substr(1), n);
    auto pos = s.find('.');
    if (pos == string::npos) return stoll(s + string(n, '0'));
    return stoll(s.substr(0, pos) + s.substr(pos + 1) + string(n + pos + 1 - s.size(), '0'));
}
 
long long ceildiv(long long a, long long b) {
    if (b < 0) a = -a, b = -b;
    if (a >= 0) return (a + b - 1) / b;
    else return a / b;
}
 
long long floordiv(long long a, long long b) {
    if (b < 0) a = -a, b = -b;
    if (a >= 0) return a / b;
    else return (a - b + 1) / b;
}
 
long long floorsqrt(long long x) {
    assert(x >= 0);
    long long ok = 0;
    long long ng = 1;
    while (ng * ng <= x) ng <<= 1;
    while (ng - ok > 1) {
        long long mid = (ng + ok) >> 1;
        if (mid * mid <= x) ok = mid;
        else ng = mid;
    }
    return ok;
}

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}

const int inf = 1e9;
const ll INF = 1e18;

void main_() {
    ll n,k,s;
    cin >> n >> k >> s;
    VVV<ll> dp(11,VV<ll>(160,V<ll>(160)));
    
    while(n!=0){
        REP(i,11)REP(j,160)REP(K,160) dp[i][j][K] = 0;
        dp[0][0][0] = 1;
        REP(i,k){
            REP(j,160)REP(a,s+1){
                for(ll b = j+1;b <= n;b++){
                    if(a + b > s)break;
                    dp[i+1][b][a + b] += dp[i][j][a];
                }
            }
        }
        ll ans = 0;
        
        REP(i,160){
            ans += dp[k][i][s];
        }
        cout << ans << endl;
        cin >> n >> k >> s;
    }
}
 
int main() {
	int t = 1;
	//cin >> t;
	while(t--) main_();
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5544
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define miele(v) min_element(v.begin(), v.end())
#define maele(v) max_element(v.begin(), v.end())
#define SUM(v) accumulate(v.begin(), v.end(), 0LL)
#define lb(a, key) lower_bound(a.begin(),a.end(),key)
#define ub(a, key) upper_bound(a.begin(),a.end(),key)
#define COUNT(a, key) count(a.begin(), a.end(), key) 
#define BITCOUNT(x) __builtin_popcount(x)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using P = pair <int,int>;
using WeightedGraph = vector<vector <P>>;
using UnWeightedGraph = vector<vector<int>>;
using Real = long double;
using Point = complex<Real>; //Point and Vector2d is the same!
using Vector2d = complex<Real>;
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double EPS = 1e-15;
const double PI=3.14159265358979323846;
template <typename T> 
int getIndexOfLowerBound(vector <T> &v, T x){
    return lower_bound(v.begin(),v.end(),x)-v.begin();
}
template <typename T> 
int getIndexOfUpperBound(vector <T> &v, T x){
    return upper_bound(v.begin(),v.end(),x)-v.begin();
}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define DUMPOUT cerr
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
istream &operator>>(istream &is, Point &p) {
    Real a, b; is >> a >> b; p = Point(a, b); return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T,U> &p_var) {
    is >> p_var.first >> p_var.second;
    return is;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    DUMPOUT<<'{';
    os << pair_var.first;
    DUMPOUT<<',';
    os << " "<< pair_var.second;
    DUMPOUT<<'}';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    DUMPOUT<<'[';
    for (int i = 0; i < vec.size(); i++) 
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    DUMPOUT<<']';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<vector<T>> &df) {
  for (auto& vec : df) os<<vec;
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    DUMPOUT << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) DUMPOUT << ", ";
        itr--;
    }
    DUMPOUT << "}";
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    DUMPOUT << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) DUMPOUT << ", ";
        itr--;
    }
    DUMPOUT << "}";
    return os;
}
void print() {cout << endl;}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
void dump_func() {DUMPOUT << '#'<<endl;}
template <typename Head, typename... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) DUMPOUT << ", ";
    dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int t = 0;
    while(1) {
        int n, k, s; cin>>n>>k>>s;
        if(n == 0) exit(0);
       
        int ans = 0;
        int bit;
        for(bit=0;bit<(1<<n);bit++){
            int cnt = 0;
            int sum = 0;
            for(int i=0;i<n;i++){
                if(bit&(1<<i)){
                    cnt++;
                    sum += i+1;
                }
            }
            if(cnt == k && sum == s) {
                ans++;
            }
        }
    
        print(ans);
    }
}
accuracy: 1
time_ms: 560
memory_kb: 3344
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

    while(1){
        ll n,k,s; cin >> n >> k >> s;
        if(n == 0) break;
        int ans = 0;
        rep(i,1<<n){
            if(__builtin_popcount(i) != k) continue;
            ll cur = 0;
            rep(j,n) if(i & (1 << j)) cur += j + 1;
            if(cur == s) ans++;
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3056
final_rank: 4

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

int main()
{
    int n,k,s;
    while(cin>>n>>k>>s,n){
        int ans=0;
        for(int i=0;i<(1<<n);++i){
            int m=0,c=0;
            for(int j=0;j<n;++j){
                if(i&(1<<j)){
                    m+=j+1;
                    c++;
                }
            }
            if(c==k && m==s)ans++;
        }
        cout<<ans<<endl;
    }
}
accuracy: 1
time_ms: 560
memory_kb: 3116
final_rank: 14

code_snippet: #include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int func(int n,int k,int s){
    method(func,int,int place,int sum,int used){
        if(used > k)return 0;
        if(sum > s)return 0;
        if(place == n+1){
            return sum == s and k == used;
        }
        int res = 0;
        res += func(place+1,sum+place,used+1);
        res += func(place+1,sum,used);
        return res;
    };
    return func(1,0,0);
}

int main(){
    while(true){
        int n = in();
        int k = in();
        int s = in();
        if(n==0)break;
        cout << func(n,k,s) << endl;
    }

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3240
final_rank: 5

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

using ll = long long;
#define var auto

using namespace std;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){ if (a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){ if (a < b) a = b; }

int main(){
  int n, k, s;
  cin >> n >> k >> s;
  if (n == 0) return 0;
  int res = 0;
  for (int i = 0; i < (1 << n); i++){
    int sum = 0;
    int count = 0;
    for (int j = 0; j < n; j++){
      if (!(i >> j & 1)) continue;
      sum += (j + 1);
      count++;
    }
    if (sum == s && count == k) res++;
  }
  cout << res << endl;
  main();
}
accuracy: 1
time_ms: 570
memory_kb: 3040
final_rank: 13