Problem:
 Score : 500 points    Problem Statement There is an integer sequence A of length N .  Find the number of the pairs of integers l and r ( 1 \leq l \leq r \leq N ) that satisfy the following condition:   A_l\ xor\ A_{l+1}\ xor\ ...\ xor\ A_r = A_l\ +\ A_{l+1}\ +\ ...\ +\ A_r   Here, xor denotes the bitwise exclusive OR.   Definition of XOR  The XOR of integers c_1, c_2, ..., c_m is defined as follows:   Let the XOR be X . In the binary representation of X , the digit in the 2^k 's place ( 0 \leq k ; k is an integer) is 1 if there are an odd number of integers among c_1, c_2, ...c_m whose binary representation has 1 in the 2^k 's place, and 0 if that number is even.   For example, let us compute the XOR of 3 and 5 . The binary representation of 3 is 011 , and the binary representation of 5 is 101 , thus the XOR has the binary representation 110 , that is, the XOR is 6 .

Solution (Python):
n = int(input())
aaa = list(map(int, input().split()))
right = 0
sum = 0
cnt = 0
for left in range(n):
    while right < n and (sum ^ aaa[right]) == (sum + aaa[right]):
        sum += aaa[right]
        right += 1
    cnt += right - left
    if left == right:
        right += 1
    else:
        sum -= aaa[left]
print(cnt)

Solution (Python):


import sys







from bisect import bisect_left, bisect_right 






















def main():
    mod = 1000000007                
    
    inf = 2 ** 64 - 1             
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    digit = len(bin(max(L))[2:])
    bin_L = [(bin(elm)[2:]).zfill(digit) for elm in L]
    

    counter = [[0] * n for _ in range(digit)]

    for d in range(digit):
        accum = 0
        for i in range(n):
            if bin_L[i][d] == '1':
                accum += 1
            counter[d][i] = accum
    
    
    

    ans = 0
    j = 0
    for i in range(n):
        target_list = [counter[d][i] if bin_L[i][d] == '1' else counter[d][i] + 1 for d in range(digit)]
        while j < n:
            if not all([counter[d][j] <= target_list[d] for d in range(digit)]):
                break
            j += 1
        ans += (j - i)
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    l, t, n = 0, 0, 0
    for r, a in enumerate(A):
        while a & t:
            t ^= A[l]
            l += 1
        t |= a
        n += r - l + 1
    return n

print(main())

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))

    l, r = 1, 0
    t = A[0]
    n = 1
    while l < N:
        if A[l] & t:
            t ^= A[r]
            r += 1
            continue
        t |= A[l]
        l += 1
        n += l - r
    return n

print(main())

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

r = 0
res = 0
x = 0
s = 0
for l in range(N):
    while r < N and x ^ A[r] == s + A[r]:
        x ^= A[r]
        s += A[r]
        r += 1
    res += r - l

    if r == l:
        r += 1
    else:
        x ^= A[l]
        s -= A[l]

print(res)

Solution (Python):
n=int(input())
a=tuple(map(int,input().split(' ')))
r,ans,tsum,txor=0,0,0,0
for l in range(n):
    while r<n and txor^a[r]==tsum+a[r]:
        txor = txor^a[r]
        tsum = tsum+a[r]
        r += 1
    ans += r-l
    if l==r:
        r+=1
    else:
        txor = txor^a[l]
        tsum -= a[l]
print(ans)

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    right, ans, tmp = 0, 0, 0

    
    for left in range(N):
        while right < N and tmp ^ A[right] == tmp + A[right]:
            tmp += A[right]
            ans += right - left + 1
            right += 1

        
        if left == right:
            right += 1
        
        else:
            tmp -= A[left]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    
    ans = 0
    right = 0
    xor = 0
    s = 0
    for left in range(N):
        while right < N and s + A[right] == xor ^ A[right]:
            s += A[right]
            xor ^= A[right]
            right += 1

        ans += right - left

        if right == left:
            right += 1
        else:
            s -= A[left]
            xor ^= A[left]

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a_list = [int(x) for x in input().split()]

