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):
import math
n = int(input())
a = [int(x) for x in input().split()]

bit = int(math.log2(max(a+[1])))+1
key = [0]*bit
ans = 0
ans_bef = 0
for i in range(n):
  value = a[i]
  max_len = ans_bef
  for j in range(bit):
    if value%2 == 1:
      if max_len > key[j]:
        max_len = key[j]
      key[j] = 0
    else:
      key[j] += 1
    value //= 2
  ans_bef = max_len+1
  ans += max_len
      
ans += n
print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
l, r, SumA, ans = 0, 0, 0, 0

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

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

nowi = 0
nowj = 0
prej = -1

nowX = 0
nowS = 0
ans = 0

while nowj < N:
    
    nowS += A[nowj]
    nowX ^= A[nowj]
    if nowX == nowS:
        nowj += 1
    else:
        
        ans += (prej - nowi+1)*(nowj - prej - 1) + (nowj - prej - 1)*(nowj - prej)//2
        prej = nowj - 1
        while nowS != nowX:
            
            nowS -= A[nowi]
            nowX ^= A[nowi]
            nowi += 1
        nowj += 1
ans += (prej - nowi+1)*(nowj - prej - 1) + (nowj - prej - 1)*(nowj - prej)//2
print(ans)

Solution (Python):

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


class CumSum1d:
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        from itertools import accumulate
        self.ls_accum = [0] + list(accumulate(ls))

    def total(self, i, j):
        
        return self.ls_accum[j] - self.ls_accum[i]


class CumXor1d:
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        self.ls_accum = [0]
        for l in ls:
            self.ls_accum.append(l ^ self.ls_accum[-1])

    def total(self, i, j):
        
        return self.ls_accum[j] ^ self.ls_accum[i]


from collections import deque
N = int(input())
A = read_ints()






cumsum = CumSum1d(A)
cumxor = CumXor1d(A)

ids = []
r_pre = 0
for l in range(0, N):
    r = max(r_pre, l + 1)  
    while r <= N and cumsum.total(l, r) == cumxor.total(l, r):
        r += 1  
    r -= 1  
    if r != r_pre:
        r_pre = r
        ids.append((l, r))


ans = 0
for l, r in ids:
    n = r - l
    ans += n + n * (n - 1) // 2

if len(ids) > 1:
    for (_, r), (l, _) in zip(ids, ids[1:]):
        n = max(0, r - l)
        ans -= n + n * (n - 1) // 2


print(ans)

Solution (Python):

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


class CumSum1d:
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        from itertools import accumulate
        self.ls_accum = [0] + list(accumulate(ls))

    def total(self, i, j):
        
        return self.ls_accum[j] - self.ls_accum[i]


class CumXor1d:
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        self.ls_accum = [0]
        for l in ls:
            self.ls_accum.append(l ^ self.ls_accum[-1])

    def total(self, i, j):
        
        return self.ls_accum[j] ^ self.ls_accum[i]


from collections import deque
N = int(input())
A = read_ints()






cumsum = CumSum1d(A)
cumxor = CumXor1d(A)

ids = []
r_pre = 0
for l in range(0, N):
    r = max(r_pre, l + 1)  
    while r <= N and cumsum.total(l, r) == cumxor.total(l, r):
        r += 1  
    if r != r_pre:
        r_pre = r
        ids.append((l, r - 1))


ans = 0
for l, r in ids:
    n = r - l
    ans += n + n * (n - 1) // 2

if len(ids) > 1:
    for (_, r), (l, _) in zip(ids, ids[1:]):
        n = max(0, r - l)
        ans -= n + n * (n - 1) // 2


print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from itertools import product
INF = 10**9
MOD = 10**9 + 7

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

    bit = 0
    ans = 0
    right = 0
    for left in range(n):
        while right < n:
            num = a[right]
            if num & bit == 0:
                bit += num
                right += 1
            else:
                bit -= a[left]
                break
        ans += right - left
    
    print(ans)
if __name__=='__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
from itertools import product
INF = 10**9
MOD = 10**9 + 7

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

    ans , right = 0 , 0 
    cnt_1 = [0] * 20
    power = [pow(2,i) for i in range(20)]
    keta = [[0]*20 for _ in range(n)]

    for left in range(n):
        flag = False
        while right < n:
            for i in range(20):
                if (a[right]>>i)&1:
                    cnt_1[i] += 1
                    keta[right][i] = 1
                    a[right] ^= power[i]
                if cnt_1[i] == 2:
                    flag = True
            
            if flag:
                break
            else:
                right += 1

        for i in range(20):
            if keta[left][i]:
                cnt_1[i] -= 1
        ans += right - left
        if right - left == 1:
            right += 1
    
    print(ans)
