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 bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

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



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

s = 0
x = 0
l = 0
r = 0
ans = 0
while l < N:
    while r < N and s + A[r] == x ^ A[r]:
        s += A[r]
        x ^= A[r]
        r += 1
    ans += r - l
    
    s -= A[l]
    x ^= A[l]
    l += 1
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
A_acc = list(accumulate([0]+A))
r = 0
s = 0
ans = 0
for l in range(N):
	while r < N and s^A[r] == A_acc[r+1]-A_acc[l]:
		s ^= A[r]
		r += 1
	ans += r-l
	if r == l+1:
		s = 0
	else:
		s ^= A[l]

print(ans)

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

s=[0]*(N+1)
xs=[0]*(N+1)
for i in range(N):
  s[i+1]=s[i]+A[i]
  xs[i+1]=xs[i] ^ A[i]
ans=0
l=0
for r in range(N+1):
    
    
    if r == N:
      ans+=((r-l)*(r+1-l))//2
      continue   
    while(r != l):
      if s[r+1]-s[l] == xs[r+1]^xs[l]:
        break
      else:         
        ans+=r-l
        l+=1
print(ans)

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

ans = 0

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

print(ans)

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

Solution (Python):


def calc(al, n):
    res = 0
    r = 0
    tmpsum = 0
    tmpxor = 0
    for l in range(n):
        while r<n and tmpsum+al[r]==tmpxor^al[r]:
            tmpsum += al[r]
            tmpxor ^= al[r]
            r += 1

        res += (r-l)

        if r==l:
            r += 1
        else:
            tmpsum -= al[l]
            tmpxor ^= al[l]

    return res


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

print(calc(al,n))

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()

cur = A[0]
l = 0
answer = 1 
for i in range(1, N):
    x = A[i]
    while cur^x != cur + x:
        cur -= A[l]
        l += 1
    answer += i - l + 1
    cur += x

print(answer)

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

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
aa = inl()
a = []
for i in range(n):
    x = []
    for j in range(20):
        x.append((aa[i]>>j)&1)
    a.append(x)
if DBG:
    for i,z in enumerate(a):
        printn(aa[i])
        printn(' ')
        printn(i)
        print(z)
    print("- a -")
cnt = n
c = [a[0][j] for j in range(20)]
s = 1
for i in range(1,n):
    ok = True
    for j in range(20):
        if c[j]==1 and a[i][j]==1:
            ok = False
            break
    
    if ok:
        cnt += s
        s += 1
        for j in range(20):
            c[j] += a[i][j]
    else:
        for j in range(20):
            c[j] += a[i][j]
        
        s += 1
        
        while s>1:
            if max(c)<=1:
                break
            for j in range(20):
                c[j] -= a[i-s+1][j]
            s -= 1
            
        cnt += s-1
print(cnt)

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

count=0
SumL=SumR=0
R=0
for L in range(N):
    if L>R:
        R=L
    while R<N and SumL^List[R]==SumR+List[R]:
        SumR+=List[R]
        SumL^=List[R]
        R+=1

    SumR-=List[L]
    SumL^=List[L]
    count += R-L

print(count)

Solution (Python):
def examC():
    N = I()
    S = SI()
    E = S.count("E"); W = N-E
    curW = 0; curE = 0
    ans = N-1
    for i in range(N):
        if S[i]=="W":
            curW +=1
        cur = N -1 - (W-curW) - curE
        if S[i]=="E":
            curE +=1
        ans = min(ans,cur)

    print(ans)
    return

