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):
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007
"""

    n,k,m=LI() 
    
    
    
    
    N=I()
    p=LIR(N)
    print(n,k,m,p)
"""
from itertools import accumulate

def resolve():
    n=I()
    a=LI()
    asum = list(accumulate(a))
    ans=0
    right=0
    buf=0
    for left in range(n):
        
        
        while right<n and ((asum[right]-asum[left-1] if left>0 else asum[right])==(buf^a[right] if not(left==0 and right==0) else a[right])):
            buf=buf^a[right]
            right+=1
        ans+=right-left
        if left==right:
            right+=1
        else:
            buf=buf^a[left]

    print(ans)

    return
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4
2 5 4 6"""
        output = """5"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """9
0 0 0 0 0 0 0 0 0"""
        output = """45"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """19
885 8 1 128 83 32 256 206 639 16 4 128 689 32 8 64 885 969 1"""
        output = """37"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

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

def func(a,b):
    for i in range(21):
        if (a>>i)&(b>>i): 
            return False
    return True

def add_point(length):
    res = 0
    for i in range(1,length):
        res += i
    return res

a,b,count,ans = 0,1,0,0
host = lst1[0]

while True:
    if b >= n and a >= n:
        break
    while  b<n and func(host,lst1[b]):
        host = host^lst1[b]
        b += 1
    host = host^lst1[a] 
    if b -a > 1:
        ans += b-a-1
    a += 1

ans += n
print(ans)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    x = []
    q = 0
    ans_list = []
    x = a[0]
    s = a[0]
    for i in range(n):
        while True:
            if q == n-1:
                ans_list.append((i,q))
                break
            else:
                tx = x^a[q+1]
                ts = x+a[q+1]
                if tx != ts:
                    ans_list.append((i,q))
                    x ^= a[i]
                    s -= a[i]
                    if i == q:
                        q += 1
                        x = a[q]
                        y = a[q]
                    break
                else:
                    q += 1
                    x = tx
                    s = ts
    ans = 0
    for i in ans_list:
        ans += i[1]-i[0]+1
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
lists=list(map(int,input().split()))
ans =0
SUMS=0
index=0
for l in range(n):
    while index < l or index< n and SUMS ^ lists[index] == SUMS + lists[index]:
        SUMS ^= lists[index]
        index+= 1
    ans += index-l
    SUMS ^= lists[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 < 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):
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))

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

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
xor = a[0]
sm = a[0]
r = 1
ans = 0
for l in range(n):
  if l == r:
    xor = a[r]
    sm = a[r]
    r += 1
  while sm == xor and r <= n-1:
    xor = xor^a[r]
    sm = sm+a[r]
    ans += r-l
    r += 1
  if sm == xor:
    ans += 1
  xor = xor^a[l]
  sm = sm-a[l]
print(ans)

Solution (Python):
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))

cnt = 0
right = 0
acc = a[0]
xor = a[0]
for left in range(n):
    while right < n:
        if right + 1 >= n or acc + a[right+1] != xor ^ a[right+1]:
            break
        right += 1
        acc += a[right]
        xor ^= a[right]
    if acc == xor:
        
        cnt += (right - left + 1)
    acc -= a[left]
    xor ^= a[left]
print(cnt)

Solution (Python):
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))

cnt = 0
right = 0
acc = a[0]
xor = a[0]
for left in range(n):
    while right < n:
        if right + 1 >= n or acc + a[right+1] != xor ^ a[right+1]:
            break
        right += 1
        acc += a[right]
        xor ^= a[right]
    if acc == xor:
        
        cnt += (right - left + 1)
    acc -= a[left]
    xor ^= a[left]
print(cnt)

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

def addable(a,b):
  if a<b:
    a,b=b,a
  sa=bin(a)[2:]
  sb=bin(b)[2:].zfill(len(sa))
  for i in range(len(sa)):
    if sa[i]=="1" and sb[i]=="1":
      return False
  return True
  
right=1
ans=0
cur=A[0]
for left in range(N):
  while right<N and addable(cur,A[right]):
    cur|=A[right]
    right+=1
  ans+=(right-left)
  
  if left==right:
    right+=1
  else:
    cur-=A[left]
  
print(ans)

Solution (Python):

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

l=0
r=1
tmp=a[0]
ans=0

while l<n:
    if r==n:
        ans+=(r-l)
        l+=1
        continue
    if tmp+a[r]==tmp^a[r]:
        tmp=tmp+a[r]
        r+=1
    else:
        ans+=(r-l)
        tmp=tmp-a[l]
        l+=1      

