#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int64 MOD = 1000000007LL;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long n;
int k;
long long x;
if(!(cin >> n >> k >> x)) return 0;
// Sum of indices
int T = k * (k + 1) / 2;
// cnt[s] = number of subsets of {1..k} with sum s (mod MOD)
vector<int64> cnt(T + 1, 0);
cnt[0] = 1;
for(int i = 1; i <= k; ++i){
for(int s = T; s >= i; --s){
cnt[s] += cnt[s - i];
if(cnt[s] >= MOD) cnt[s] -= MOD;
}
}
// Build options for x_b == 0: pairs (S, multiplicity)
vector<pair<int,int64>> opts_zero;
opts_zero.reserve(T + 1);
for(int s = 0; s <= T; ++s){
int64 m = cnt[s];
if(s == T){
m = (m - 1) % MOD; // exclude the "all-ones" vector
if(m < 0) m += MOD;
}
if(m != 0) opts_zero.emplace_back(s, m);
}
// option for x_b == 1: only S = T with multiplicity 1
pair<int,int64> opt_one = {T, 1};
// Determine number of bits B to process
// bits(n) + enough extra bits to carry all S-values (max S ~ T requires ~log2(T) extra bits)
int bits_n = (n == 0 ? 1 : 64 - __builtin_clzll((unsigned long long)n));
int extra = 0;
while((1LL << extra) <= T) ++extra; // need ceil(log2(T+1))
int B = bits_n + extra + 2; // +2 safety
if(B < 1) B = 1;
if(B > 200) B = 200; // safety cap
// get bits arrays for n and x
vector<int> nb(B, 0), xb(B, 0);
{
long long tmp = n;
for(int i = 0; i < B; ++i){
nb[i] = (tmp & 1LL) ? 1 : 0;
tmp >>= 1;
}
}
{
long long tmp = x;
for(int i = 0; i < B; ++i){
xb[i] = (tmp & 1LL) ? 1 : 0;
tmp >>= 1;
}
}
// DP arrays: two layers for current bit: curr_tight0[c], curr_tight1[c] where c=carry (0..T)
vector<int64> curr0(T+1, 0), curr1(T+1, 0);
vector<int64> next0(T+1, 0), next1(T+1, 0);
curr1[0] = 1; // at bit 0, carry 0, tight = 1 (so far equal to n)
for(int b = 0; b < B; ++b){
fill(next0.begin(), next0.end(), 0);
fill(next1.begin(), next1.end(), 0);
// choose options based on xb[b]
const vector<pair<int,int64>> *opts_ptr = nullptr;
vector<pair<int,int64>> single_opt;
if(xb[b] == 0){
opts_ptr = &opts_zero;
} else {
single_opt.clear();
single_opt.push_back(opt_one);
opts_ptr = &single_opt;
}
const auto &opts = *opts_ptr;
// transitions from tight == 0 (already < n), no restriction on bit
for(int carry = 0; carry <= T; ++carry){
int64 ways = curr0[carry];
if(ways == 0) continue;
for(const auto &pr : opts){
int S = pr.first;
int64 mult = pr.second;
int total = carry + S;
int bit = total & 1;
int carry2 = total >> 1;
if(carry2 > T) continue; // safety, shouldn't happen
int64 add = ( (__int128)ways * mult ) % MOD;
next0[carry2] += add;
if(next0[carry2] >= MOD) next0[carry2] -= MOD;
}
}
// transitions from tight == 1 (must obey nb[b])
for(int carry = 0; carry <= T; ++carry){
int64 ways = curr1[carry];
if(ways == 0) continue;
for(const auto &pr : opts){
int S = pr.first;
int64 mult = pr.second;
int total = carry + S;
int bit = total & 1;
if(bit > nb[b]) continue; // would exceed n at this bit
int carry2 = total >> 1;
if(carry2 > T) continue; // safety
int next_tight = (bit == nb[b]) ? 1 : 0;
int64 add = ( (__int128)ways * mult ) % MOD;
if(next_tight){
next1[carry2] += add;
if(next1[carry2] >= MOD) next1[carry2] -= MOD;
} else {
next0[carry2] += add;
if(next0[carry2] >= MOD) next0[carry2] -= MOD;
}
}
}
curr0.swap(next0);
curr1.swap(next1);
}
// After processing B bits, accept states where carry == 0 (no leftover) and tight can be 0 or 1
int64 ans = (curr0[0] + curr1[0]) % MOD;
cout << ans << "\n";
return 0;
}