Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

queue = []
ans = 0
popAt = -1
for i in range(N):
    for j in range(popAt + 1,len(queue)):
        if queue[j][1] & A[i] != 0:
            ans += i - queue[j][0]
            popAt = j
        else:
            queue[j][1] += A[i]
    queue.append([i,A[i]])

popAt += 1
z = ((N - popAt) * (N - popAt + 1)) // 2
print(ans+z)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))

cur = A[0]
ans = 0
rp = 1
for lp in range(N):
    while rp < N and cur & A[rp] == 0:
        cur += A[rp]
        rp += 1
    ans += rp - lp
    cur -= A[lp]
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

queue = []
ans = 0
popAt = -1
for i in range(N):
    temp = []
    while A[i] > 0:
        temp.append(A[i] & -A[i])
        A[i] -= A[i] & -A[i]
    for j in range(popAt + 1,len(queue)):
        if len(set(queue[j][1] + temp)) < len(queue[j][1]) + len(temp):
            ans += i - queue[j][0]
            popAt = j
        else:
            queue[j][1] = list(set(queue[j][1] + temp))
    queue.append([i,temp])

popAt += 1
z = ((N - popAt) * (N - popAt + 1)) // 2
print(ans+z)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))

cur = A[0]
ans = 0
rp = 1
for lp in range(N):
    while rp < N and cur & A[rp] == 0:
        cur += A[rp]
        rp += 1
    ans += rp - lp
    cur -= A[lp]
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

queue = []
ans = 0
popAt = -1
for i in range(N):
    temp = set()
    while A[i] > 0:
        temp.add(A[i] & -A[i])
        A[i] -= A[i] & -A[i]
    for j in range(popAt + 1,len(queue)):
        if len(queue[j][1] | temp) < len(queue[j][1]) + len(temp):
            ans += i - queue[j][0]
            popAt = j
        else:
            queue[j][1] |= temp
    queue.append([i,temp])

popAt += 1
z = ((N - popAt) * (N - popAt + 1)) // 2
print(ans+z)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))

cur = A[0]
ans = 0
rp = 1
for lp in range(N):
    while rp < N and cur & A[rp] == 0:
        cur += A[rp]
        rp += 1
    ans += rp - lp
    cur -= A[lp]
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import log

N = int(input())
A = list(map(int,input().split()))

bits = [[] for x in range(20)]
queue = []
ans = 0
for i in range(N):
    temp = set()
    while A[i] > 0:
        bits[int(log(A[i] & -A[i],2))].append(i)
        temp.add(A[i] & -A[i])
        A[i] -= A[i] & -A[i]
    popAt = -1
    for j in range(len(queue)):
        if len(queue[j][1] | temp) < len(queue[j][1]) + len(temp):
            ans += i - queue[j][0]
            popAt = j
        else:
            queue[j][1] |= temp
    queue = queue[popAt+1:] + [[i,temp]]

z = (len(queue) * (len(queue) + 1)) // 2
print(ans+z)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))

cur = A[0]
ans = 0
rp = 1
for lp in range(N):
    while rp < N and cur & A[rp] == 0:
        cur += A[rp]
        rp += 1
    ans += rp - lp
    cur -= A[lp]
    
print(ans)