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 sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n=int(input())
a=tuple(map(int,input().split() ))
from itertools import accumulate
b=[0]+list(accumulate(a))
xor=[0]
ar=0
for i in a:ar^=i;xor.append(ar)
right=0
ub=-1
ans=0
for left in range(n):
    while right<n and xor[right+1]^xor[left]==b[right+1]-b[left]:
        right+=1
    
    if xor[right]^xor[left]==b[right]-b[left]:
        ans+=(right-left)*(right-left-1)//2
        if ub>left:
            ans-=(ub-left)*(ub-left-1)//2
        ub=right
    if right==left:right+=1
    
print(ans+n)

Solution (Python):
from collections import deque

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

buf = deque()  
tmp = 0        
ans = 0

for i in A_list:
    while tmp & i:
        
        remove_0_pos = buf.popleft()
        tmp ^= remove_0_pos 
    buf.append(i)
    tmp ^= i 
    ans += len(buf)
print(ans)

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

ans, xor, cnt = 0, 0, 0
for i in range(n):
    while cnt < n and xor & a[cnt] == 0:
        xor ^= a[cnt]
        cnt += 1
    ans += cnt - i
    xor ^= a[i]
print(ans)

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

ans, num, xor, cnt = 0, 0, 0, 0
for i in range(n):
    while cnt < n and xor & a[cnt] == 0:
        num += a[cnt]
        xor ^= a[cnt]
        cnt += 1
    ans += cnt - i
    num -= a[i]
    xor ^= a[i]
print(ans)

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

ans, num, xor, cnt = 0, 0, 0, 0
for i in range(n):
    while cnt < n and (num + a[cnt] == xor ^ a[cnt]):
        num += a[cnt]
        xor ^= a[cnt]
        cnt += 1
    ans += cnt - i
    num -= a[i]
    xor ^= a[i]
print(ans)

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

ans, num, xor, cnt = 0, 0, 0, 0
for i in range(n):
    for j in range(cnt, n):
        if num + a[j] == xor ^ a[j]:
            num += a[j]
            xor ^= a[j]
        else:
            ans += j - i
            cnt = max(j, i + 1)
            break
    else:
        ans += n - i
        cnt = n
    num -= a[i]
    xor ^= a[i]
print(ans)

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

Solution (Python):
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve2() -> Any:
    N = read_int()
    A = read_ints()
    S = 0
    xorS = 0
    l = 0
    answer = 0
    for r in range(N):
        S += A[r]
        xorS ^= A[r]
        while l < r and xorS != S:
            S -= A[l]
            xorS ^= A[l]
            l += 1
        answer += (r-l+1)
    return answer


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

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

Solution (Python):
"""
尺取り方で行ける。
"""

from itertools import accumulate
N = int(input())
A = [0]+list(map(int,input().split()))
accumA = list(accumulate(A))
r = 1
tmp = 0
ans = 0
for l in range(1,N+1):
    while r <= N:
        if tmp^A[r] == accumA[r]-accumA[l-1]:
            tmp ^= A[r]
            r += 1
        else:
            tmp -= A[l]
            ans += r-l
            break
    else:
        tmp -= A[l]
        ans += r-l
print(ans)

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

a, b = A[0], A[0]
ct = 0
j = 0
flag = True
for i in range(N):
    while a == b and j < N:
        j += 1
        if j == N:
            break
        a += A[j]
        b ^= A[j]
    ct += j-i
    a -= A[i]
    b ^= A[i]
print(ct)

Solution (Python):
from copy import deepcopy

N = int(input())
A = list(map(int, input().split()))
ans = [0]*20
L = [[0]*20 for _ in range(N)]
for i in range(N):
    for j in range(20):
        if (A[i] >> j) & 1:
            L[i][j] += 1

x = deepcopy(L[0])
ct = 0
j = 0
flag = True
for i in range(N):
    while flag and j < N:
        j += 1
        if j == N:
            break
        for k in range(20):
            x[k] += L[j][k]
            if x[k] >= 2:
                flag = False
    ct += j-i
    for k in range(20):
        x[k] -= L[i][k]
    if all(x[k] <= 1 for k in range(20)):
        flag = True
    
    
print(ct)

Solution (Python):
n= int(input())
a = list(map(int, input().split()))
g = [[0]*20 for i in range(n)]
for i in range(n):
  e = a[i]
  for j in range(20):
    g[i][j]+=e%2
    e//=2
