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())
A = list(map(int, input().split()))

sums = [0] * (N + 1)
xors = [0] * (N + 1)
for i in range(1, N + 1):
    sums[i] = sums[i - 1] + A[i - 1]
    xors[i] = xors[i - 1] ^ A[i - 1]

ans = 0
for i in range(N):
    l = i
    r = N
    while l + 1 < r:
        m = (l + r) // 2
        if sums[m + 1] - sums[i] == xors[m + 1] ^ xors[i]:
            l = m
        else:
            r = m
    ans += l - i + 1
print(ans)

Solution (Python):
from bisect import bisect_right
from bisect import bisect_left

icase=0
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))
elif icase==1:
    n=4
    a=[2,5,4,6]
elif icase==2:
    n=9
    a=[0,0,0,0,0,0,0,0,0]
elif icase==3:
    n=19
    a=[885,8,1,128,83,32,256,206,639,16,4,128,689,32,8,64,885,969,1]

amax=max(a)
k=len(bin(amax))-2

cc=[[0]*k for i in range(n)]
for i in range(n):
    ai=bin(a[i])[2:]

    kd=k-len(ai)
    for j in range(len(ai)):
        cc[i][kd+j]=int(ai[j])

cc2=[[0]*(n+1) for i in range(k)]
for i in range(n):
    for j in range(k):
        cc2[j][i+1]=cc2[j][i]+cc[i][j]


icnt=0
for i in range(n):

    cmin=n+1
    for j in range(k):

        iright=bisect_right(cc2[j],cc2[j][i]+1,i+1)-(i+1)
        cmin=min(cmin,iright)


    icnt+=cmin
print(icnt)

Solution (Python):
def XorSum2():
    n = int(input())
    a = list(map(int, input().split()))
    ans, tmp0, tmp1 = 0, 0, 0
    
    
    right = 0

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


if __name__ == '__main__':
    XorSum2()

Solution (Python):
def XorSum2():
    n = int(input())
    a = list(map(int, input().split()))
    ans, tmp0, tmp1 = 0, 0, 0
    
    
    right = 0

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


if __name__ == '__main__':
    XorSum2()

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

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

Solution (Python):
import numpy as np

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




r = 0 
temp = 0
ans = 0 
for l in range(N): 
    while r < N and temp ^ A[r] == temp + A[r]: 
        temp += A[r]
        r += 1
    
    ans += r - l 
    
    if r == l:
        r += 1 
        temp = 0
    else:
        temp -= A[l]
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A2 = []
Z = []
ans = 0
zerocnt = 0
for ai in A:
    if ai == 0:
        zerocnt += 1
    elif zerocnt >= 1:
        A2 += [0]
        Z += [zerocnt]
        ans += (zerocnt * (zerocnt+1)) // 2
        zerocnt = 0
    if ai != 0:
        A2 += [ai]
        Z += [1]
        ans += 1

if zerocnt >= 1:
    A2 += [0]
    Z += [zerocnt]
    ans += (zerocnt * (zerocnt+1)) // 2
    zerocnt = 0

for i, ai in enumerate(A2):
    aixor = ai
    sumA = ai
    for j in range(i+1, min(i+41, len(A2))):
        aj = A2[j]
        aixor = aixor ^ aj
        sumA += aj
        if aixor != sumA:
            break
        else:
            ans += (Z[i] * Z[j])
        
print(ans)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    right = 0
    s = 0

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

        ans += right - left

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

n=int(input())
a=list(map(int,input().split()))
ans=0
r=0
cnt=0

for l in range(n):
    while r<n and (cnt^a[r]==cnt+a[r]):
        cnt+=a[r]
        r+=1
    
    ans+=r-l
    cnt^=a[l]


print(ans)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

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

        ans += right - left

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

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

        ans += right - left

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    csum = [[0] * 20 for _ in range(N + 1)]
    for i in range(N):
        for j in range(20):
            csum[i + 1][j] = csum[i][j] + (1 if A[i] & (1 << j) else 0)

    def is_ok(l, r):
        res = True
        for j in range(20):
            if csum[r][j] - csum[l][j] > 1:
                res = False
                break
        return res

    ans = 0
    right = 0
    for left in range(N):
        while right < N and is_ok(left, right + 1):
            right += 1

        ans += right - left

        if left == right:
            right += 1

    print(ans)
    return


if __name__ == '__main__':
    main()

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

ans = 0
tmp = A[0]
end = 0


for start in range(N):

    while end < N - 1 and (tmp ^ A[end + 1] == tmp + A[end + 1]):
        end += 1
        tmp += A[end]

    ans += (end - start + 1)
    tmp -= A[start]

    if start == end and end < N - 1:
        end += 1
        tmp += A[end]

