#include using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long LL; typedef pair P; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template T gcd(T a,T b){return b?gcd(b,a%b):a;} const LL mod=1000000007; const LL LINF=1LL<<60; const int INF=1<<30; int dx[]={1,0,-1,0,1,-1,1,-1}; int dy[]={0,1,0,-1,1,-1,-1,1}; vector v(64,0); void rec(int k,vector a){ if(k < 0) return; int n = a.size(); if(n == 1) return; int cnt = 0; for (int i = 0; i < n - 1; i++) { int t = a[i] >> k & 1, nt = a[i+1] >> k & 1; if(t != nt) cnt++; } if(cnt == 0){ rec(k-1, a); } else if(cnt == 1){ vector L,R; for (int i = 0; i < n; i++) { int t = a[i] >> k & 1; if(t == 0) L.pb(a[i]); else R.pb(a[i]); } if(a[0] >> k & 1) v[k] |= 2; else v[k] |= 1; rec(k-1, L); rec(k-1, R); } else{ v[k] |= 3; } return ; } LL dp[64][2]; LL rec2(int k,LL s,bool f){ if(k < 0) return 1; if(~dp[k][f]) return dp[k][f]; int x = f ? s >> k & 1 : 1; LL ret = 0; if(v[k] == 0){ for (int i = 0; i <= x; i++) { ret += rec2(k-1,s,f&(x == i)); } } else if(v[k] == 1){ ret += rec2(k-1,s,f&(x == 0)); } else if(v[k] == 2){ if(x == 0) return dp[k][f] = 0; ret += rec2(k-1,s,f&(x == 1)); } else{ return dp[k][f] = 0; } return dp[k][f] = ret; } int f(LL n){ int ret = 0; while(n){ n >>= 1; ret++; } return ret - 1; } int main(){ LL n,l,r;cin >> n >> l >> r; l--; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } rec(63,a); LL ans = 0; auto solve = [](LL r){ for (int i = f(r)+1; i <= 63; i++) { if(v[i]) return 0LL; } memset(dp,-1,sizeof(dp)); return rec2(f(r), r, 1); }; ans += solve(r); if(l >= 0){ ans -= solve(l); } cout << ans << endl; return 0; }