ans=0
b =0
c =0
d= [0]*20
s=1
while(1):
  e =0
  if s ==1:
    for i in range(20):
      d[i]+=g[c][i]
      if d[i]>=2:
        e+=1
  else:
    for i in range(20):
      d[i]-=g[b-1][i]
      if d[i]>=2:
        e+=1
  if e==0 and c!=n-1:
    s=1
    c+=1
  elif e!=0:
    ans+=c-b
    s=0
    b+=1
  else:
    ans+=c-b+1
    s=0
    b+=1
    if b==n:
      break
print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
l, r = 0, 0
a = 0
cnt = 0
while l < N:
    if r < N and a & A[r] == 0:
        assert a+A[r] == a^A[r]
        a += A[r]
        r += 1
    else:
        cnt += r-l
        assert a-A[l] == a^A[l]
        a -= A[l]
        l += 1
print(cnt)

Solution (Python):

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

sumA,xorA=[0],[0]
tmp_s=0
tmp_x=0
for a in A:
    tmp_s+=a
    tmp_x=tmp_x^a
    sumA.append(tmp_s)
    xorA.append(tmp_x)

def check(l,r):
    if r>N:
        return False
    return sumA[r]-sumA[l]==xorA[r]^xorA[l]


l,r=0,0
res=0
while 1:
    if check(l,r):
        if r<=N:
            r+=1
            continue
    res+=r-l-1
    if l<=N-1:
        l+=1
    if r>N and l>=N:
        break
print(res)

Solution (Python):
N = int(input())
Alist = [0] + list(map(int,input().split()))
Sumlist = [0]*(N+1)
A = Alist[0]
Sumlist[0] = A
for i in range(1,N+1):
    Sumlist[i] = Sumlist[i-1] + Alist[i]
    Alist[i] = A ^ Alist[i]
    A = Alist[i]
Ans = 0
ri = 0
for le in range(N+1):
    while ri <= N and Sumlist[ri] - Sumlist[le] == Alist[le] ^ Alist[ri]:
        ri += 1
    Ans += ri-le-1
    if le == ri:
        ri += 1
print(Ans)

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

ans, cnt = 0, 0
s = 0
for t in range(n):
    while cnt & A[t]:
        ans += t - s
        cnt -= A[s]
        s += 1
    
    cnt += A[t]

ans += (t-s+1) * (t-s+2) // 2
        
    
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
r,l=0,0
s,x=0,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]
  if r==l:r+=1
  l+=1
print(ans)

Solution (Python):
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def syakutori(array):
    n = len(array)
    r = 1
    res = 0
    now = array[0]
    for l in range(n):
        while 0 < r < n and now^array[r] == now+array[r]:
            now = now ^ array[r]
            r += 1
        res += r-l
        now = now ^ array[l]

        if l == r:
            r += 1

    return res


def main():
    N = NI()
    A = NLI()
    print(syakutori(A))


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def syakutori(array):
    n = len(array)
    r = 1
    res = 0
    now = array[0]
    for l in range(n):
        while 0 < r < n and (r <= l or now^array[r] == now+array[r]):
            now = now ^ array[r]
            r += 1
        res += r-l
        now = now ^ array[l]

        if l == r:
            r += 1

    return res


def main():
    N = NI()
    A = NLI()
    print(syakutori(A))


if __name__ == "__main__":
    main()

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

b=0
X=0
K=0

for a in range(N):
    try:
        while X+A[b]==X^A[b]:
            X+=A[b]
            b+=1
    except:
        pass

    K+=b-a
    X-=A[a]

print(K)

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

b=0
X=0
K=0

for a in range(N):
    try:
        while X+A[b]==X^A[b]:
            X+=A[b]
            b+=1
    except:
        pass

    K+=b-a
    X-=A[a]

print(K)

Solution (Python):
def f(A,B):
    m=0
    for i in range(len(A)):
        if m<A[i]+B[i]:
            m=A[i]+B[i]
    return m

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

B=[[0 for _ in range(J)] for __ in range(N)]
for i in range(N):
    m=A[i]
    for j in range(J):
        B[i][j]=m%2
        m>>=1
B+=[[float("inf")]*J]

b=0
X=[0]*J
K=0

for a in range(N):
    while f(X,B[b])<=1:
        for k in range(J):
            X[k]+=B[b][k]
        b+=1

    K+=b-a

    for k in range(J):
        X[k]-=B[a][k]