ans = 0
temp_xor = a_list[0]
temp_sum = a_list[0]
r = 0
for l in range(n):
    while r < n:
        if temp_xor != temp_sum:
            break
        r += 1
        if r < n:
            temp_xor ^= a_list[r]
            temp_sum += a_list[r]
    ans += r - l
    temp_xor ^= a_list[l]
    temp_sum -= a_list[l]
print(ans)

Solution (Python):


def submit():
    n = int(input())
    a = [int(e) for e in input().split()]

    l, r = 0, 0
    ans = 0
    curr_xor = 0
    curr_sum = 0
    while r < n:
        curr_xor = curr_xor ^ a[r]
        curr_sum = curr_sum + a[r]

        
        while curr_xor != curr_sum:
            curr_xor = curr_xor ^ a[l]
            curr_sum = curr_sum - a[l]
            l += 1
            
        ans += r - l + 1
        
        r += 1

    print(ans)


submit()

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
L=list(map(int,input().split()))
t=0
ans=0
l=0
r=0
while r<=N-1:
 if t+L[r]==t^L[r]:
  t+=L[r]
  r+=1
 else:
  ans+=(r-l)
  t-=L[l]
  l+=1
ans+=(r-l)*(r-l+1)/2
print(int(ans))

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
L=list(map(int,input().split()))
t=0
ans=0
l=0
r=0
while r<=N-1:
 if t+L[r]==t^L[r]:
  t+=L[r]
  r+=1
 else:
  ans+=(r-l)
  t-=L[l]
  l+=1
ans+=(r-l)*(r-l+1)/2
print(int(ans))

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

ans,x=0,0
wa,haita=0,0
for j in range(N):
    while x<N and haita^A[x]==wa+A[x]:
        haita^=A[x]
        wa+=A[x]
        x+=1
    ans+=x-j
    haita^=A[j]
    wa-=A[j]
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
l=0 
r=1
buf=0
cnt=0
ans=[]
su=0
i=0
length=0
while r<=N:
    if buf+A[r-1]==buf^A[r-1]:
        length=length+1
        buf=buf^A[r-1]
        r=r+1
    else:
        buf=buf^A[l]
        l=l+1
        cnt=0
        su=su+length
        length=length-1
        if r==l:
            r=r+1
    
    




print(su+((r-l-1)*(r-l))//2)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
k=0
Xor=0
Add=0
for i in range(n):
    while k<n and Xor^a[k]==Add+a[k]:
        Xor^=a[k]
        Add+=a[k]
        k+=1
    ans+=k-i
    Xor^=a[i]
    Add-=a[i]
print(ans)

Solution (Python):
def isok(a):
    for j in range(21):
        if(a>>j&1):
            if(bit[j]>0):
                return False
    return True
def bitplus(a):
    for j in range(21):
        if(a>>j&1):
            bit[j]+=1
def bitdif(a):
    for j in range(21):
        if(a>>j&1):
            bit[j]-=a>>j&1

N=int(input())
A=list(map(int,input().split()))
left=0
ans=0
bit=[0]*21
right=0
while(left<N):
    while(right<N and isok(A[right])):
        bitplus(A[right])
        right+=1
    ans+=right-left
    if right==left:
        right+=1
    else:
        bitdif(A[left])
    left+=1
print(ans)

Solution (Python):
n,a=int(input()),list(map(int,input().split()));r,i,x=0,0,0
for j in range(n):
    while x<n and(i&a[x])==0:i+=a[x];x+=1
    r+=x-j;i-=a[j]
print(r)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

result = 0
i = 0
x = 0
for j in range(n):
    while x < n and (i & a[x]) == 0:
        i += a[x]
        x += 1
    result += x-j
    i -= a[j]
print(result)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

result = 0
i = 0
x = 0
for j in range(n):
    while x < n and (i & a[x]) == 0:
        i += a[x]
        x += 1
    result += x-j
    i -= a[j]
print(result)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))

ll=0
rr=0
llrr=0

result=0

for ll in range(n):

    while rr<n and a[rr]&llrr==0:
        llrr+=a[rr]
        rr+=1
    result+=rr-ll
    llrr=llrr^a[ll]