print(ans)

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

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

ans = 0
r = 0
bit_check = 0
for l in range(n):
    while r <= n-1:
        num = A[r]
        if num & bit_check == 0:
            bit_check |= num
            r += 1
        else:
            bit_check -= A[l]
            break
    ans += r - l

print(ans)

Solution (Python):
import sys

n, *a = map(int, sys.stdin.read().split())

cumsum = [0] + a
cumxor = cumsum.copy()
for i in range(1, n):
    cumsum[i+1] += cumsum[i]
    cumxor[i+1] ^= cumxor[i]

def is_ok(l, r):
    s = cumsum[r] - cumsum[l-1]
    x = cumxor[r] ^ cumxor[l-1]
    return s == x

def main():
    res = 0
    l = r = 1
    flag = False
    while l <= n:
        if is_ok(l, r):
            if r == n:
                res += r - l + 1
                l += 1
                flag = False
            else:
                r += 1
                flag = True
        else:
            if flag:
                res += r - 1 - l + 1
            else:
                res += r - l + 1
            l += 1
    return res
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import sys

n, *a = map(int, sys.stdin.read().split())

cumsum = [0] + a
cumxor = cumsum.copy()
for i in range(1, n):
    cumsum[i+1] += cumsum[i]
    cumxor[i+1] ^= cumxor[i]

def is_ok(l, r):
    s = cumsum[r] - cumsum[l-1]
    x = cumxor[r] ^ cumxor[l-1]
    return s == x

def main():
    res = 0
    l = r = 1
    flag = False
    while l <= n and r <= n:
        if is_ok(l, r):
            if r == n:
                res += r - l + 1
                l += 1
                flag = False
            else:
                flag = True
                r += 1
        else:
            if flag:
                res += r - 1 - l + 1
            else:
                res += r - l + 1
            l += 1
    return res
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import sys

n, *a = map(int, sys.stdin.read().split())

cumsum = [0] + a
cumxor = cumsum.copy()
for i in range(1, n):
    cumsum[i+1] += cumsum[i]
    cumxor[i+1] ^= cumxor[i]

def is_ok(l, r):
    s = cumsum[r] - cumsum[l-1]
    x = cumxor[r] ^ cumxor[l-1]
    return s == x

def main():
    res = 0
    for l in range(1, n+1):
        lo = l - 1; hi = n+1
        while lo + 1 < hi:
            r = (lo + hi) // 2
            if is_ok(l, r):
                lo = r
            else:
                hi = r
        res += lo - l + 1
            
    return res
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 0
    ri = 0
    cur_sum = 0
    for le in range(N):
        while ri < N and cur_sum + A[ri] == cur_sum ^ A[ri]:
            cur_sum += A[ri]
            ri += 1
        ans += ri - le
        if le == ri:
            ri += 1
        else:
            cur_sum -= A[le]
    print(ans)


if __name__ == '__main__':
    main()

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

result = 0
r = 0
xs = A[0]
cs = A[0]
for l in range(N):
    while r < N - 1 and xs ^ A[r + 1] == cs + A[r + 1]:
        r += 1
        xs ^= A[r]
        cs += A[r]
    result += r - l + 1
    xs ^= A[l]
    cs -= A[l]
print(result)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
cnt=0
r=0
sum=0
for l in range(N):
    while r<N and sum^a[r]==sum+a[r]:
        sum+=a[r]
        r+=1
        if r>=N:break
    cnt+=r-l
    if l==r:
        r+=1
    else:
        sum-=a[l]
print(cnt)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    l = 0
    now = 0
    ans = 0
    for r,a in enumerate(A):
        while now&a:
            now -= A[l]
            l+=1
        now += a
        ans += r-l+1
    print(ans)
if __name__ == '__main__':
    main()

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

N = int(input())
A = [int(i) for i in input().split()]

answer = 0
right = 0
lrsum = 0
for left in range(N):
    while right < N and (lrsum ^ A[right]) == (lrsum + A[right]):
        lrsum += A[right]
        right += 1
    answer += right - left
    if left == right:
        right += 1
    else:
        lrsum -= A[left]

print(answer)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
start, end = 0, 1
now = a[0]
ans = 0
while end < n:
  NEXT = a[end]
  if now + NEXT == now ^ NEXT:
    now += NEXT
    end += 1
  else:
    LEN = end - start
    ans += LEN
    now -= a[start]
    start = start + 1
LEN = end - start
ans += LEN * (LEN+1) // 2
print(ans)

