#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int MOD = 1'000'000'007;
// Thêm mod
inline void addmod(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }
inline int64 mulmod(int64 a, int64 b) { return (a * b) % MOD; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long n, x;
int k;
cin >> n >> k >> x;
// Tính phần cố định do x
__int128 Sx128 = (__int128)x * k * (k + 1) / 2;
if (Sx128 > n) {
cout << 0;
return 0;
}
long long remain = n - (long long)Sx128;
int fullSum = k * (k + 1) / 2;
// ways[s] = số subset của {1..k} có tổng s
vector<int> ways(fullSum + 1);
ways[0] = 1;
for (int i = 1; i <= k; i++) {
for (int s = fullSum; s >= i; s--)
addmod(ways[s], ways[s - i]);
}
vector<pair<int,int>> validS;
for (int s = 0; s < fullSum; s++)
if (ways[s]) validS.emplace_back(s, ways[s]);
int waysFull = ways[fullSum];
// dp[carry] = số cách tại bit hiện tại
vector<int> dp(fullSum + 1), ndp(fullSum + 1);
dp[0] = 1;
int maxBit = 0;
while ((1LL << maxBit) <= (remain + (1LL << 11))) maxBit++;
maxBit += 3;
for (int bit = 0; bit < maxBit; bit++) {
fill(ndp.begin(), ndp.end(), 0);
int bitN = (remain >> bit) & 1LL;
bool xbit = (x >> bit) & 1LL;
for (int carry = 0; carry <= fullSum; carry++) if (dp[carry]) {
int cur = dp[carry];
if (xbit) {
int S = fullSum;
int parity = (carry + S) & 1;
if (parity != bitN) continue;
int nc = (carry + S) >> 1;
if (nc <= fullSum)
ndp[nc] = (ndp[nc] + mulmod(cur, waysFull)) % MOD;
} else {
for (auto [S, w] : validS) {
int parity = (carry + S) & 1;
if (parity != bitN) continue;
int nc = (carry + S) >> 1;
if (nc <= fullSum)
ndp[nc] = (ndp[nc] + mulmod(cur, w)) % MOD;
}
}
}
dp.swap(ndp);
}
cout << dp[0] % MOD;
return 0;
}