/** * author: ivanzuki * created: Tue May 11 2021 **/ #include using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template string to_string(pair p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } template void dout(string name, int idx, T arg) { cerr << name << " = " << to_string(arg); } template void dout(string names, int idx, T1 arg, T2... args) { cerr << names.substr(0, names.find(',')) << " = " << to_string(arg) << ", "; dout(names.substr(names.find(',') + 2), idx + 1, args...); } #ifdef LOCAL #define debug(...) cerr << "[", dout(#__VA_ARGS__, 0, __VA_ARGS__), cerr << "]" << endl; #else #define debug(...) 42 #endif const int B = 60; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; long long l, r; cin >> n >> l >> r; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector mask(B + 1); for (int i = 0; i + 1 < n; i++) { for (int bit = B; bit >= 0; bit--) { int b1 = (a[i] >> bit) & 1; int b2 = (a[i + 1] >> bit) & 1; if (b1 == 0 && b2 == 1) { mask[bit] |= 1; break; } else if (b1 == 1 && b2 == 0) { mask[bit] |= 2; break; } } } for (int bit = B; bit >= 0; bit--) { if (mask[bit] == 3) { cout << 0 << '\n'; return 0; } } auto Solve = [&](long long mx) { vector> dp(B + 2, vector(2, 0)); dp[0][0] = 1; for (int bit = B; bit >= 0; bit--) { int i = B - bit; int b_mx = (mx >> bit) & 1; int b_x = mask[bit]; if (b_x == 0) { // it can any of 0 or 1 if (b_mx == 0) { dp[i + 1][0] += dp[i][0]; dp[i + 1][1] += 2 * dp[i][1]; } else { dp[i + 1][1] += dp[i][0] + 2 * dp[i][1]; dp[i + 1][0] += dp[i][0]; } } else if (b_x == 1) { // it must be 0 if (b_mx == 0) { dp[i + 1][0] += dp[i][0]; dp[i + 1][1] += dp[i][1]; } else { dp[i + 1][1] += dp[i][0] + dp[i][1]; } } else if (b_x == 2) { // it must be 1 if (b_mx == 0) { dp[i + 1][1] += dp[i][1]; } else { dp[i + 1][0] += dp[i][0]; dp[i + 1][1] += dp[i][1]; } } else { assert(0); } } return dp[B + 1][0] + dp[B + 1][1]; }; long long ans = Solve(r) - (l - 1 < 0 ? 0 : Solve(l - 1)); cout << ans << '\n'; return 0; }