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

#max_xor = 1 << (len(bin(max(A))) - 2)
ans = N
for l in range(N-1):
    csum = A[l]
    cxor = A[l]
    for r in range(l+1,N):
        #if csum >= max_xor:
        #    break
        csum += A[r]
        cxor ^= A[r]
        if csum == cxor:
            ans += 1
        else:
            break
print(ans)


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

    if N == 1:
        return 1

    ans = N
    l = 0
    r = 0
    s = A[l]
    while l < N-1:
        if r+1 < N:
            if s & A[r+1] == 0:
                r += 1
                s |= A[r]
                ans += r - l
                continue
        if l == r:
            l += 1
            r += 1
            s = A[l]
        else:
            s &= ~A[l]
            l += 1
    return ans

print(solve())

#  1  2  4  8  1
#  l  r              (1,2)
#  l     r           (1,4)(2,4)
#  l        r        (1,8)(2,8)(4,8)
#     l     r
#     l        r     (2,1)(4,1)(8,1)

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

max_xor = 1 << (len(bin(max(A))) - 2)
ans = N
for l in range(N-1):
    csum = A[l]
    cxor = A[l]
    for r in range(l+1,N):
        if csum >= max_xor:
            break
        csum += A[r]
        cxor ^= A[r]
        if csum == cxor:
            ans += 1
print(ans)


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

    if N == 1:
        return 1

    ans = N
    l = 0
    r = 0
    s = A[l]
    while l < N-1:
        if r+1 < N:
            if s & A[r+1] == 0:
                r += 1
                s |= A[r]
                ans += r - l
                continue
        if l == r:
            l += 1
            r += 1
            s = A[l]
        else:
            s &= ~A[l]
            l += 1
    return ans

print(solve())

#  1  2  4  8  1
#  l  r              (1,2)
#  l     r           (1,4)(2,4)
#  l        r        (1,8)(2,8)(4,8)
#     l     r
#     l        r     (2,1)(4,1)(8,1)

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

max_xor = 1 << (len(bin(max(A))) - 2)
ans = N
for l in range(N-1):
    csum = A[l]
    cxor = A[l]
    for r in range(l+1,N):
        if csum >= max_xor:
            break
        csum += A[r]
        cxor ^= A[r]
        if csum == cxor:
            ans += 1
print(ans)


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

    if N == 1:
        return 1

    ans = N
    l = 0
    r = 0
    s = A[l]
    while l < N-1:
        if r+1 < N:
            if s & A[r+1] == 0:
                r += 1
                s |= A[r]
                ans += r - l
                continue
        if l == r:
            l += 1
            r += 1
            s = A[l]
        else:
            s &= ~A[l]
            l += 1
    return ans

print(solve())

#  1  2  4  8  1
#  l  r              (1,2)
#  l     r           (1,4)(2,4)
#  l        r        (1,8)(2,8)(4,8)
#     l     r
#     l        r     (2,1)(4,1)(8,1)

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

csum = [0 for _ in range(N+1)]
cxor = [0 for _ in range(N+1)]
for i in range(1,N+1):
    csum[i] = csum[i-1] + A[i]
    cxor[i] = cxor[i-1] ^ A[i]
ans = N
for l in range(1,N):
    for r in range(l+1,N+1):
        rsum = csum[r] - csum[l-1]
        rxor = cxor[r] ^ cxor[l-1]
        if rsum == rxor:
            ans += 1
print(ans)


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

    if N == 1:
        return 1

    ans = N
    l = 0
    r = 0
    s = A[l]
    while l < N-1:
        if r+1 < N:
            if s & A[r+1] == 0:
                r += 1
                s |= A[r]
                ans += r - l
                continue
        if l == r:
            l += 1
            r += 1
            s = A[l]
        else:
            s &= ~A[l]
            l += 1
    return ans

print(solve())

#  1  2  4  8  1
#  l  r              (1,2)
#  l     r           (1,4)(2,4)
#  l        r        (1,8)(2,8)(4,8)
#     l     r
#     l        r     (2,1)(4,1)(8,1)