#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:512000000 )   using namespace std;   void solve(bool);   void precalc();   clock_t start;   int main() {     start = clock();     int t = 1;     cout.sync_with_stdio(0);     cin.tie(0);     precalc();     cout.precision(10);     cout << fixed;     int testNum = 1;     while (t--) {       solve(true);     }     cout.flush();     return 0;   }   template <typename T>   T binpow(T q, T w, T mod) {     if (!w) return 1 % mod;     if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;     return binpow(q * 1LL * q % mod, w / 2, mod);   }   template <typename T>   T gcd(T q, T w) {     while (w) {       q %= w;       swap(q, w);     }     return q;   }   template <typename T>   T lcm(T q, T w) {     return q / gcd(q, w) * w;   }   template <typename T>   void make_unique(vector<T>& a) {     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());   }   template <typename T>   void relax_min(T& cur, T val) {     cur = min(cur, val);   }   template <typename T>   void relax_max(T& cur, T val) {     cur = max(cur, val);   }   void precalc() {}   const long long C = 100500;   long long mod;   long long phi;   long long rem[C];   long long rev_rem[C];   vector<long long> primes, degs;   long long n;   long long get_deg(long long n, long long p) {     long long res = 0;     while (n) {       res += n / p;       n /= p;     }     return res;   }   long long getC(long long n, long long k) {     if (n < k) {       return 0;     }     long long res = rem[n] * rev_rem[k] % mod * rev_rem[n - k] % mod;     for (long long i = 0; i < primes.size(); ++i) {       long long deg = get_deg(n, primes[i]) - get_deg(k, primes[i]) -                       get_deg(n - k, primes[i]);       res = res * binpow(primes[i], deg, mod) % mod;     }     return res;   }   long long get_res(long long l) {     long long res = 0;     for (long long par = 0; par < 2; ++par) {       for (long long cur = 0; 2 * cur + par <= n; ++cur) {         long long m = 2 * cur + par;         long long cur_l = l;         if ((cur_l + par) % 2) {           ++cur_l;         }         long long now_c = (m + cur_l) / 2;         res += getC(n, m) * getC(m, now_c);         res %= mod;       }     }     return res;   }   void solve(bool read) {     long long l, r;     cin >> n >> mod >> l >> r;     rem[0] = 1;     long long M = mod;     phi = mod;     for (long long p = 2; p * p <= M; ++p) {       if (M % p == 0) {         phi = phi * (p - 1) / p;         primes.push_back(p);         degs.push_back(0);         while (M % p == 0) {           M /= p;           ++degs.back();         }       }     }     if (M > 1) {       phi = phi * (M - 1) / M;       primes.push_back(M);       degs.push_back(1);     }     for (long long i = 1; i < C; ++i) {       long long cur = i;       for (long long p : primes) {         while (cur % p == 0) {           cur /= p;         }       }       rem[i] = rem[i - 1] * cur % mod;     }     for (long long i = 0; i < C; ++i) {       rev_rem[i] = binpow(rem[i], phi - 1, mod);     }     long long res = get_res(l) - get_res(r + 1);     res %= mod;     if (res < 0) {       res += mod;     }     cout << res << endl;   }