print(K)

Solution (Python):
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter



input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    n = getN()
    lis = getList()
    xo, su = 0, 0
    ans = 0
    l, r = 0, 0
    forward = True
    while True:
        
        if r == n:
            print(ans)
            return
        if forward:
            xo = xo^lis[r]
            su += lis[r]
            if xo == su:

                ans += r - l + 1
                r += 1
            else:
                forward = False
        else:
            xo = xo^lis[l]
            su -= lis[l]
            if xo == su:
                forward = True
                ans += r - l
                r += 1
                l += 1
            else:
                l += 1

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    
    solve()

Solution (Python):
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter



input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    n = getN()
    lis = getList()
    xo, su = 0, 0
    ans = 0
    l, r = 0, 0
    forward = True
    while True:
        
        if r == n:
            print(ans)
            return
        if forward:
            xo = xo^lis[r]
            su += lis[r]
            if xo == su:

                ans += r - l + 1
                r += 1
            else:
                forward = False
        else:
            xo = xo^lis[l]
            su -= lis[l]
            if xo == su:
                forward = True
                ans += r - l
                r += 1
                l += 1
            else:
                l += 1

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    
    solve()

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

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

    ans += r-l

    if l == r:
        r += 1
        x = 0
    else:
        x ^= A[l]
print(ans)

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




def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))




def main():
	n=II()
	A=LI()

	s=0
	x=0
	r=-1

	ans=0

	for l in range(n):
		while s==x and r<n:
			r+=1
			if r==n:
				break
			s+=A[r]
			x^=A[r]
			
		
		ans+=r-l

		s-=A[l]
		x^=A[l]
	print(ans)







if __name__ == "__main__":
	main()

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




def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))




def main():
	n=II()
	A=LI()

	s=0
	x=0
	r=-1

	ans=0

	for l in range(n):
		while s==x and r<n:
			r+=1
			if r==n:
				break
			s+=A[r]
			x^=A[r]
			
		
		ans+=r-l

		s-=A[l]
		x^=A[l]
	print(ans)







if __name__ == "__main__":
	main()

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

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

    ans += right - left

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

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


n = int(input())
A = [int(i) for i in input().split()]
_sum = 0
_xor = 0
l, r = 0, 0
ans = 0
while l < n:
    while r < n and _sum + A[r] == _xor ^ A[r]:
        _sum += A[r]
        _xor ^= A[r]
        r += 1
    ans += r - l
    _sum -= A[l]
    _xor ^= A[l]
    if l == r:
        r += 1
    l += 1

print(ans)

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

l = r = 0
s = 0
xor = 0
unko = 0
while l < n:
    while r < n and s + a[r] == xor ^ a[r]:
        s += a[r]
        xor ^= a[r]
        r += 1
    unko += r - l
    s -= a[l]
    xor ^= a[l]
    if l == r:
        r += 1
    l += 1
print(unko)

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

X = [[0]*22 for i in range(n)]
for i, a in enumerate(A):
    b = format(a, 'b')
    b = list(b)
    b.reverse()
    for j in range(len(b)):
        if b[j] == '1':
            X[i][j] = 1

def is_ok(x, S):
    for j in range(22):
        if x[j] == 1:
            if j in S:
                return False
    else:
        return True

t = 0
S = set()
ans = 0
for s in range(n):
    while t < n:
        if is_ok(X[t], S):
            for j in range(22):
                if X[t][j] == 1:
                    S.add(j)
            t += 1
        else:
            break
    
    ans += t-s
    if t == s:
        t += 1
    else:
        for j in range(22):
            if X[s][j] == 1:
                S.remove(j)
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right

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

al2 = [ [] for _ in range(20)]
for a in al:
    for i in range(20):
        if a&(1<<i) > 0:
            al2[i].append(1)
        else:
            al2[i].append(0)

al2_cum = []
for i in range(20):
    cum = 0
    cumsum = [0]
    for a in al2[i]:
        cum += a
        cumsum.append(cum)
    al2_cum.append(cumsum)



ans = 0
for i in range(n+1):
    curr_maxind = 0
    for j in range(20):
        curr_cum = al2_cum[j]
        curr_1_cnt = curr_cum[i]
        if curr_1_cnt <= 1:
            continue
        else:
            ind = bisect_left(curr_cum, curr_1_cnt-1)
            curr_maxind = max(curr_maxind,ind)
    ans += (i-curr_maxind)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    N = int(input().strip())
    A = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    return N, A