print(result)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
r = 0
ans = 0
s = 0
xor = 0

for i in range(n):
    while r < n:
        if xor ^ a[r] == s + a[r]:
            xor = xor ^ a[r]
            s += a[r]
            r += 1
            ans += (r-i)
        else:
            xor = xor ^ a[i]
            s -= a[i]
            break

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    r = 0
    b = 0
    ans = 0
    for l in range(N):
        while r < N and A[r] & b == 0:
            b |= A[r]
            r += 1
        ans += r - l
        b = b ^ A[l]

    print(ans)




if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    r = 0
    b = A[0]
    ans = 0
    for l in range(N):
        while r + 1 < N and A[r + 1] & b == 0:
            r += 1
            b |= A[r]
        ans += r - l + 1
        b = b ^ A[l]

    print(ans)




if __name__ == '__main__':
    main()

Solution (Python):
from heapq import heapify,heappush,heappop
n = int(input())
a = [int(i) for i in input().split()]

p = 0
ans = 0
cc = 0
cs = 0
chk = []
heapify(chk)
for i,ai in enumerate(a):
  heappush(chk,(i,ai))
  cc = cc^ai
  cs += ai
  ans += 1
  if cc != cs :
    p += (ans-1)*(ans)//2
    while chk:
      j,aj = heappop(chk)
      ans -= 1
      cc = cc^aj
      cs -= aj
      if cc == cs:
        p -= (ans-1)*(ans)//2
        cnt = 0
        break
p += ans*(ans+1)//2
print(p)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
L=0
R=0
now=A[0]
add=0
flag=0 
Ans=[]
while R<n-1:
    if flag==0:
        R+=1
        if now+A[R]==now^A[R]:
            now+=A[R]
        else:
            Ans.append([L,R-1])
            flag=1
    else:
        now-=A[L]
        L+=1
        if now+A[R]==now^A[R]:
            now+=A[R]
            flag=0
if flag==0:
    Ans.append([L,R])
else:
    while L<n-1:
        now-=A[L]
        L+=1
        if now+A[R]==now^A[R]:
            Ans.append([L,R])


ans=0
for i in range(len(Ans)):
    d=Ans[i][1]-Ans[i][0]+1
    ans+=(d+1)*d//2
    if i!=0:
        d=Ans[i-1][1]-Ans[i][0]+1
        if d>0:
            ans-=(d+1)*d//2
print(ans)

Solution (Python):







def bin20(x):
    bin_x = bin(x)[2:]
    x_len = len(bin_x)

    return list(map(int, "0" * (20-x_len) + bin_x))


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = [bin20(a) for a in A]

    ans = 0
    left = 0
    right = 0
    sum20 = [0] * 20
    pre_right = -1
    while True:
        if right > pre_right:
            for k in range(20):
                sum20[k] += A[right][k]

        pre_right = right

        if 2 in sum20:
            for k in range(20):
                sum20[k] -= A[left][k]
            ans += right - left
            left += 1
        else:
            right += 1

        if right == N:
            ans += (N-left) * (N-left+1) // 2

            return ans


print(main())

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

l,r = 0,0
num = 0
ans = 0
while r<N:
    if num^A[r] == num + A[r]:
        num += A[r]
        r += 1
        ans += r-l
        
    else:
        if l==r:
            l += 1
            r += 1
            
        else:
            num -= A[l]
            l += 1
            
print(ans)

Solution (Python):

import sys

def solve(N: int, A: "List[int]"):
    ans, t, s = 0, 0, 0
    for h in range(N):
        while t < N and s ^ A[t] == s + A[t]:
            s += A[t]
            t += 1
        ans += t - h
        s -= A[h]
    return ans


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
count = 0
r = 1
l = 0
now = a[0]
while l < n:

    while True:
        if r < n and now + a[r] == now^a[r]:
            now += a[r]
            count += r-l
            r += 1
        else:
            break
    if l == r:
        now = a[l]
        r += 1
    elif l < n:
        now -= a[l]
        l += 1
print(count+n)

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

left = 0
right = 0
ans = 0
tmp = 0