def examD():
    N = I()
    A = LI()
    cur = [0]*21
    k = 0; ans = 0
    flag = True
    for i in range(N):
        for j in range(21):
            if cur[j]>=2:
                a = A[i]
                for l in range(21):
                    if a & (1 << l) == (1 << l):
                        cur[l] -= 1
                continue
        flag = True
        while(k<N):
            a = A[k]
            for j in range(21):
                if a&(1<<j)==(1<<j):
                    if cur[j]>=1:
                        flag = False
                        break
            if flag:
                for j in range(21):
                    if a & (1 << j) == (1 << j):
                        cur[j] += 1
                k +=1
            if not flag:
                break
        ans += k-i

        a = A[i]
        for j in range(21):
            if a & (1 << j) == (1 << j):
                cur[j] -= 1

    print(ans)
    return

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()
global mod,mod2,inf,alphabet,ALPHABET
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]
ALPHABET = [chr(ord('A') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

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

    
    r = 1
    xor, tot = a[0], a[0]

    ret = 0
    for l in range(n):
        while (r < n) and (xor ^ a[r]) == (tot + a[r]):
            xor ^= a[r]
            tot += a[r]
            r += 1

        ret += r - l

        xor ^= a[l]
        tot -= a[l]

    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
if n > 1:
    A = list(map(int, input().split()))
else:
    A = [int(input())]

right = 0
tot = 0
count = 0

for left in range(n):
    while (right < n) and (tot + A[right] == tot ^ A[right]):
        tot += A[right]
        right += 1
    
    count += right - left
    
    if right == left:
        right += 1
    else:
        tot -= A[left]

print(count)

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

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

for Ai in A:
    acc.append(acc[-1]+Ai)

r = 0
xor = 0
ans = 0

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

print(ans)

Solution (Python):





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

ans = 0
sum = 0

left = 0
right = 0

while(left < n):
    while(right < n and (sum ^ a[right] == sum + a[right])):
        sum = sum + a[right]
        right = right + 1

    ans = ans + right - left
    if(left == right):
        right = right + 1
    else:
        sum = sum - a[left]

    left = left + 1

print(ans)

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

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

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

i=j=0
g, h = a[0], a[0]
r = 0
while i<=N-1:
    if g == h:
        r += j-i+1
        if j==N-1:
            break
        j += 1
        g = a[j]^g
        h = a[j]+h
    else:
        g = a[i]^g
        h = h-a[i]
        i += 1
print(r)

Solution (Python):
from itertools import accumulate


def solve():
    N, *A = map(int, open(0).read().split())
    
    ans, l = 0, 0
    sum_lr, xor, length = 0, 0, 0
    for r in range(N):
        sum_lr += A[r]
        xor ^= A[r]
        length += 1
        while sum_lr != xor:
            sum_lr -= A[l]
            xor ^= A[l]
            l += 1
            length -= 1
        ans += length
    print(ans)


if __name__ == '__main__':
    solve()

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

sum_temp = 0
count = 0
left = 0

for i in range(n):

    while( i >= left):
        check = sum_temp & a[i]
        if check > 0:
            sum_temp -= a[left]
            left += 1
        else :
            count += (i-left) + 1
            sum_temp += a[i]
            break

print(count)

Solution (Python):
def main():
    N = int(input())
    L = list(map(int, input().split()))
    A, S = [0] * (N+1), [0] * (N+1)
    for i in range(N):
        A[i+1] = A[i] ^ L[i]
        S[i+1] = S[i] + L[i]
    res, l = 0, 1
    for r in range(1, N+1):
        while (S[r] - S[l-1]) != (A[r] ^ A[l-1]):
            l += 1
        res += r-l+1
    print(res)
  
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    L = list(map(int, input().split()))
    A, S = [0] * (N+1), [0] * (N+1)
    for i in range(N):
        A[i+1] = A[i] ^ L[i]
        S[i+1] = S[i] + L[i]
    res, l = 0, 1
    for r in range(1, N+1):
        while (S[r] - S[l-1]) != (A[r] ^ A[l-1]):
            l += 1
        res += r-l+1
    print(res)
  
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A, S = [0] * (N+1), [0] * (N+1)
a = list(map(int, input().split()))
for i in range(N):
    A[i+1] = A[i] ^ a[i]
    S[i+1] = S[i] + a[i]
ans = 0
l = 1
for r in range(1, N+1):
    while (S[r]-S[l-1]) != (A[r]^A[l-1]):
        l += 1
    ans += r-l+1
print(ans)

Solution (Python):




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


ex = 0


ans = 0
j = 0
ex = 0
for i in range(N):
    while j <= N-1 and ex + A[j] == ex ^ A[j]:
        ex += A[j]
        j += 1

    ans += j-i  
    ex -= A[i]

print(ans)

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

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

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

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

l=0
r=0
ans=0
p=A[l]
while r<N:
  if r==l:
    if r<N-1:
      if p^A[r+1]==p+A[r+1]:
        r+=1
        p+=A[r]
      else:
        r+=1
        p+=A[r]
        p-=A[l]
        ans+=r-l
        l+=1
    else:
      r+=1
      p-=A[l]
      ans+=r-l
      l+=1
  else:
    if r<N-1:
      if p^A[r+1]==p+A[r+1]:
        r+=1
        if r<N:
          p+=A[r]
      else:
        p-=A[l]
        ans+=r-l+1
        l+=1
    else:
      p-=A[l]
      ans+=r-l+1
      l+=1


print(ans)

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

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

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

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

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

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

ans = 0
sum = 0
right = 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 = [int(i) for i in input().split()]

ans = 0
sum = 0
right = 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
        sum = A[left]
    else:
        sum -= A[left]
print(ans)

Solution (Python):
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=[-1]*n
    cnt=0
    now=0
    for i in range(n):
        while now<=i:
            if cnt+a[i]==cnt^a[i]:
                cnt+=a[i]
                ans[i]=now
                break
            else:
                cnt-=a[now]
                now+=1
    print(sum([i-ans[i] for i in range(n)])+n)
main()

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]

l,r,ans=1,1,1

tempsum = a[0]

while(r<n):
    while(r<n and (tempsum^a[r]==tempsum+a[r])):
        tempsum^=a[r]
        r+=1
        ans+=(r-l+1)
    tempsum-=a[l-1]
    l+=1

    if(l>r):
        ans+=1
        r=l
        tempsum=a[l-1]
print(ans)

Solution (Python):
import sys
n = int(input())
an = list(map(int,input().split()))
l = 1
r = 1
ans = 1
tmpsum=an[0]
while r<n:
  while r<n and tmpsum^an[r]==tmpsum+an[r]:
    tmpsum+=an[r]
    r += 1
    ans += r-l+1
  tmpsum -= an[l-1]
  l +=1
  if l>r:
    r=l
    tmpsum=an[l-1]
    ans += 1
print(ans)

Solution (Python):
import sys
n = int(input())
an = list(map(int,input().split()))
l = 1
r = 1
ans = 1
tmpsum=an[0]
while True:
  if r == n:
    print(ans)
    sys.exit()
  while tmpsum^an[r]==tmpsum+an[r]:
    tmpsum+=an[r]
    r += 1
    ans += r-l+1
    if r == n:
      print(ans)
      sys.exit()
  tmpsum -= an[l-1]
  l +=1
  if l>r:
    r=l
    tmpsum=an[l-1]
    ans += 1

Solution (Python):

from collections import defaultdict


def getlist():
	return list(map(int, input().split()))


def main():
	N = int(input())
	A = getlist()
	XOR = [0]
	S = [0]
	for i in range(N):
		XOR.append(XOR[-1] ^ A[i])
		S.append(S[-1] + A[i])
	
	
	i = 0
	j = 1
	ans = 0
	while j < N + 1:
		if S[j] - S[i] == XOR[j] ^ XOR[i]:
			ans += j - i
			j += 1
		else:
			i += 1
	print(ans)

if __name__ == '__main__':
	main()

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



ans = 0

t = 0
l = 0

for r, x in enumerate(a):
    while t & x != 0:
        
        t -= a[l]
        l += 1
        if l == r:
            break
    ans += r - l + 1
    t += x
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
L = 0
R = 0
S = A[0]
ans = 0
while(R < N-1):
    if S + A[R+1] == S ^ A[R+1]:
        S += A[R+1]
        R+= 1
    elif R > L:
        S -= A[L]
        ans += R - L + 1
        L += 1
    else:
        L += 1
        R += 1
        ans += 1
        S = A[L]
print(ans+(R-L+2)*(R-L+1)//2)

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

a = list(map(int, input().split( )))
a.append(1<<20-1)
left = 0
right = 0
ans = 0
temp = 0
while left<n:
    while temp + a[right] == temp^a[right]  and right<n:
        temp += a[right]
        right += 1
    ans += right - left
    temp -= a[left]
    left += 1
print(ans)

Solution (Python):
def show():
    global L,R,X,ans
    print((L,R,X,ans))

N=int(input())
A=list(map(int,input().split()))
A.append(2**20-1)

L=0;R=0
ans=0
X=A[L]

while L<N or R<N:
    while R<N-1 and X&A[R+1]==0:
        X=X^A[R+1]
        R+=1

    if L==R:
        ans+=1
        L+=1
        R+=1
        X=A[L]
    else:
        ans+=R-L+1
        X=X^A[L]
        L+=1

print(ans)

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

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

bit_a = [list(bin(a)[2:].zfill(20)) for a in a_list]

digits = [[int(a[i])for a in bit_a] for i in range(20)]

for digit in digits:
    one_idx = (-1,-1)
    for i,d in enumerate(digit):
        if d == 1:
            digit[i] = one_idx[1]
            one_idx = (one_idx[1],i)
        else:
            digit[i] = one_idx[0]
        

max_idx = [max([digit[i] for digit in digits]) for i in range(N)]

cnt = 0
for i,idx in enumerate(max_idx):
    cnt += i-idx

print(cnt)

Solution (Python):
N = int(input())
nums = list(map(int, input().split()))
cnt = 0
xor = 0
sum_n = 0
lb = 0
rb = 0
while rb < N:
  if sum_n+nums[rb] == xor^nums[rb]:
    sum_n += nums[rb]
    xor ^= nums[rb]
    cnt += rb-lb+1
    rb += 1
  else:
    sum_n -= nums[lb]
    xor ^= nums[lb] 
    lb += 1
print(cnt)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    t = 0
    tb = 0
    cur = 0
    cnt = 0
    for i in range(n):
        t += a[i]
        tb = tb ^ a[i]
        if t == tb:
            cnt += (i - cur + 1)
        else:
            while True:
                t -= a[cur]
                tb = tb ^ a[cur]
                cur += 1
                if t == tb:
                    cnt += (i - cur + 1)
                    break
    print(cnt)


if __name__ == '__main__':
    slove()

Solution (Python):

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

srui = [0]
xrui = [0]

for a in A:
    srui.append(srui[-1]+a)
    xrui.append(xrui[-1]^a)
    

ans = 0
J = 1
for i in range(N):
    I = i+1
    while J <= N and (srui[J]-srui[I-1]) == (xrui[J]^xrui[I-1]):
        J+=1
    J-=1
    ans += J-I+1
            
print(ans)

Solution (Python):

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

srui = [0]
xrui = [0]

for a in A:
    srui.append(srui[-1]+a)
    xrui.append(xrui[-1]^a)
    

ans = 0
J = 1
for i in range(N):
    I = i+1
    while J <= N and (srui[J]-srui[I-1]) == (xrui[J]^xrui[I-1]):
        J+=1
    J-=1
    ans += J-I+1
            
print(ans)

Solution (Python):
import math
import copy

def secize(n, k):
    n2=bin(n)
    n3=n2[2:]
    for i in range(k-len(n2)+2):
        n3='0'+n3
    return n3


n=int(input())
alist = list(map(int,input().split()))
saidai=max(alist)
keta=math.ceil(math.log(saidai+1, 2))
blist=[]
for i in range(n):
    kaz=secize(alist[i], keta)
    blist.append(kaz)

now1=0
now2=0
nowarr=[]
for bl in blist[0]:
    nowarr.append(int(bl))
answer=0
swit=0
while now1<=n-2 and now2<=n-2:
    """
    maearr=copy.deepcopy(nowarr)
    for i in range(keta):
        if blist[now2+1][i]=='1':
            if nowarr[i]==1:
                swit=1
            else:
                nowarr[i]=1
    """
    for i in range(keta):
        if blist[now2+1][i]=='1':
            if nowarr[i]==1:
                swit=1
            else:
                nowarr[i]=2
    if swit==1:
        for i in range(keta):
            if nowarr[i]==2:
                nowarr[i]=0
        answer+=(now2-now1+1)
        
        for i in range(keta):
            if blist[now1][i]=='1':
                nowarr[i]=0
        if now1==now2:
            nowarr=[]
            for bl in blist[now1+1]:
                nowarr.append(int(bl))
            now1+=1
            now2+=1
            if now1==n-1:
                answer+=1
        else:
            now1+=1
        swit=0
    else:
        for i in range(keta):
            if nowarr[i]==2:
                nowarr[i]=1
        if now2!=n-2:
            now2+=1
        else:
            wa=now2-now1+2
            answer+=(wa*(wa+1)//2)
            now2+=1


if n!=1:
    print(answer)
else:
    print(1)

Solution (Python):
n = int(input())
num_list = [ int(v) for v in input().split() ]

symple_sum, xor_sum = num_list[0], num_list[0]
ans = 0
l, r = 0, 0


while l < n:
    stop_r = 0
    while stop_r == 0:
        if r == n - 1:
            stop_r = 1

        elif symple_sum ^ num_list[r+1] == xor_sum + num_list[r+1]:
            symple_sum ^= num_list[r+1]
            xor_sum += num_list[r+1]
            r += 1
        else:
            stop_r = 1

    ans += r - l + 1

    symple_sum ^= num_list[l]
    xor_sum -= num_list[l]
    l += 1

print(ans)

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

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = [0] + LI()
b = list(accumulate(a))
l,r,tmp,ans = 0,0,0,n
while r < n:
    if b[r+1] - b[l] == tmp ^ a[r+1]:
        tmp ^= a[r+1]
        ans += r-l
        r += 1
    elif l == r:
        tmp ^= a[l]
        l += 1
        r += 1
    else:
        l += 1
        tmp ^= a[l]
print(ans)

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

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

Solution (Python):
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() 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)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
num = LI()
ans = n
l = 0
r = 0
cnt = 0
ret = num[0]
while r < n-1:
    if ret & num[r+1] == 0:
        ret ^= num[r+1]
        cnt += 1
        r += 1
        ans += cnt
    elif l == r:
        l +=1; r += 1;
        ret = num[l]
    else:
        ret ^= num[l]
        cnt -= 1
        l += 1



print(ans)

Solution (Python):
from collections import deque

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

ans = 0
tmp = 0
buf = deque()

for a in A:
    while tmp & a:
        item = buf.popleft()
        tmp ^= item
    buf.append(a)
    tmp |= a
    ans += len(buf)
print(ans)

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



j = 0
acc = 0
s = 0
for i, a in enumerate(A):
    while a & acc != 0 and j < i:
        acc ^= A[j]
        j += 1
    s += i - j + 1
    acc ^= a
ans = s

print(ans)

Solution (Python):

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


count = 0
right = 0
total = 0
xor= 0
for left in range(N):
    
    while (right < N and xor ^ a[right] == total + a[right]):        
        xor = xor ^ a[right]
        total += a[right]
        right += 1
        
    
    count += (right - left)

    
    if(right == left):
        right += 1
    else:
        total -= a[left]
        xor ^= a[left]


print(count)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
r=0
from collections import defaultdict
d=defaultdict(int)
d[A[0]]=1
for i in range(1,N):
    d2=defaultdict(int)
    for a in d.keys():
        if a&A[i]==0:
            r+=d[a]
            d2[a+A[i]]+=d[a]
    d2[A[i]]+=1
    d=d2
print(r+N)

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

end_index = 0
sum_plus = A[0]
sum_xor = A[0]
ans = 0

for i in range(N):
    if(i > 0):
        sum_plus -= A[i-1]
        sum_xor ^= A[i-1]
    if(i == N-1):
        ans += 1
        break

    while(sum_plus == sum_xor and end_index < N):
        end_index += 1
        if(end_index == N):
            break
        sum_plus += A[end_index]
        sum_xor ^= A[end_index]

    if(end_index == N):
        end_index -= 1
    else:
        sum_plus -= A[end_index]
        sum_xor ^= A[end_index]
        end_index -= 1

    ans += end_index - i + 1
    
print(ans)

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

bit = [0] * 20
ans = 0
L = R = 0
while L < N:
    A_new = bin(A[R])[2:].zfill(20) if R < N else '0' * 20
    ok = 1
    remove_left = 1
    for i in range(20):
        if A_new[i] == '1' and bit[i] == 1:
            ok = 0
            break
    if ok:
        for i in range(20):
            if A_new[i] == '1':
                bit[i] = 1
        if R < N:
            remove_left = 0
        R = min(R + 1, N)
    if remove_left:
        A_left = bin(A[L])[2:].zfill(20)
        for i in range(20):
            if A_left[i] == '1':
                bit[i] = 0
        ans += R - L
        L += 1
print(ans)

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

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

def kuriagari(n, m):
  if n+m == n^m:
    return 0
  else:
    return 1
  
num=0

zero_list = [0] * (N-1)
zero_list.append(N)
for i in range(N-1):
  if A[N-1-i] == 0:
    zero_list[N-2-i]=zero_list[N-1-i]
  else:
    zero_list[N-2-i]=N-1-i

for i in range(N):
  judge = 0
  num2 = 0
  j=0
  while judge == 0 and i+j<N:
    judge=kuriagari(num2, A[i+j])
    if judge==0:
      num2+=A[i+j]
      num+=zero_list[i+j]-(i+j)
    j+=zero_list[i+j]-(i+j)
      
print(num)

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

l = 0
r = 0
ans = 0
S = 0

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

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

l = 0
r = 1
all_xor = A[0]
all_sum = A[0]
count = 0

while True:
    count += r-l
    while r < N:
        
        all_sum += A[r]
        all_xor = all_xor ^ A[r]
        r += 1
        if all_xor == all_sum:
            count += r-l
        else:
            break
    else:
        break
    while l < r-1:
        all_sum -= A[l]
        all_xor = all_xor ^ A[l]
        l += 1
        if all_sum == all_xor:
            break
else:
    count += l-r
print(count)

Solution (Python):
import sys
from collections import deque  
from collections import defaultdict  
from heapq import heapify, heappush, heappop, heappushpop  
from bisect import bisect_left, bisect_right  



s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N = i2n()
    A = i2nn()
    a = A[0]
    b = A[0]
    n = 1
    j = 0
    
    for i in range(1, N):
        c = A[i]
        a ^= c
        b += c
        
        while a != b:
            d = A[j]
            a ^= d
            b -= d
            j += 1
            
        n += i - j + 1
    print(n)

main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
S=0
XOR=0
r=-1
ans=0
for i in range(N):
    while S==XOR and r<N:
        r+=1
        if r>=N:
            break
        S+=A[r]
        XOR^=A[r]
    ans+=r-i
    S-=A[i]
    XOR^=A[i]
print(ans)

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


xor = [0]*(N+1)
cum = [0]*(N+1)
for i in range(N):
    xor[i] = xor[i-1]^A[i]
    cum[i] = cum[i-1]+A[i]

rlist = []
r = 0
for l in range(N):
    r = max(l+1,r)
    while r < N and xor[r]^xor[l-1] == cum[r]-cum[l-1]:
        r += 1
    if r == N:
        break
    r -= 1
    rlist.append(r)
ans = 0
rlist += [N-1]*(N-len(rlist))
for l in range(N):
    r = rlist[l]
    ans += r-l+1
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
data=[0]*N
r=-1
S=0
T=0
for k in range(N):
    while S==T and r<N:
        r+=1
        if r==N:
            break
        S+=A[r]
        T^=A[r]
    data[k]=r-1
    S-=A[k]
    T^=A[k]
print(sum([data[i]-i+1 for i in range(N)]))