print(ans)

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

ans = 0
tmp = A[0]
end = 0
for start in range(N):
    while end < N-1 and tmp ^ A[end+1] == tmp + A[end+1]:
        end += 1
        tmp += A[end]
    ans += (end - start + 1)
    tmp -= A[start]
    if start == end and end < N - 1:
        end += 1
        tmp += A[end]
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = r = x = 0

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

print(ans)

Solution (Python):


import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))

right = 0
ans = 0
total = 0

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

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

    if n == 1:
        print(1)
        exit()

    
    
    
    ans = n
    l = 0
    now = a[0]
    for r in range(1, n):
        if now & a[r] == 0:
            now = now ^ a[r]
            continue

        now = now ^ a[r]
        for new_l in range(r-1, l-1, -1):
            if a[new_l] & a[r] != 0:
                break
        
            
            
        new_l += 1

        for i in range(l, new_l):
            now = now ^ a[i]

        ans += (r-l) * (r-l-1) // 2 - (r-new_l) * (r-new_l-1) // 2

        l = new_l

    r += 1
    ans += (r-l) * (r-l-1) // 2

    print(ans)

main()

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

    if n == 1:
        print(1)
        exit()

    
    
    
    ans = n
    l = 0
    now = a[0]
    for r in range(1, n):
        if now & a[r] == 0:
            now = now ^ a[r]
            continue

        now = now ^ a[r]
        for new_l in range(r-1, l-1, -1):
            if a[new_l] & a[r] != 0:
                break
        
            
            
        new_l += 1

        for i in range(l, new_l):
            now = now ^ a[i]

        ans += (r-l) * (r-l-1) // 2 - (r-new_l) * (r-new_l-1) // 2

        l = new_l

    r += 1
    ans += (r-l) * (r-l-1) // 2

    print(ans)

main()

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

r = 0
xor = 0
total = 0
cnt = 0
for l in range(N):
    while r < N and total + A[r] == xor ^ A[r]:
        total += A[r]
        xor ^= A[r]
        r += 1

    cnt += r - l
    
    total -= A[l]
    xor ^= A[l]
print(cnt)

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

l = 0
r = 0
s = 0 
res = 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):
import copy
N = int(input())
A = list(map(int, input().split()))
K = [0]*21
bin_num = format(A[0], 'b')
bin_num = bin_num[::-1]
for i in range(len(bin_num)):
    if bin_num[i] == "1":
        K[i] = 1
start = 0
end = 0
ans = 0
while(True):
    if start == N:
        break
    t = 0
    for j in range(end+1, N):
        K_ex = K.copy()
        bin_num = format(A[j], 'b')
        bin_num = bin_num[::-1]
        for l in range(len(bin_num)):
            if bin_num[l] == "1" and K[l] == 1:
                t = 1
            if bin_num[l] == "1":
                K[l] = 1
        if t == 1:
            K = K_ex.copy()
            bin_num = format(A[start], 'b')
            bin_num = bin_num[::-1]
            for p in range(len(bin_num)):
                if bin_num[p] == "1":
                    K[p] = 0
            end = j - 1
            break
    if t == 0:
        end = N - 1
    ans += end - start + 1
    start += 1
print(ans)

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

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

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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


r = 0  
cnt = 0
xorv = 0
sumv = 0
for l in range(0, N):
    while r < N and xorv ^ A[r] == sumv + A[r]:
        sumv += A[r]
        xorv ^= A[r]
        r += 1
    
    cnt += r - l
    if l == r:
        r += 1
    else:
        sumv -= A[l]
        xorv = sumv
print(cnt)

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

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

s = [0] * n
t = [0] * n

s[0] = a[0]
t[0] = a[0]

for i in range(1, n):
    s[i] = s[i-1] + a[i]
    t[i] = t[i-1] ^ a[i]

s = [0] + s
t = [0] + t 

ans = 0


l = 1
r = l
while l < n+1:
    
    if s[r] - s[l-1] == t[r] ^ t[l-1]:
        while True:
            
            if s[r] - s[l-1] == t[r] ^ t[l-1]:
                r += 1
                if r > n:
                    ans += r - l
                    r = n
                    break
            else:
                ans += r - l 
                break
    else:
        while True:
            
            if s[r] - s[l-1] == t[r] ^ t[l-1]:
                ans += r - l + 1
                break
            else:
                r -= 1
                if r == l:
                    ans += 1
                    r = l + 1
                    break

    l += 1

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
right,ans,sum_xor,sum=1,0,a[0],a[0]

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