for left in range(N):
    while right < N and tmp + A[right] == tmp ^ A[right]:
        tmp += A[right]
        right += 1
        
    ans += right - left
    
    if right == left:
        right += 1
    else:
        tmp -= A[left]
        
print(ans)

Solution (Python):

import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    ans=0
    left=0
    S,X=0,0
    for right in range(N):
        S+=A[right]
        X^=A[right]
        if S==X:
            continue
        else:
            ans+=(right-left)*(right-left+1)//2
            for left in range(left,right):
                S-=A[left]
                X^=A[left]
                if S==X:
                    left+=1
                    break
            ans-=(right-left)*(right-left+1)//2
    right+=1
    ans+=(right-left)*(right-left+1)//2
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
ans = R = X = 0
for L in range(n):
    while R < n and not(X & A[R]):
        X ^= A[R]
        R += 1
    ans += R-L
    X ^= A[L]
print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
ans = R = X = 0
for L in range(n):
    while R < n and not(X & A[R]):
        X ^= A[R]
        R += 1
    ans += R-L
    X ^= A[L]
print(ans)

Solution (Python):
n = int(input())
A = [list(map(int, list('{:020b}'.format(a))))
     for a in map(int, input().split())]

ans = 0
R = 0
X = [0]*20
for L in range(n):
    while R < n and all(x+y != 2 for x, y in zip(X, A[R])):
        for i in range(20):
            X[i] += A[R][i]
        R += 1
    ans += R-L
    for i in range(20):
        X[i] -= A[L][i]
print(ans)

Solution (Python):
n = int(input())
A = [list(map(int, list('{:020b}'.format(a))))
     for a in map(int, input().split())]

ans = 0
R = -1
X = [0]*20
for L in range(n):
    while R+1 < n and all(x+y != 2 for x, y in zip(X, A[R+1])):
        for i in range(20):
            X[i] += A[R+1][i]
        R += 1
    ans += R-L+1
    for i in range(20):
        X[i] -= A[L][i]
print(ans)

Solution (Python):
n = int(input())
A = [list(map(int, list('{:020b}'.format(a))))
     for a in map(int, input().split())]

ans = 0
R = -1
X = [0]*20
for L in range(n):
    if R < L:
        R += 1
        for i in range(20):
            X[i] += A[R][i]

    while R+1 < n and all(x+y != 2 for x, y in zip(X, A[R+1])):
        for i in range(20):
            X[i] += A[R+1][i]
        R += 1
    ans += R-L+1
    for i in range(20):
        X[i] -= A[L][i]
print(ans)

Solution (Python):

import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') 
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(sys.stdin.readline()) 
def ifn(): return float(sys.stdin.readline()) 
def isn(): return sys.stdin.readline().split() 
def imn(): return map(int, sys.stdin.readline().split()) 
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) 
def fmn(): return map(float, sys.stdin.readline().split()) 
def iln(): return list(map(int, sys.stdin.readline().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, sys.stdin.readline().split())) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N = iin()
A = iln()

right=0
total=0
xtotal=0
ans = 0
for left in range(N):
    while (right < N and total+A[right]==xtotal^A[right]):
        total += A[right]
        xtotal ^= A[right]
        right += 1
    ans += (right - left)
    if (right==left): right +=1
    else:
        total -= A[left]
        xtotal ^= A[left]
print(ans)

Solution (Python):

import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    ans=0
    left=0
    S,X=0,0
    for right in range(N):
        S+=A[right]
        X^=A[right]
        if S==X:
            continue
        else:
            ans+=(right-left)*(right-left+1)//2
            for left in range(left,right):
                S-=A[left]
                X^=A[left]
                if S==X:
                    left+=1
                    break
            ans-=(right-left)*(right-left+1)//2
    right+=1
    ans+=(right-left)*(right-left+1)//2
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m, x, c = 0, 0, 0
j = 0
ans = 0
for i in range(n):
    m += a[i]
    x ^= a[i]
    c += 1
    if not m == x:
        while True:
            if m == x:
                break
            x ^= a[j]
            m -= a[j]
            j += 1
            c -= 1
    ans += c
print(ans)

