#include using namespace std; using i64 = int_fast64_t; using ui64 = uint_fast64_t; #define REP(i, n) for (i64 (i) = 0; (i) < (n); ++(i)) #define FOR(i, a, b) for (i64 (i) = (a); (i) < (b); ++(i)) constexpr int MOD = (int)1e9 + 7; ui64 MOP(ui64 x, ui64 n, ui64 m = MOD) { ui64 r = 1; while (n > 0) { if (n & 1) (r *= x) %= m; (x *= x) %= m; n >>= 1; } return r; } int D, L, R, K; vector fact, dep; signed main() { cin >> D >> L >> R >> K; if (K > D * 2) { cout << -1 << endl; return 0; } dep.resize(D + 1); dep[0] = dep[1] = 1; REP(i, D - 1) dep[i + 2] = dep[i + 1] * 2; fact.resize(2100100); fact[0] = fact[1] = 1; REP(i, 2100108) fact[i + 2] = (fact[i + 1] * (i + 2)) % MOD; ui64 dl = 0, dr = 0; { int tmp = L; while (tmp > 0) { ++dl; tmp >>= 1; } tmp = R; while (tmp > 0) { ++dr; tmp >>= 1; } } ui64 res = 0; if (dl == dr) { if (K % 2 == 1) { cout << 0 << endl; return 0; } K >>= 1; res = dep[K]; REP(i, K) (res <<= 1) %= MOD; res *= dep[dl - K]; for (int i = 1; i <= D; ++i) { if (i == dl) { res *= fact[dep[i] - 2]; } else { res *= fact[dep[i]]; } res %= MOD; } } else { int dif = dr - dl; if (K - dif % 2 == 1) { cout << 0 << endl; return 0; } int k = (K - dif) >> 1; res = dep[k] * dep[dr]; for (int i = 1; i <= D; ++i) { if (i == dl or i == dr) { res *= fact[dep[i] - 1]; } else { res *= fact[dep[i]]; } res %= MOD; } } cout << res << endl; }