if __name__=='__main__':
    main()

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

ans = 0
xor1 = a[0]
sum1 = a[0]
right = 1

for left in range(n):
    while right < n and (a[right] + sum1 == a[right] ^ xor1):
        sum1 += a[right]
        xor1 ^= a[right]
        right += 1
    ans += right - left
    if right == left: right += 1
    else:
        sum1 -= a[left]
        xor1 = xor1 ^ a[left]

print(ans)

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

right = 0  
res = 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

    
    res += right - left

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

print(res)

Solution (Python):
N, *A = map(int, open(0).read().split())
l = 0
r = 0
s = A[l]
x = A[l]
ans = 0
flag = True
for l in range(N):
  while s==x and flag:
    r += 1
    if r==N:
      flag = False
      break
    s += A[r]
    x ^= A[r]
  ans += r-l
  s -= A[l]
  x ^= A[l]
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
l=[-1]*20
a=0
t=-1
for i in range(N):
    for j in range(20):
        if (A[i]>>j)%2:
            if t<l[j]:
                t=l[j]
            l[j]=i
    a+=i-t
print(a)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
ans = 1
r = 1
AA = A[0]
for i in range(1,N):

  r+=1
  if ( AA & A[i] == 0 ):
    AA |= A[i]
  else:
    for l in range(i-r+1,i):
      r -= 1
      AA ^= A[l]

      if ( AA & A[i] == 0 ):
        break
    AA |= A[i]
  ans += r

print(ans)

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

N = int(input())
A = list(map(int, input().split()))
s = 0
t = 0
cur = 0
ans = 0
while s < N:
    while t < N and cur + A[t] == cur ^ A[t]:
        cur += A[t]
        t += 1
    ans += t - s
    cur -= A[s]
    s += 1
print(ans)

Solution (Python):
N = int(input())

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

S = A[0]
X = A[0]
l = 0
r = 0
count = 0

while r < N and l <= r:
    if S == X and r < N-1:
        r += 1
        S += A[r]
        X = X ^ A[r]
    elif S == X and r == N-1:
        count += r-l+1
        l += 1
        S -= A[l-1]
        X = X ^ A[l-1]
    else:
        count += r-l
        l += 1
        S -= A[l-1]
        X = X ^ A[l-1]
    

print(count)

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

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

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

ans = 0
t = 0
S = [0]*30

def func(cur, S):
    cur_bi = list(format(cur, 'b'))
    cur_bi = list(reversed(cur_bi))
    flag = True
    for i in range(len(cur_bi)):
        if cur_bi[i] == '1' and S[i] == 1:
            flag = False
            break
    return flag

for s in range(n):
    while t < n and func(A[t], S):
        cur = A[t]
        cur_bi = list(format(cur, 'b'))
        cur_bi = list(reversed(cur_bi))
        for i in range(len(cur_bi)):
            if cur_bi[i] == '1':
                S[i] = 1
        t += 1
    ans += t-s
    if s == t:
        t += 1
    else:
        cur = A[s]
        cur_bi = list(format(cur, 'b'))
        cur_bi = list(reversed(cur_bi))
        for i in range(len(cur_bi)):
            if cur_bi[i] == '1':
                S[i] = 0

print(ans)

Solution (Python):


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

"""
org_A=A[1:N]

judge=True
for item in org_A:
    if item!=0:
        judge=False
        break
if judge:
    print(N*(N+1)//2)
    exit()
"""

ans=0

wa10=A[1]
wa2=A[1]
front=1
end=0
count=0
while front!=N+1 or end!=N:
    
    
    temp=front-end-1
    if wa10==wa2 and front!=N+1:
        ans+=temp
        front+=1
        wa10+=A[front]
        wa2^=A[front]

    else:
        end+=1
        count=0
        wa10-=A[end]
        wa2^=A[end]
    
    
print(ans+N)

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

right = left = 0
xor_sum = 0
total = 0
while right < N:
    if xor_sum ^ A[right] == xor_sum + A[right]:
        xor_sum += A[right]
        right += 1
        total += right - left
    elif right == left:
        right += 1
        left += 1
    else:
        xor_sum -= A[left]
        left += 1
print(total)

Solution (Python):

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

bi = [[0]*20 for _ in range(N)]

state = [False]*20

for i,a in enumerate(A):
    tmp = a
    idx = 0
    while tmp>0:
        bi[i][idx] = tmp%2
        tmp >>= 1
        idx += 1

ans = 0
left = 0
right = 1

def upt(state,b):
    for i in range(20):
        if b[i]:
            state[i] = True
    return state
    
def rmv(state,b):
    for i in range(20):
        if b[i]:
            state[i] = False
    return state

def judge(state,b):
    for i in range(20):
        if state[i] and b[i]:
            return False
    return True