@njit
def cond(l, r, S, O = np.ones(20, dtype=np.int32)):
    s = S[r, :] - S[l, :]
    return np.less_equal(s, O).all()


@njit
def solve(N, A):
    ans = 0
    
    S = np.zeros((N+1, 20), dtype=np.int32)
    for i in range(N):
        a = A[i]
        for j in range(20):
            S[i+1, j] = S[i, j] + ((a >> j) & 0x1)
    for l in range(N):
        ok = l+1
        ng = N+1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if cond(l, mid, S):
                ok = mid
            else:
                ng = mid
        r = ok
        ans += r - l
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n = ni()
A = lma()
r= 1
l = 0
ans = 0
xorA = A[0]
sumA = A[0]

for l in range(n):
    while r<=n-1:
        if l==r:
            r+=1
            sumA = A[l]
            xorA = A[l]
            continue
        if xorA^A[r] == sumA + A[r]:
            xorA ^= A[r]
            sumA +=A[r]
            r+=1
        else:
            xorA ^= A[l]
            sumA -=A[l]
            break
    ans+=r-l

print(ans)

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

def check(tmp, x):
    for i in range(20):
        if (x >> i) & 1 and (tmp >> i) & 1:
            return False
    return True

ans = 0
tmp = 0
r = 0
for l in range(n):
    if r < l:
        r = l
    while r < n and check(tmp, a[r]):
        tmp += a[r]
        r += 1

    ans += r - l
    tmp -= a[l]

print(ans)

Solution (Python):
import sys
import math
import collections
import bisect
import copy
import itertools



sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))





def main():
    n = ni()
    a = na()
    bit = [[0] * 20 for _ in range(n)]
    bitidx = [[] * 20 for _ in range(20)]

    for i, ai in enumerate(a):
        cnt = 0
        while ai > 0:
            if ai & 1:
                bit[i][cnt] = 1
                bitidx[cnt].append(i)
            cnt += 1
            ai >>= 1

    ans = n

    for i in range(n):
        min_idx = n
        for j in range(20):
            
            tmp = bisect.bisect_left(bitidx[j], i + 1)
            if not bit[i][j]:
                
                tmp += 1

            if tmp < len(bitidx[j]):
                tmp = bitidx[j][tmp]
            else:
                tmp = n
                
            min_idx = min(min_idx, tmp)
        ans += min_idx - i - 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
import collections
import bisect
import copy
import itertools



sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))





def main():
    n = ni()
    a = na()
    bit = [[0] * 20 for _ in range(n)]
    bitidx = [[] * 20 for _ in range(20)]

    for i, ai in enumerate(a):
        cnt = 0
        while ai > 0:
            if ai & 1:
                bit[i][cnt] = 1
                bitidx[cnt].append(i)
            cnt += 1
            ai >>= 1

    ans = n

    for i in range(n):
        min_idx = n
        for j in range(20):
            
            tmp = bisect.bisect_left(bitidx[j], i + 1)
            if bit[i][j]:
                
                if tmp < len(bitidx[j]):
                    tmp = bitidx[j][tmp]
                else:
                    tmp = n
            else:
                
                tmp += 1
                if tmp < len(bitidx[j]):
                    tmp = bitidx[j][tmp]
                else:
                    tmp = n
            min_idx = min(min_idx, tmp)
        ans += min_idx - i - 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



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

count = N
Sum = 0
r = 1
Sum = A[0]

for l in range(0, N-1):

    while r < N and Sum + A[r] == Sum ^ A[r]:
            
            Sum += A[r]
            r += 1
    count += r-l-1

    Sum -= A[l]    

print(count)

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

count = N
Sum = 0
r = 1
Sum = A[0]

for l in range(0, N-1):

    while r < N and Sum + A[r] == Sum ^ A[r]:
            
            Sum += A[r]
            r += 1
    count += r-l-1

    Sum -= A[l]    

print(count)

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

count = 0
Sum = 0
r = 0

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ps=0
xs=0
c=0
j=0
for i in range(n):
  ps+=a[i]
  xs^=a[i]
  while ps!=xs:
    ps-=a[j]
    xs^=a[j]
    j+=1
  c+=i-j+1
print(c)

Solution (Python):
'''
研究室PCでの解答
'''
import math