Solution (Python):
N = int(input())
ARR = list(map(int,input().split()))
def calculate(n,arr):
    right = 0
    sum = arr[0]
    result = 0

    for left in range(0,n):
        while (right + 1 < n) and ( (sum + arr[right+1]) == (sum ^ arr[right+1]) ):
            right = right + 1
            sum = sum + arr[right]

        result = result + right - left + 1
        sum = sum - arr[left]

    print(result)

calculate(N,ARR)

Solution (Python):
N = int(input())
ARR = list(map(int,input().split()))
def calculate(n, arr):
    result = 0
    right = 0
    sum = arr[0]
    for left in range(0, n):
        while right+1 < n:
            if sum ^ arr[right+1] == (sum + arr[right+1]):
                right = right + 1
                sum = sum + arr[right]
            else:
                break
        result = result + right - left + 1
        sum = sum - arr[left]
    print(result)

calculate(N, ARR)

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, A: "List[int]"):
    ans = 0
    j = 0
    x = 0
    for i in range(N):
        while j < N and (x & A[j]) == 0:
            x ^= A[j]
            j += 1
        ans += j - i
        x ^= A[i]
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)


if __name__ == '__main__':
    main()

Solution (Python):
nim =int(input())
mike = list(map(int,input().split()))

S = [0]
X = [0]
for a in mike:
    S.append(S[-1]+a)
    X.append(X[-1]^a)

l,r = 1,1
result = 0
p = 1
while r <= nim:
    if S[r]-S[l-1] == X[r]^X[l-1]:
        if p==0:
            result -= (r-l)*(r-l+1)//2
        r += 1
        p = 1
    else:
        if p ==1:
            result += (r-l)*(r-l+1)//2
        l += 1
        p = 0
result += (r-l)*(r-l+1)//2
print(result)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    N = int(input())
    A = [0] + list(map(int, input().split()))
    acc = list(accumulate(A))
    xor = [0]
    for i in range(N):
        xor.append(xor[-1]^A[i+1])
        
    l, r = 1, 1
    res = 0
    while l <= N:
        if acc[r]-acc[l-1] == (xor[r]^xor[l-1]):
            r += 1
            if r == N+1:
                res += (r-l+1)*(r-l)//2
                break
        else:
            temp = l
            l += 1
            while acc[r]-acc[l-1] != (xor[r]^xor[l-1]):
                l += 1
            if l-temp == 1:
                res += r-temp
            else:
                res += (r-temp+r-temp-l+temp+1)*(l-temp)//2
    print(res)

if __name__ == '__main__':
    main()

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

right = 0
SUM = 0
ans = 0
for left in range(N):
    while right < N and SUM | A[right] == SUM + A[right]:
        SUM += A[right]
        right += 1
    
    ans += right - left
    
    if right == left:
        right += 1
    else:
        SUM -= A[left]
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
left=0
ans=0
xor_sum=0
normal_sum=0
for right,b in enumerate(a):
	xor_sum^=b
	normal_sum+=b
	while xor_sum<normal_sum:
		xor_sum^=a[left]
		normal_sum-=a[left]
		left+=1
	ans+=right-left+1
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
r=max(a)
e=len(bin(r))-2
p=[[]for _ in range(n)]
for i in range(e):
	for j in range(n):
		p[j].append(a[j]%2)
		a[j]//=2
ans=0
cnt=[0]*e
j=0
for i in range(n):
	while 2 not in cnt and j<n:
		for k in range(e):
			cnt[k]+=p[j][k]
		j+=1
	if 2 not in cnt:
		ans+=1
	ans+=j-i-1
	for k in range(e):
		cnt[k]-=p[i][k]
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
res = 0
right = 0
total = 0
for left in range(N):
    while right < N and (total ^ A[right]) == (total + A[right]):
        total += A[right]
        right += 1
    res += right - left
    if right == left:
        right += 1
    else:
        total -= A[left]
print(res)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

ans=0
right=0
left=0
array_sum = 0
sum_xor = 0
sum_pls = 0

