import bisect from collections import defaultdict def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 A = list(map(int, input[ptr:ptr+N])) ptr += N B = list(map(int, input[ptr:ptr+N])) ptr += N # Compute prefix XOR for B preB = [0] current = 0 for b in B: current ^= b preB.append(current) # Build pos_dict: value to sorted list of indices pos_dict = defaultdict(list) for idx, val in enumerate(preB): pos_dict[val].append(idx) last_occurrence = [-1] * 32 left = 0 answer = 0 for right in range(N): x = A[right] current_left = left # Find the set bits in x bits = [] for bit in range(32): if (x >> bit) & 1: bits.append(bit) # Determine new left for bit in bits: if last_occurrence[bit] != -1: if current_left < last_occurrence[bit] + 1: current_left = last_occurrence[bit] + 1 # Update last_occurrence for all bits in x for bit in bits: last_occurrence[bit] = right left = current_left # Calculate target value and query target_val = preB[right + 1] a = left b = right # because l ranges from left to right (0-based in A), which corresponds to preB indices a to b (inclusive) lst = pos_dict.get(target_val, []) if not lst: continue # Find the number of indices in [a, b] inclusive l_pos = bisect.bisect_left(lst, a) r_pos = bisect.bisect_right(lst, b) answer += r_pos - l_pos print(answer) if __name__ == "__main__": main()