import sys from functools import lru_cache def main(): N, L, R = map(int, sys.stdin.readline().split()) A = list(map(int, sys.stdin.readline().split())) if N == 1: print(max(0, R - L + 1)) return constraints = {} for i in range(N-1): a = A[i] b = A[i+1] c = a ^ b if c == 0: print(0) return k = c.bit_length() - 1 while (c >> k) == 0: k -= 1 if a < b: required_bit = 0 else: required_bit = 1 if k in constraints: if constraints[k] != required_bit: print(0) return else: constraints[k] = required_bit fixed_val = 0 fixed_mask = 0 for bit in constraints: val = constraints[bit] fixed_mask |= (1 << bit) fixed_val |= (val << bit) allowed_mask = (~fixed_mask) & ((1 << 61) - 1) if fixed_val > R: print(0) return lower = max(0, L - fixed_val) upper = R - fixed_val if lower > upper: print(0) return @lru_cache(maxsize=None) def count_subset_le(max_var, allowed_bits): def dp(bit, is_less): if bit < 0: return 1 current_bit_mask = 1 << bit max_bit = (max_var >> bit) & 1 allowed = (allowed_bits & current_bit_mask) != 0 res = 0 if allowed: if is_less: res += dp(bit-1, True) else: if 1 <= max_bit: new_is_less = (1 < max_bit) res += dp(bit-1, new_is_less) if is_less: res += dp(bit-1, True) else: new_is_less = (0 < max_bit) res += dp(bit-1, new_is_less) else: if is_less: res += dp(bit-1, True) else: new_is_less = (0 < max_bit) res += dp(bit-1, new_is_less) return res return dp(60, False) count_upper = count_subset_le(upper, allowed_mask) count_lower = count_subset_le(lower - 1, allowed_mask) if lower > 0 else 0 total = count_upper - count_lower print(total) if __name__ == "__main__": main()