state = upt(state,bi[0])

while right<N:
    if judge(state,bi[right]):
        state = upt(state,bi[right])
        right += 1
    else:
        ans += right-left
        state = rmv(state,bi[left])
        left += 1

L = right - left
ans += L*(L+1)//2

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
c=0
t=0
l=0
for r in range(N):
  if t+A[r]==t^A[r]:
    t+=A[r]
  else:
    while t+A[r]!=t^A[r]:
      t-=A[l]
      c+=r-l
      l+=1
    t+=A[r]
c+=(N-l)*(N-l+1)//2
print(c)

Solution (Python):
def solve():
    N = int(input())
    A = [int(x) for x in input().split()]
    right = 0
    sum = 0
    res = 0
    for left in range(N):
        while right < N and (right <= left or sum^A[right] == sum + A[right]):
            sum += A[right]
            right += 1
        res += (right - left)
        if right == left: right += 1
        else:
            sum -= A[left]
    return res

if __name__ == '__main__':
    print(solve())

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

r,l=0,0
ans=0
sum_a=0

while r<n:
    if sum_a+a[r]==(sum_a^a[r]):
        sum_a+=a[r]
        r+=1
        ans+=r-l
    elif l==r:
        l+=1
        r+=1
    else:
        sum_a-=a[l]
        l+=1
print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
l = 0; r = 0
bit = [False] * 22
res = 0
def f(n):
    return "".join(list(bin(n))[2:])
def back(l):
    c = f(a[l])[::-1]
    for i,t in enumerate(c):
        if t == '1':
            bit[i] = False
def check(c):
    for i,t in enumerate(c):
        if t == '1' and bit[i]:
            return False
    return True

def write(c):
    for i,t in enumerate(c):
        if t == '1': bit[i] = True

while l < n and r < n+1:
    if r == n:
        res += r-l
        back(l)
        l += 1
        continue
    now = f(a[r])[::-1]
    if check(now):
        write(now)
        r += 1
    else:
        res += r-l
        back(l)
        l += 1
    
res += r-l
print(res)

Solution (Python):


scale = 20

n = int(input())
raw = list(map(int,input().split()))
a = [[] for _ in range(scale)]
for i in range(n):
  x = raw[i]
  for d in range(scale):
    a[d].append(x%2)
    x //= 2

c = []
for d in range(scale):
  b = []
  tmp = 0
  for i in range(n):
    if a[d][i] == 1:
      tmp += 1
      if tmp == 2:
        b.append(i)
        break
  else:
    b += [n for _ in range(n)]
    c.append(b)
    continue
  for i in range(1,n):
    if a[d][i-1] == 0:
      b.append(b[-1])
      continue
    for j in range(b[-1]+1,n):
      if a[d][j] == 1:
        b.append(j)
        break
    else:
      b += [n for _ in range(i,n)]
      break
  c.append(b)

ans = []
for l in range(n):
  now = []
  for d in range(scale):
    now.append(c[d][l])
  ans.append(min(now)-l)

print(sum(ans))

Solution (Python):
N=int(input())
A=[0]+list(map(int,input().split()))+[0]
x=[0]
for i in range(1,2*(10**5+3)):
    x.append(x[-1]+i)

X=0

S=0
E=0
SUM=0
ans=0
for i in range(10**6):
    if S==N+1:
        ans+=x[(S-E-1)]
        break
    if SUM+A[S+1]==SUM^A[S+1]:
        SUM+=A[S+1]
        S+=1
    else:
        ans+=(S-E)
        SUM-=A[E+1]
        E+=1
    
print(ans)

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

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


def ch(x,y):
    lx=len(bin(x))-2
    ly=len(bin(y))-2
    L=min(lx,ly)
    for i in range(L):
        if (x&1) and (y&1):
            return False
        x=x>>1
        y=y>>1
    return True

ans=0
temp=0
l=0
for i in range(N):
    if ch(temp,A[i]):
        temp+=A[i]
        L=i+1-l
        ans+=L
    else:
        while not (ch(temp,A[i])):
            temp-=A[l]
            l+=1
        temp+=A[i]
        L=i+1-l
        ans+=L


print(ans)

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

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

print(ans)

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]


def judge(x, y):
    return x & y == 0


l = 0
r = -1
x = 0
ans = 0
while l < N:

    while r + 1 < N and judge(x, A[r + 1]):
        x ^= A[r + 1]
        r += 1

    ans += r - l + 1
    x ^= A[l]
    l += 1