import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    ans = 0
    l = 0
    sm = 0
    for i,ai in enumerate(a):
        while sm&ai != 0:
            sm -= a[l]
            l += 1
        ans += (i-l+1)
        sm += ai

    print(ans)


    return None

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ps=0
xs=0
c=0
j=0
for i in range(n):
  ps+=a[i]
  xs^=a[i]
  while ps!=xs:
    ps-=a[j]
    xs^=a[j]
    j+=1
  c+=i-j+1
print(c)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



N = INT()

A = LIST()
A_acc = list(accumulate([0]+A))
n = max(A).bit_length()

ans = 0
r = 0
tmp = 0

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

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



N = INT()

A = LIST()

n = max(A).bit_length()

ans = 0
r = 0
tmp = 0

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

print(ans)

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

l = r = tot = xor = cnt = 0
while l <= r < N:
    a = A[r]
    if xor & a == 0:
        tot += a
        xor ^= a
        r += 1
        cnt += r-l
    else:
        while xor & a:
            tot -= A[l]
            xor ^= A[l]
            l += 1
print(cnt)

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

l=r=s=0
while l<n:
    if s^a[r]==s+a[r]:
        s+=a[r]
        if r!=n-1:
            r+=1
        else:
            break
    else:
        ans+=r-l
        s-=a[l]
        l+=1

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

print(ans)

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

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

print(ans)

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

xor = 0
count = 0
r = 0
for l in range(n):
    while r < n and xor & a[r] == 0:
        xor ^= a[r]
        r += 1
    count += r - l
    xor ^= a[l]
print(count)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
bi = [0 for i in range(20)]
l = 0
r = 0
ans = 0
while True:
    if r == n:
        break
    rflag = False
    kar = bi[:]
    for i in range(20):
        if a[r] >> i & 1 == 1:
            kar[i] += 1
            if kar[i] == 2:
                rflag = True
    while True:
        if not rflag:
            bi = kar[:]
            break
        ans += r - l
        for i in range(20):
            if a[l] >> i & 1 == 1:
                kar[i] -= 1
        l += 1
        if max(kar) <= 1:
            rflag = False
    r += 1
ans += (r-l)*(r-l-1)//2 + r-l
print(ans)

Solution (Python):
def add_list(l1,l2):
    res = []
    for v1,v2 in zip(l1,l2):
        res.append(v1+v2)
    return res

def sub_list(l1,l2):
    res = []
    for v1,v2 in zip(l1,l2):
        res.append(v1-v2)
    return res

n = int(input())
al = list(map(int, input().split()))
al2 = []
for a in al:
    a2 = list( map(int,format(a,'020b')) )
    al2.append(a2)



left = -1
right = -1
next_i = 0
each_keta = [0]*20
ans = 0
while True:
    if right == n-1:
        break
    next_2 = add_list(al2[right+1], each_keta)
    if 2 in next_2:
        left += 1
        each_keta = sub_list(each_keta, al2[left])
    else:
        right += 1
        each_keta = next_2[:]
        ans += (right-left)

print(ans)

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
X=0
P=0
Q=0
j=0
for i in range(N):
  Q+=1
  while X^A[i]!=X+A[i]:
    Q-=1
    X^=A[j]
    j+=1
  X^=A[i]
  P+=Q
print(P)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.append(0)
x=a[0]
xi=1
ans=0
x_s=0
x_e=0
a_sum=a[0]
while x_e<n:
    if x_s==x_e:
        x_e+=1
        ans+=1
        xi=2
        x^=a[x_e]
        a_sum+=a[x_e]
    elif x==a_sum:
        ans+=xi
        xi+=1
        x_e+=1
        x=x^a[x_e]
        a_sum=a_sum+a[x_e]
    else:
        xi-=1
        x=x^a[x_s]
        a_sum=a_sum-a[x_s]
        x_s+=1

print(ans)

Solution (Python):
def resolve():
    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)

if __name__ == "__main__":
    resolve()

Solution (Python):
import numpy as np




N = int(input())
A = np.array(list(map(int, input().split())))
l = 0
r = 0
c = 0

x = 0
s = 0

while (l < len(A)):
    while (x == s):
        r += 1
        if (r > len(A)):
            break
        x = x ^ A[r-1]
        s += A[r-1]
    if (r <= len(A)):
        x = x ^ A[r-1]
        s -= A[r-1]
    r -= 1
    c += (r - l)
    x = x ^ A[l]
    s -= A[l]
    l += 1

print(c)

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