n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) max_a = max(a).bit_length() ans = 0 for i in range(n): a_r = b_r = 0 for j in range(i, min(n, i+max_a)): if a_r & a[j] != 0: break else: a_r |= a[j] b_r |= b[j] if b_r == 0: ans += 1 print(ans)