print(ans)

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): 
    n = int(input())
    a = list(map(int,input().split()))
    tmp = 0
    ans = 0
    r = 0
    for l in range(n):
        while r < n and tmp ^ a[r] == tmp + a[r]:
            tmp += a[r]
            r += 1
        ans += r-l
        if l == r:
            r += 1
        else:
            tmp -= a[l]
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): 
    n = int(input())
    a = list(map(int,input().split()))
    tmp = 0
    ans = 0
    r = 0
    for l in range(n):
        while r < n and tmp ^ a[r] == tmp + a[r]:
            tmp += a[r]
            r += 1
        ans += r-l
        if l == r:
            r += 1
        else:
            tmp -= a[l]
    print(ans)
if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    
    bit = 0
    r = 0
    ans = 0
    for l in range(N):
        while r < N:
            num = a[r]
            if num & bit == 0:
                bit += num
                r += 1
            else:
                num = a[l]
                bit -= num
                break
            ans += r-l
    
    print(ans)
    
if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    
    le = max(a).bit_length()
    bin = [0 for _ in range(le)]
    l,r = 0,0
    ans = 0
    while r < N:
        num = a[r]
        for i in range(le):
            bin[i] += num%2
            num //= 2
        if 2 not in bin:
            ans += r-l+1
            r += 1
        else:
            while (l < r and 2 in bin):
                num = a[l]
                for i in range(le):
                    bin[i] -= num%2
                    num //= 2
                l += 1
            ans += r-l+1
            r += 1

    print(ans)
    
if __name__ == "__main__":
    main()

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




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


if __name__ == "__main__":
    main()

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): 
    n = int(input())
    a = list(map(int,input().split()))
    r = 0
    pinf = 0
    ans = 0
    for l in range(n):
        while (r<n)and pinf ^ a[r] == pinf + a[r]:
            pinf += a[r]
            r += 1
        ans += r-l
        if l == r:
            r += 1
        else:
            pinf -= a[l]
    
    print(ans)
if __name__ == "__main__":
    main()

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

i, j = 0, 0
s = 0
ans = 0
while i < N:
    if s | A[i] != s + A[i]:
        s -= A[j]
        j += 1
    else:
        s += A[i]
        i += 1
        ans += i - j
print(ans)

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

xor = 0
ans = 0

right = 0

for l in range(n):
    if l>0:
        xor -= a[l-1]
    for r in range(right,n):
        if xor^a[r] == xor+a[r]:
            if r==n-1:
                ans += r-l+1
                right = max(r,l+1)
            else:
                xor += a[r]
        else:
            ans += r-l
            right = max(r,l+1)
            break

print(ans)

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ret = N
    i = 0
    xor_A = A[0]
    j = 1
    while i < N-1:
        tail_flag = False
        
        if i == j:
            xor_A = A[i]
            j = i+1
        while j < N:
            if xor_A ^ A[j] == xor_A+A[j]:
                tail_flag = True
                
                xor_A = xor_A ^ A[j]
                ret += j-i
            else: 
                tail_flag = False
                break
            
            if j != N-1: 
                j += 1
            else: break
        
        xor_A ^= A[i]
        i += 1
        if tail_flag and j == N-1: break
                
    print(ret)
    
solve()

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(input()) 
def ifn(): return float(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def fmn(): return map(float, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, input().split())) 
def join(l, s=''): return s.join(l) 
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 comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD

N = iin()
A = iln()

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
suma = 0
left = 0
right = 0
count = 0
while left != N:
    if right == N:
        count += right-left
        suma -= A[left]
        left += 1
    elif suma+A[right] == suma^A[right]:
        suma += A[right]
        right += 1
    else:
        count += right - left
        suma -= A[left]
        left += 1
print(count)

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

l, r = 0, 0
sum = 0
ans = 0
while r < n:
    
    if sum ^ a[r] == sum+a[r]:
        sum += a[r]
        r += 1
        ans += r - l
    
    elif l == r:
        l += 1
        r += 1
    
    else:
        sum -= a[l]
        l += 1
    
print(ans)

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

ruiseki = [0] * (n + 1)
ruiseki2 = [0] * (n + 1)
for i in range(n):
    ruiseki[i + 1] = ruiseki[i] + a[i]
    ruiseki2[i + 1] = ruiseki2[i] ^ a[i]

def solve(l, r):
    return ruiseki[r] - ruiseki[l] == ruiseki2[r] ^ ruiseki2[l]
  
ans = 0
for i in range(n):
    ok = i
    ng = n + 1
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if solve(i, mid):
            ok = mid
        else:
            ng = mid
    ans += ok - i
print(ans)

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(input()) 
def ifn(): return float(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def fmn(): return map(float, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, input().split())) 
def join(l, s=''): return s.join(l) 
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 comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD

N = iin()
A = iln()

right = 0
ans = 0
total = 0
xtotal = 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 left == right: right+=1
    else:
        total -= A[left]
        xtotal ^= A[left]
print(ans)