Solution (Python):


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

total = a[0]
xor = a[0]
ans = 0
l = 0
r = 0

while 1:
    if xor == total:
        ans += r-l+1
        r += 1
        if r == n:
            break
        total += a[r]
        xor ^= a[r]
    else:
        total -= a[l]
        xor ^= a[l]
        l += 1
print(ans)

Solution (Python):
from operator import*
from copy import*
class TP:
    def __init__(self, cond, init=0, right=add, left=sub):
        self.cond = cond
        self.init = init
        self.next_right = right
        self.next_left = left
    
    def __call__(self, A, uniq=True):
        cond = self.cond
        next_right, next_left = self.next_right, self.next_left
        s = deepcopy(self.init)
        n = len(A)
        X = {}
        r = 0
        for l in range(n):
            if not uniq:
                X[l] = r
            while r < n and cond(s, A[r]):
                s = next_right(s, A[r])
                r += 1
                X[l] = r
            if l == r:
                r += 1
            else:
                s = next_left(s, A[l]) if l+1 != r else deepcopy(self.init)
        return list(X.items())
    
    def maximum(self, A):
        X = self.__call__(A)
        return max(r-l for l, r in X) if X else 0
    
    def count(self, A):
        X = self.__call__(A, False)
        return sum(r-l for l, r in X)
 
n, *a = map(int, open(0).read().split())
print(TP(lambda s, n: s + n == s ^ n).count(a))

Solution (Python):
def ind(S):
  L4=list()
  for i in range(len(S)):
    if S[len(S)-i-1]=="1":
      L4.append(i)
  return set(L4)
N=int(input())
L=list(map(int,input().split()))
L=[ind(bin(i)[2:]) for i in L]
ans=0
n=0
i=0
T=set()
while True:
  if i==N and n==N:
    break
  elif i==N:
    ans+=i-n
    n+=1
    continue
  if T&L[i]==set():
    T=T|L[i]
    ans+=1
    i+=1
  else:
    T=T-L[n]
    n+=1
    ans+=i-n
  if i==N and n!=N:
    n+=1
print(ans)

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

B=[[] for i in range(n)]
for i in range(n):
    B[i]= [int(j) for j in  bin(A[i])[2:]]
    B[i]= [0]*(20-len(B[i]))+B[i]

ans=n

R=[[] for i in range(n+1)]
R[0]=[0]*20
for i in range(n):
    R[i+1] = [l+k for l,k in zip(R[i], B[i])]



TR=[[0]*(n+1) for i in range(20)]
for i in range(n+1):
    for j in range(20):
        TR[j][i]=R[i][j]

from bisect import bisect_left as bi
for i in range(n,1,-1):
    now=R[i] ; 
    
    ans+=i-max([bi(TR[k],now[k]-1) for k in range(20)])-1
    

print(ans)

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

cnt, su, r = 0, 0, 0
for l in range(n):
    while r < n and su + a[r] == su ^ a[r]:
        su += a[r]
        r += 1
    cnt += r - l
    if l == r:
        r += 1
    else:
        su -= a[l]
print(cnt)

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

summ, right, left = 0, 0, 0
ans = 0

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

print(ans)

Solution (Python):
import sys

read = sys.stdin.buffer.read


N, *A = map(int, read().split())

ans = 0
right = 0
s = 0

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

    ans += right - left

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

print(ans)

Solution (Python):
import sys

read = sys.stdin.buffer.read


def main():
    N, *A = map(int, read().split())

    ans = 0
    right = 0
    s = 0

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

        ans += right - left

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    right = 0
    s = 0

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

        ans += right - left

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    right = 0
    s = 0

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

        ans += right - left

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    A = [list(map(int, f'{a:0>20b}')) for a in A]

    ans = 0
    right = 0
    digits = [0] * 20

    for left in range(N):
        while right < N and all(d + b <= 1 for d, b in zip(digits, A[right])):
            for i in range(20):
                digits[i] += A[right][i]
            right += 1

        ans += right - left

        if left == right:
            right += 1
        else:
            for i in range(20):
                digits[i] -= A[left][i]

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
def abc098_d():
    n = int(input())
    A = list(map(int, input().split()))
    ans = 0
    rt = 0
    total = 0
    for lf in range(n):
        while rt < n:
            if total ^ A[rt] == total + A[rt]:
                total += A[rt]
                rt += 1
            else:
                break
        ans += rt - lf
        if lf == rt: rt += 1
        else: total -= A[lf]
    print(ans)

if __name__ == '__main__':
    abc098_d()

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

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

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()))

to = [0]*N