Solution (Python):
"""
多分またバグらせる
"""


N = int(input())
As = list(map(int, input().split()))
res = 0
l,r = 0, 0
val = As[l]
for l in range(N):
    cnt = 0
    
    if l == r:
        r += 1
        val = As[l]
    
    elif r-(l-1) > 1:
        val -= As[l-1]
    
    
    while (r < N and val^As[r] == val+As[r]):
        val += As[r]
        r += 1
    
    
    res += (r-l)
print(res)

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

ans = 0
now = 0
while True:
    while right < n and now + a[right] == now ^ a[right]:
        now += a[right]
        right += 1

    if left >= n:
        break

    ans += right - left
    now -= a[left]
    left += 1

print(ans)

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

L, R = 0, 0
S = A[0]
T = A[0]

answer = 0
while L < N and R < N:
  
  if S == T:
    answer += R - L + 1
    R += 1
    if R > N - 1:
      break
    S += A[R]
    T ^= A[R]
  else:
    S -= A[L]
    T ^= A[L]
    L += 1
  
print(answer)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
bitlist=[]
for i in range(n):
  bit=[]
  num=l[i]
  for j in range(20):
    bit.append(num%2)
    num//=2
  bitlist.append(bit)
left=0
right=0
b=True
ans=1
now={}
for i in range(20):
  if bitlist[0][i]==1:
    now[2**i]=1
  else:
    now[2**i]=0
b=1
while right<n:
  if b==1:
    right+=1
    if right==n:
      break
    for i in range(20):
      if bitlist[right][i]==1:
        now[2**i]+=1
        if now[2**i]>=2:
          b=0
    if b==1:
      ans+=right-left+1
  else:
    b1=1
    for i in range(20):
      if bitlist[left][i]==1:
        now[2**i]-=1
      if now[2**i]>=2:
        b1=0      
    left+=1
    if b1==1:
      b=1
      ans+=right-left+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()))
bit_acc = [[0 for i in range(21)] for j in range(n+1)]
for i in range(1,n+1):
    k = format(a[i-1], '021b')
    for j in range(len(k)):
        if k[j] == "1":
            bit_acc[i][j] = bit_acc[i-1][j] + 1
        else:
            bit_acc[i][j] = bit_acc[i-1][j]
right = 1
left = 0
ans = 0
while left <= n:
    flag = True
    for j in range(21):
        if bit_acc[right][j] - bit_acc[left][j] >= 2:
            
            ans += right - 1 - left
            left += 1
            flag = False
            break
    if flag:
        if right < n:
            right += 1
        else:
            
            ans += right - left
            left += 1
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls = ril()
left = 0
s0 = 0
s1 = 0
res = 0
for right, x in enumerate(ls):
    s0 += x
    s1 ^= x
    while s0 != s1:
        s0 -= ls[left]
        s1 ^= ls[left]
        left += 1
    res += right - left + 1
print(res)

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls = ril()
left = 0
s0 = 0
s1 = 0
res = 0
for right, x in enumerate(ls):
    s0 += x
    s1 ^= x
    while left <= right and s0 != s1:
        s0 -= ls[left]
        s1 ^= ls[left]
        left += 1
    res += right - left + 1
print(res)

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

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

    ans += (right-left)

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

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

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

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

Solution (Python):
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
start = 0
end = 1
a_ls = [bin(i)[2:].zfill(20) for i in a_ls] + ["2" * 20]
dic = {i : 0 if j == "0" else 1 for i,j in enumerate(a_ls[0])}
cnt = 0
while start < n and end <= n:
    flg = True
    a = a_ls[end]
    for i, j in enumerate(a):
        if dic[i] + int(j) > 1:
            flg = False
    if flg:
        for i, j in enumerate(a):
            dic[i] += int(j)
        end += 1
    else:
        cnt += (end - start - 1)
        for i, j in enumerate(a_ls[start]):
            dic[i] -= int(j)
        start += 1
        if end == start:
            for i, j in enumerate(a):
                dic[i] += int(j)
            end += 1
print(cnt + n)

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

xorsum = 0
right = 0
ans = 0

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

print(ans)

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

xorsum = A[0]
right = 0
ans = 0
for left in range(N):
    if right < N-1:
        while xorsum+A[right+1]==xorsum^A[right+1]:
            right += 1
            xorsum += A[right]
            if right == N-1:
                break
        xorsum -= A[left]
    ans += right-left+1
    
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=format(a[i],'022b')
A=[[0 for i in range(22)] for j in range(n+1)]
for i in range(n):
  for j in range(22):
    if a[i][j]=='1':
      A[i+1][j]=A[i][j]+1
    else:
      A[i+1][j]=A[i][j]