for left in range(n):

    while right<n and sum_pls+a[right] == sum_xor^a[right]:
        sum_pls += a[right]
        sum_xor ^= a[right]
        right+=1

    ans += right-left
    sum_pls -= a[left]
    sum_xor ^= a[left]

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
right=0
np=a[0]
nx=a[0]
for left in range(n):
    while np==nx:
        right+=1
        if right==n:
            break
        np+=a[right]
        nx^=a[right]
    else:
        np-=a[right]
        nx^=a[right]
    right-=1
    ans+=(right-left+1)
    np-=a[left]
    nx^=a[left]
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
right=0
np=a[0]
nx=a[0]
for i in range(n):
    left=i
    if i!=0:
        np-=a[left-1]
        nx^=a[left-1]
    while np==nx:
        right+=1
        if right==n:
            break
        np+=a[right]
        nx^=a[right]
    else:
        np-=a[right]
        nx^=a[right]
    right-=1
    ans+=(right-left+1)
print(ans)

Solution (Python):
N=int(input())
alist=list(map(int,input().split()))


slist=[0]
xlist=[0]
for i in range(N):
  slist.append(slist[-1]+alist[i])
  xlist.append(xlist[-1]^alist[i])



ans_list=[0]*N
l,r=1,1
while(r<N):
  
  sum_lr=slist[r+1]-slist[l-1]
  xor_lr=xlist[r+1]^xlist[l-1]
  
  if sum_lr==xor_lr:
    r+=1
  else:
    
    ans_list[l-1]=r-1
    l+=1


for i in range(l-1,N):
  ans_list[i]=r-1


answer=0
for i in range(N):
  answer+=ans_list[i]+1-i
  
print(answer)

Solution (Python):

n=int(input())
a=list(map(int,input().split()))
ans=0
right=0
now=[0]*20
for i in range(n):
    left=i
    if i!=0:
        for j in range(20):
            if (a[left-1]>>j)&1:
                now[j]-=1
    else:
        for j in range(20):
            if (a[left]>>j)&1:
                now[j]+=1
    while all([now[j]<=1 for j in range(20)]):
        
        right+=1
        if right==n:
            break
        for k in range(20):
            if (a[right]>>k)&1:
                now[k]+=1
    else:
        
        for k in range(20):
            if (a[right]>>k)&1:
                now[k]-=1
    right-=1
    ans+=(right-left+1)
    
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

res = 0
right = 0
sum = 0
for left in range(n):
    while (right < n and sum^a[right] == sum+a[right]):
        sum += a[right]
        right += 1
    res += right - left
    if left == right:
        right += 1
    else:
        sum -= a[left]
print(res)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
c = 0
s = 0
d = 0
j = 0
for i in range(n):
	d = 0
	while j < n and s & a[j] == 0:
		s += a[j]
		j += 1
	s -= a[i]
	c += j-i
print (c)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = [[0]*20]
for i in a:
    tmp = []
    for j in range(20):
        tmp.append((i>>j&1)+s[-1][j])
    s.append(tmp)
l = 0
r = 0
ans = 0
while l < n:
    for j in range(20):
        if s[r+1][j]-s[l][j]>1:
            ans += r-l
            l += 1
            break
    else:
        if r < n-1:
            r += 1
        else:
            ans += n-l
            l += 1
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=s=r=0
for l in range(n):
  while r<n and s&a[r]==0:
    s+=a[r]
    r+=1
  s-=a[l]
  ans+=r-l
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
a = [int(x) for x in input().split()]

right = 0
s = 0
ans = 0

for left in range(n):
    while right < n and s ^ a[right] == s | a[right]:
        s ^= a[right]
        right += 1
    
    ans += right - left

    if left == right:
        right += 1
    else:
        s -= a[left]

print(ans)

Solution (Python):
n, *A = map(int, open(0).read().split())

ans = s = r = 0
for l in range(n):
    while r < n and s & A[r] == 0:
        s += A[r]
        r += 1
    s -= A[l]
    ans += r-l
print(ans)

Solution (Python):
n, *A = map(int, open(0).read().split())

ans = s = r = 0
for l in range(n):
    while r < n:
        if s & A[r] != 0:
            break
        s += A[r]
        r += 1
    s -= A[l]
    ans += r-l