for i in range(N-1):
  if i == 0:
    SUM = A[i]
  else:
    SUM -= A[i-1]
  for j in range(min(to[i-1]+1,N-1),N):
    if SUM+A[j] != SUM^A[j]:
      to[i]=j-1
      break
    if j == N-1:
      to[i] = j
      break
    SUM += A[j]
  
print(sum([max(0,to[i]-i) for i in range(N)])+N)

Solution (Python):

import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

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

    
    res = 0
    right = 0
    sumA = 0

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

        res += right - left
        if left == right:
            right += 1
        else:
            sumA -= A[left]

    print(res)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    A=list(mi())

    r = 0
    asum = 0
    xsum = 0
    ans = 0
    for l in range(N):
        while r < N and asum+A[r] == xsum^A[r]:
            asum += A[r]
            xsum ^= A[r]
            r += 1

        
        ans += r-l
        if l == r:
            r += 1
        else:
            asum -= A[l]
            xsum ^= A[l]
        
        
    print(ans)



    


if __name__ == "__main__":
    main()

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

ans = 0
S = 0
X = 0
end = -1

for i in range(N):
  while end < N-1:
    end += 1
    S += A[end]
    X ^= A[end]
    if S != X:
      S -= A[end]
      X ^= A[end]
      end -= 1
      break
  ans += end - i + 1
  S -= A[i]
  X ^= A[i]

print(ans)

Solution (Python):
N = int(input())
A = [0] + list(map(int, input().split()))

ans = 0
S = 0
X = 0
end = 0

for i in range(1, N+1):
  S -= A[i-1]
  X ^= A[i-1]
  if end == N:
    ans += end - i + 1
    continue
  if end < N:
    end += 1
  for j in range(end, N+1):
    S += A[j]
    X ^= A[j]
    if S != X:
      S -= A[j]
      X ^= A[j]
      end = j-1
      break
    if j == N:
      end = j
  ans += end - i + 1

print(ans)

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd


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

s=0
e=1
ans=n
acc=[0]*(n+1)
for i in range(n):
  acc[i+1]=acc[i]+a[i]
while True:
    if s==e:
      e+=1
      continue
    if s==n-1:
      
      break
    res=acc[e]-acc[s]
    for i in range(20):
        if res&(1<<i)!=0 and a[e]&(1<<i)!=0:
            s+=1
            ans+=(e-s)
            break
    else:
        e+=1
    if e==n:
      s+=1
      ans+=(e-s)
      e=n-1
print(ans)

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

al.append(0)

res = 0
r = 0
x = 0
y = 0


for l in range(n):

    while x == y and r<=n:
        x += al[r]
        y = y ^ al[r]
        r += 1

    r -= 1
    x -= al[r]
    y = y ^ al[r]

    res +=r-l
    x -= al[l]
    y = y^ al[l]
    if l ==r:
        r += 1

print(res)

Solution (Python):
n = raw_input()
ais = map(int , raw_input().split())
i = 0
j = 0
cumul = 0
r = 0
while(i < len(ais)):
	while(j < len(ais) and (cumul & ais[j] == 0)):
		cumul |= ais[j]
		j += 1
	r += j - i
	cumul ^= ais[i]
	i += 1
print r

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

r = 0
ans = 0
su = 0

for l in range(N):
  while (l == r or su+A[r]==su^A[r]) and r<N:
    su += A[r]
    r+=1
  ans += r - l
  su -= A[l]
print(ans)

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

rt = 0
res = 0
x = 0
s = 0

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

print(res)

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

xo = A[0]
l = 0
r = 1
ans = 0

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

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

ans = 0
w_xor,w_sum = A[0],A[0]
l,r = 0,0

while l < N and r < N:
  

  if w_xor == w_sum:
    if r < N-1:
    
      r += 1
      w_xor = w_xor ^ A[r]
      w_sum = w_sum + A[r]
      continue
    else:
      ans += 1+r-l
  else:
    
    ans += r-l
  w_xor = w_xor ^ A[l] 
  w_sum = w_sum - A[l]
  l += 1
  
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
l=0
r=1
t=a[0]
ans=0
 
while l<n:
  if r==n:
    ans+=r-l
    l+=1
    continue
  if t+a[r]==t^a[r]:
    t+=a[r]
    r+=1
  else:
    ans+=r-l
    t-=a[l]
    l+=1
print(ans)

Solution (Python):
n = int(input())
aas = list(map(int, input().split()))
acc = 0
res = 0
r = 0
for i in range(n):
    ok = True
    while r < n:
        s = format(aas[r],'020b')
        acc_s = format(acc,'020b')
        for j in range(20):
            if s[j] == '1':
                if acc_s[j] == '1':
                    ok = False
                    
        if ok:
            acc += aas[r]
            r += 1
        else:
            break
    if r < n:
        res += r - i
    else:
        res += r - i
    acc -= aas[i]