ct=0
right=1
for i in range(n):
  flag=0
  if i>right:
    right=i
  for j in range(right,n+1):
    check=0
    for k in range(22):
      if A[j][k]-A[i][k]<=1:
        check+=1
    if check!=22:
      right=j-1
      ct+=right-i
      flag=1
      break
  if flag==0:
    right=j
    ct+=right-i
print(ct)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=format(a[i],'022b')
A=[[0 for i in range(22)] for j in range(n+1)]
for i in range(n):
  for j in range(22):
    if a[i][j]=='1':
      A[i+1][j]=A[i][j]+1
    else:
      A[i+1][j]=A[i][j]

ct=0
right=1
for i in range(n):
  flag=0
  for j in range(right,n+1):
    check=0
    for k in range(22):
      if A[j][k]-A[i][k]<=1:
        check+=1
    if check!=22:
      right=j-1
      ct+=right-i
      flag=1
      break
  if flag==0:
    right=j
    ct+=right-i
print(ct)

Solution (Python):
n,*a=map(int,open(0).read().split())
ans=n; s=a[0]; r=0
for l in range(n-1):
    while r<n-1 and not(s&a[r+1]):
        s^=a[r+1];r+=1
    ans+=r-l;s^=a[l]
print(ans)

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

Solution (Python):
def examD():
    N = I()
    A = LI()
    ans = 0; l = 0; r = 0
    cur = 0
    while l < N:
        while r < N:
            if cur&A[r]==0:
                cur +=A[r]
                ans += (r-l+1)
            else:
                break
            r += 1

        cur ^=A[l]
        l +=1
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Solution (Python):
N = int(input())
INF = 1<<22
a = [int(c) for c in input().split()]+[INF]
l = 0
r = 1
s = a[l]
x = a[l]
ans = 0
for l in range(N):
  if l==r:
    r += 1
  while r<=N:
    if s!=x:
      break

    s += a[r]
    x ^= a[r]
    r += 1
  s -= a[l]
  x ^= a[l]
  ans += r-l-1

print(ans)

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    right = 1
    xor = A[0]
    sum = A[0]
    ans = 0
    for left in range(N):
        while right < N and xor ^ A[right] == sum + A[right]:
            xor ^= A[right]
            sum += A[right]
            right += 1

        ans += right - left

        if left == right:
            right += 1

        xor ^=A[left]
        sum -=A[left]
    print(ans)
    
    return


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

r,S,R=0,0,0

for l in range(N):
  while r<N:
    if S&A[r]==0:
      S|=A[r]
      r+=1
    else:
      break
  R+=r-l
  S&=~A[l]

print(R)

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

head = 0
tail = 0
sub = 0
ll = 0
ans = 0
while True:
    if sub + al[tail] == sub ^ al[tail]:
        ll += 1
        if tail == n-1:
            for i in range(ll+1):
                ans += i
            break
        sub += al[tail]
        tail += 1
    else:
        ans += ll
        ll -= 1
        sub -= al[head]
        head += 1

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    ans=0
    now=0
    r=0
    for l in range(n):
        while(r<n and now&A[r]==0):
            now+=A[r]
            r+=1
        ans+=r-l
        now-=A[l]
    print(ans)
resolve()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a+=[None]
ans=0
if n==1:print(1);exit()
r=0
check=a[0]
for i in range(n):
  if r==n-1:
    ans+=(r-i+1)*(r-i+2)//2
    break
  for j in range(r+1,n+1):
    if j==n:
      ans+=j-i
      r=j-1
      break
    if check^a[j]==check+a[j]:
      check+=a[j]
    else:
      ans+=j-i
      r=j-1
      break
  check^=a[i]
print(ans)

Solution (Python):


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

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

l,r = 0,1 
tmp_xor = A[l] ^ A[r]
tmp_sum = A[l] + A[r]
ans = N

while 1:
    if tmp_xor == tmp_sum:
        ans += r-l 
        r += 1
        if r == N:
            break
        tmp_xor = tmp_xor ^ A[r]
        tmp_sum += A[r]
    elif l+1 < r:
        tmp_sum -= A[l]
        tmp_xor = tmp_xor ^ A[l]
        l += 1
    else:
        l = r
        r += 1
        if r == N:
            break
        tmp_xor = A[l] ^ A[r]
        tmp_sum = A[l] + A[r]

