#include using namespace std; int main() { ios::sync_with_stdio(false); int N; int64_t L, R; cin >> N >> L >> R; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } auto calc = [&](int64_t ub, bool inc) -> int64_t { vector> dp(62, vector(2)); dp[0][0] = 1; for (int i = 0; i < 61; ++i) { map> pfx2pos; for (int x = 0; x < N; ++x) { pfx2pos[A[x] >> 61 - i].push_back(x); } int must = -1; for (auto it : pfx2pos) { vector vec; for (int x : it.second) { int v = A[x] >> 60 - i & 1; if (vec.empty() || vec.back() != v) { vec.push_back(v); } } if (2 < vec.size()) return 0; if (1 < vec.size()) { if (must == -1) must = vec[1] < vec[0]; if (must != (vec[1] < vec[0])) return 0; } } vector choices; if (must == -1) choices = { 0, 1 }; else choices = { must }; for (int l = 0; l < 2; ++l) { int v = ub >> 60 - i & 1; for (int d : choices) { if (!l && v < d) continue; dp[i + 1][l | d < v] += dp[i][l]; } } } int64_t res = dp[61][1]; if (inc) res += dp[61][0]; return res; }; int64_t ans = calc(R, true) - calc(L, false); cout << ans << endl; return 0; }