#include using namespace std; using ll = long long; using PII = pair; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() template void chmin(T &a, const T &b) { a = min(a, b); } template void chmax(T &a, const T &b) { a = max(a, b); } struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio; #ifdef DEBUG_ #include "../program_contest_library/memo/dump.hpp" #else #define dump(...) #endif const ll INF = 1LL<<60; int main(void) { ll n, l, r; cin >> n >> l >> r; vector a(n); REP(i, n) cin >> a[i]; vector> can(62); auto func = [&] { vector p; REP(i, 62) { ll idx = 0; vector> v(p.size()+1); REP(j, n) { if(idx<(ll)p.size() && p[idx]==j) idx++; v[idx].push_back(!!(a[j]&1LL<<(61-i))); } ll sz = 0; bool ok0 = true, ok1 = true; for(auto vec: v) { ll turn = 0; REP(j, vec.size()) { if(turn==0 && vec[j]!=vec[0]) turn = 1, p.push_back(sz+j); else if(turn==1 && vec[j]==vec[0]) { cout << 0 << endl; exit(0); } } if(turn==1) { if(vec[0]==0) ok1 = false; else if(vec[0]==1) ok0 = false; } sz += vec.size(); } if(ok0) can[i].push_back(0); if(ok1) can[i].push_back(1); sort(ALL(p)); } }; auto solve = [&](ll x) -> ll { vector> dp(63, vector(2)); dp[0][0] = 1; REP(i, 62) REP(j, 2) { ll bit = !!(x&1LL<<(61-i)); for(auto k: can[i]) { if(j==0 && k > bit) continue; dp[i+1][j || k < bit] += dp[i][j]; } } return dp[62][0] + dp[62][1]; }; func(); dump(can); cout << solve(r) - (l==0?0:solve(l-1)) << endl; return 0; }