print(ans)

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

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):
import sys
import math
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
a=list(map(int,input().split()))
cnt=0
i=0
j=0
tmp=0
while(i<n):
    while(j<n):
        if tmp&a[j]==0:
            tmp+=a[j]
            cnt+=j-i+1
            
        else:
            break
        j+=1
    tmp^=a[i]
    i+=1
print(cnt)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()


l = r = ans = 0
sm = xor = 0

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

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
seen=[0]* 22 
ans=0 
c=0 
st=0 
ans=0 
for end in range(n): 
   
    for j in range(22):
        if l[end]&(1<<j):
            if seen[j]==1: 
                while seen[j]:
                    for bit in range(22):
                        if (1<<bit)&l[st]:
                            seen[bit]=0 
                    st+=1 
            else:
                seen[j]=1 
    for j in range(22):
        if l[end]&(1<<j):
            seen[j]=1 
    
    c=(end-st+1)
   
    ans+=c
print(ans)

'''
6
2 4 2  4 3 2
'''

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N = int(input())
A = inpl()
ans = 0
xor = plus = A[0]
r = 1
for l in range(N):
    while r < N and xor^A[r] == plus+A[r]:
        xor ^= A[r]
        plus += A[r]
        r += 1
    ans += r-l
    xor ^= A[l]
    plus -= A[l]
print(ans)

Solution (Python):
import sys
n=int(input())
a=list(map(int,input().split()))
if n==1:
    print(1)
    sys.exit()
k=1
s=a[0]
lst=[0]*n
for i in range(n):
    while s^a[k]==s+a[k]:
        s+=a[k]
        k+=1
        if k==n:
            for j in range(i,n):
                lst[j]=n-j
            break
    else:
        lst[i]=k-i
        s=s^a[i]
        continue
    break
print(sum(lst))

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

right = 0
ans = 0
sum_A = 0

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

print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    answer = 0
    temp = A[0]
    right = 0

    for i in range(N):
        if right < N - 1:
            while temp + A[right + 1] == temp ^ A[right + 1]:
                right += 1
                temp += A[right]
                if right == N - 1:
                    break
            temp -= A[i]
            answer += right - i + 1
        else:
            answer += right - i + 1

    print(answer)


if __name__ == '__main__':
    main()

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

for i in range(N):
    if right < N - 1:
        while temp + A[right + 1] == temp ^ A[right + 1]:
            right += 1
            temp += A[right]
            if right == N - 1:
                break
        temp -= A[i]
        answer += right - i + 1
    else:
        answer += right - i + 1

print(answer)

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

for i in range(N):
    if right < N - 1:
        while temp + A[right + 1] == temp ^ A[right + 1]:
            right += 1
            temp += A[right]
            if right == N - 1:
                break
    temp -= A[i]
    answer += right - i + 1

print(answer)

Solution (Python):
def sol():
    n=int(input())+1
    a=[int(i) for i in input().split()]+[2**21-1]
    ans=0
    i=j=w=x=0
    while i<n-1:
        while j<n and w==x:
            w+=a[j]
            x^=a[j]
            j+=1
        ans+=(j-i-1)
        w-=a[i]
        x^=a[i]
        i+=1
    print(ans)

if __name__=="__main__":
    sol()

Solution (Python):
n,*a=map(int,open(0).read().split())
x=s=l=c=0
for r,b in enumerate(a):
  x^=b
  s+=b
  while x<s:
    x^=a[l]
    s-=a[l]
    l+=1
  c+=r-l+1
print(c)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
 
ans=0
b=0
j=0
for i in range(n):
    while j<n and b^a[j]==b+a[j]:
        b^=a[j]
        j=j+1
    ans += j-i
    b^=a[i]
print(ans)

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

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

print (count)

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

B_append = B.append
C_append = C.append

count = 0
for a in A:
    if a != 0:
        if count != 0:
            B_append(0)
            C_append(count)
        B_append(a)
        C_append(1)
        count = 0
    else:
        count += 1
if count != 0:
    B_append(0)
    C_append(count)




N = len(B)

count = 0
for l in range(N):
    tmp = C[l] 
    tmp_count = 0
    total = B[l]
    xor = B[l]
    for r in range(l + 1, N): 
        total += B[r]
        xor ^= B[r]
        if total == xor:
            tmp_count += C[r]
        else:
            break 
    count += tmp_count * tmp
    count += (tmp * (tmp + 1)) // 2

print (count)