print(res)

Solution (Python):
from copy import deepcopy
from operator import add, sub

class TwoPointers:
    def __init__(self, cond, init=0, right=add, left=sub):
        self.cond = cond
        self.init = init
        self.next_right = right
        self.next_left = left
    
    def __call__(self, A, uniq=True):
        cond = self.cond
        next_right, next_left = self.next_right, self.next_left
        s = deepcopy(self.init)
        n = len(A)
        X = {}
        r = 0
        for l in range(n):
            if not uniq:
                X[l] = r
            while r < n and cond(s, A[r]):
                s = next_right(s, A[r])
                r += 1
                X[l] = r
            if l == r:
                r += 1
            else:
                s = next_left(s, A[l]) if l+1 != r else deepcopy(self.init)
        return list(X.items())
    
    def maximum(self, A):
        X = self.__call__(A)
        return max(r-l for l, r in X) if X else 0
    
    def count(self, A):
        X = self.__call__(A, False)
        return sum(r-l for l, r in X)

n, *A = map(int, open(0).read().split())
print(TwoPointers(lambda s, n: s + n == s ^ n).count(A))

Solution (Python):
from operator import add, sub
from operator import mul, floordiv
class Two_pointer:
    def __init__(self, cond, init=0, right=add, left=sub):
        self.cond = cond
        self.init = init
        self.next_right = right
        self.next_left = left
        
    def __call__(self, A):
        cond = self.cond
        next_right, next_left = self.next_right, self.next_left
        s = init = self.init
        n = len(A)
        X = {}
        r = 0
        for l in range(n):
            X[l] = r
            while r < n and cond(s, A[r]):
                s = next_right(s, A[r])
                r += 1
                X[l] = r
            if l == r:
                r += 1
            else:
                s = next_left(s, A[l]) if l+1 != r else init
        return list(X.items())

n, *A = map(int, open(0).read().split())
X = Two_pointer(lambda s, n: s + n == s ^ n)(A)
print(sum(r-l for l, r in X))

Solution (Python):
from operator import add, sub
from operator import mul, floordiv
class Two_pointer:
    def __init__(self, cond, init=0, right=add, left=sub):
        self.cond = cond
        self.s = init
        self.next_right = right
        self.next_left = left
        
    def __call__(self, A):
        s = self.s
        cond = self.cond
        next_right, next_left = self.next_right, self.next_left
        n = len(A)
        X = []
        r = 0
        for l in range(n):
            while r < n and cond(s, A[r]):
                s = next_right(s, A[r])
                X.append((l, r+1))
                r += 1
            if l == r:
                r += 1
            else:
                s = next_left(s, A[l])
        return X

n, *A = map(int, open(0).read().split())
X = Two_pointer(lambda s, n: s + n == s ^ n)(A)
print(sum(r-l for l, r in X))

Solution (Python):



N = int(input())
A = [0] + list(map(int,input().split()))


ruiseki_xor = [A[i] for i in range(N+1)]
for i in range(1,N+1,1):
    ruiseki_xor[i]=ruiseki_xor[i-1]^A[i]


ruiseki = [0]*(N+1)
for i in range(1,N+1,1):
    ruiseki[i]=ruiseki[i-1]+A[i]

ans = 0
cersol = 1
for i in range(1,N+1,1):
    ans += cersol-i
    for j in range(cersol,N+1,1):
        if ruiseki[j]-ruiseki[i-1] == ruiseki_xor[j]^ruiseki_xor[i-1]:
            ans += 1
            cersol = j
        else:
            cersol = j
            break
        
        

print(ans)

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

csum=[0]*(n+1)
xor=[0]*(n+1)

for i in range(n):
    csum[i+1]=csum[i]+alst[i]
    xor[i+1]=xor[i]^alst[i]

ans=0

for i in range(n):
    left=0
    right=i

    while abs(right-left)>0:
        center=(right+left)//2

        s=csum[i+1]-csum[center]
        x=xor[i+1]^xor[center]

        if s==x:
            right=center
        else:
            left=center+1
    
    ans+=i-right+1

print(ans)

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

ans = 0
l = r = 0
total = A[0]
xor = A[0]

while True:
    if xor == total:
        ans += r - l + 1
        r += 1
        if r == N:
            break
        total += A[r]
        xor ^= A[r]
    else:
        total -= A[l]
        xor ^= A[l]
        l += 1

print(ans)