#include using namespace std; using lint = long long int; using pint = pair; using plint = pair; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template void ndarray(vector &vec, int len) { vec.resize(len); } template void ndarray(vector &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); } template bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; } template bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; } template pair operator+(const pair &l, const pair &r) { return make_pair(l.first + r.first, l.second + r.second); } template pair operator-(const pair &l, const pair &r) { return make_pair(l.first - r.first, l.second - r.second); } template istream &operator>>(istream &is, vector &vec){ for (auto &v : vec) is >> v; return is; } ///// This part below is only for debug, not used ///// template ostream &operator<<(ostream &os, const vector &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template ostream &operator<<(ostream &os, const deque &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template ostream &operator<<(ostream &os, const set &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_set &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const multiset &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_multiset &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const pair &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; } template ostream &operator<<(ostream &os, const map &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_map &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; ///// END ///// /* #include #include #include using namespace __gnu_pbds; // find_by_order(), order_of_key() template using pbds_set = tree, rb_tree_tag, tree_order_statistics_node_update>; template using pbds_map = tree, rb_tree_tag, tree_order_statistics_node_update>; */ constexpr lint MOD = 1000000007; vector fac, facInv, inv; // Solve ax+by=gcd(a, b) lint extgcd(lint a, lint b, lint &x, lint &y) { lint d = a; if (b != 0) d = extgcd(b, a % b, y, x), y -= (a / b) * x; else x = 1, y = 0; return d; } // Calc a^(-1) (MOD m) lint mod_inverse(lint a, lint m=MOD) { if (a == 0) exit(8); lint x, y; extgcd(a, m, x, y); return (m + x % m) % m; } void facInit(int nmax) { fac = facInv = inv = vector(nmax + 1, 1); for (int i = 2; i <= nmax; i++) { fac[i] = fac[i-1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD; facInv[i] = facInv[i-1] * inv[i] % MOD; } } int dd(int x) { return 32 - __builtin_clz(x); } void ZERO() { puts("0"); exit(0); } int main() { facInit(1 << 22); int D, L, R, K; cin >> D >> L >> R >> K; int dl = dd(L), dr = dd(R); int k = K - (dr - dl); if (k % 2 or k < 0) { ZERO(); } k /= 2; int r = dl - k; if (r <= 0) ZERO(); dbg(dl); dbg(dr); dbg(r); lint ret = 1; REP(i, D) ret = ret * fac[1 << i] % MOD; dbg(ret); if (dl == r) { ret = ret * mod_inverse(1 << (r - 1)) % MOD; } else if (dl == dr) { ret = ret * mod_inverse((1 << (dr - 1)) - 1) % MOD * ((1 << (dr - r - 1))) % MOD; } else { ret = ret * mod_inverse(1 << r) % MOD; } cout << ret % MOD << endl; }