print(ans)

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
res = 0
r = 0
s = 0
for l in range(n):
    while (r < n and s^a[r] == s+a[r]):
        s += a[r]
        r += 1
    res += r-l
    if l == r:
        r += 1
    else:
        s -= a[l]
print(res)

Solution (Python):

def search_1(x):
    l = set()
    n = len(bin(int(x))) - 2
    for j in range(n):
        if (int(x) >> j) & 1:
            l.add(j)
    return l

n = int(input())
a = [search_1(x) for x in input().split()]


ans = 0
cur = set()
r = 0
for l in range(0, n):
    while r < n and len(cur & a[r]) == 0:
        cur |= a[r]
        r += 1
    
    ans += r - l 
    
    cur -= a[l]
print(ans)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
s = 0
x = 0
r = 0
for l in range(n):
    while r<n and s+a[r]==x^a[r]:
        s += a[r]
        x ^= a[r]
        r += 1
    ans += (r-l)
    if l==r:
        r += 1
    else:
        s -= a[l]
        x ^= a[l]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))

b = []
li = [0] * 21
r = 0
ans = 0

for i in a:
    ai = bin(i)
    b.append(ai[2:])

for l in range(n):
    while True:
        if r >= n:
            ans += r - l
            break
        tmp = b[r]
        flag = True
        for i in range(len(tmp)):
            if li[i] == 1 and tmp[-i-1] == '1':
                flag = False
            if not flag:
                break
        if flag:
            for i in range(len(tmp)):
                li[i] += int(tmp[-i-1])
            r += 1
        else:
            for i in range(len(b[l])):
                li[i] -= int(b[l][-i-1])
            ans += r - l
            break

print(ans)

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

right = 0
sum_n = bit_n = 0
ans = 0

for left in range(N):
    while right < N and sum_n + A[right] == sum_n ^ A[right]:
        sum_n += A[right]
        bit_n ^= A[right]
        right += 1

    ans += right - left

    if right == left :
        right += 1
    else:
        sum_n -= A[left]
        bit_n ^= A[left]

print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
ans = 0
l, r = 0, 0
s = x = A[l]
flg = True
for l in range(n):
    while s == x and flg:
        r += 1
        if r == n:
            flg = False
            break
        s += A[r]; x ^= A[r]
    ans += r-l
    s -= A[l]
    x ^= A[l]
print(ans)

Solution (Python):
def to_b(num):
    ans = "";
    while (num > 0):
        if (num % 2 == 0):
            ans += '0';
        else:
            ans += '1';
        num //= 2;
    return ans[::-1];


def check(s, t):
    for i in range(len(s)):
        if (s[len(s) - i - 1] == t[i] and t[i] == '1'):
            return False;
    return True;


n = int(input());

v = list(map(int, input().split()))
a = [""] * n;
for i in range(n):
    num = v[i];
    a[i] = to_b(num);

tmp = ['0'] * 100
l = 0;
r = 0;
ans = 0;
while (r < n):
    if (check(a[r], tmp)):
        
        
        for i in range(len(a[r])):
            if (a[r][len(a[r]) - i - 1] == '1'):
                tmp[i] = '1';
        r += 1;
        ans += r - l;
        
    else:
        for i in range(len(a[l])):
            if (a[l][len(a[l]) - i - 1] == '1'):
                tmp[i] = '0';
        l += 1;
print(ans);

Solution (Python):
n=int(input())
a=list(map(int,input().split()))

ans = 0
a_xor = 0
a_sum = 0
r=-1

for l in range(n):
    while a_xor == a_sum:
        if r>=n-1:
            r = n
            break
        r += 1
        a_xor ^= a[r]
        a_sum += a[r]
        
    ans += r-l
    a_xor ^= a[l]
    a_sum -= a[l]
print(ans)

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















S = 0
X = 0
l = 0
cnt = 0
for r in range(N):
    S += A[r]
    X ^= A[r]
    if S == X:
        cnt += r - l + 1
    else:
        while l != r:
            S -= A[l]
            X ^= A[l]
            l += 1
            if S == X:
                cnt += r - l + 1
                break

print(cnt)