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.

-----Constraints-----
 - 1 \leq N \leq 2 \times 10^5
 - 0 \leq A_i < 2^{20}
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N

-----Output-----
Print the number of the pairs of integers l and r (1 \leq l \leq r \leq N) that satisfy the condition.

-----Sample Input-----
4
2 5 4 6

-----Sample Output-----
5

(l,r)=(1,1),(2,2),(3,3),(4,4) clearly satisfy the condition.
(l,r)=(1,2) also satisfies the condition, since A_1\ xor\ A_2 = A_1\ +\ A_2 = 7.
There are no other pairs that satisfy the condition, so the answer is 5.

Difficulty: MEDIUM_HARD

Starter code:

Solutions:
def main():
	ans = 0
	n = int(input())
	A = [int(i) for i in input().split()] + [10 ** 9]
	Sum = 0
	right = 0
	for left in range(n):
		while right < n:
			if Sum ^ A[right] == Sum + A[right]:
				Sum += A[right]
				right += 1
			else:
				break
		ans += right - left
		if left == right:
			right += 1
		else:
			Sum -= A[left]
	print(ans)
main()


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


def main():
	N = int(input())
	A = list(map(int, input().split()))
	(l, r) = (1, 0)
	t = A[0]
	n = 1
	while l < N:
		if A[l] & t:
			t ^= A[r]
			r += 1
			continue
		t |= A[l]
		l += 1
		n += l - r
	return n
print(main())


n = int(input())
al = list(map(int, input().split()))
al.append(0)
res = 0
r = 0
x = 0
y = 0
for l in range(n):
	while x == y and r <= n:
		x += al[r]
		y = y ^ al[r]
		r += 1
	r -= 1
	x -= al[r]
	y = y ^ al[r]
	res += r - l
	x -= al[l]
	y = y ^ al[l]
	if l == r:
		r += 1
print(res)


N = int(input())
A = list(map(int, input().split()))
sums = [0] * (N + 1)
xors = [0] * (N + 1)
for i in range(1, N + 1):
	sums[i] = sums[i - 1] + A[i - 1]
	xors[i] = xors[i - 1] ^ A[i - 1]
ans = 0
for i in range(N):
	l = i
	r = N
	while l + 1 < r:
		m = (l + r) // 2
		if sums[m + 1] - sums[i] == xors[m + 1] ^ xors[i]:
			l = m
		else:
			r = m
	ans += l - i + 1
print(ans)


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


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


n = int(input())
A = tuple(map(int, input().split()))
c = 0
s = 0
r = 0
for l in range(n):
	while r < n and A[r] ^ s == A[r] + s:
		s = A[r] + s
		r += 1
	c += r - l
	if l == r:
		r += 1
	s -= A[l]
print(c)


def submit():
	n = int(input())
	a = [int(e) for e in input().split()]
	(l, r) = (0, 0)
	ans = 0
	curr_xor = 0
	curr_sum = 0
	while r < n:
		curr_xor = curr_xor ^ a[r]
		curr_sum = curr_sum + a[r]
		while curr_xor != curr_sum:
			curr_xor = curr_xor ^ a[l]
			curr_sum = curr_sum - a[l]
			l += 1
		ans += r - l + 1
		r += 1
	print(ans)
submit()


n = int(input())
a = list(map(int, input().split()))
s = [0] * n
t = [0] * n
s[0] = a[0]
t[0] = a[0]
for i in range(1, n):
	s[i] = s[i - 1] + a[i]
	t[i] = t[i - 1] ^ a[i]
s = [0] + s
t = [0] + t
ans = 0
l = 1
r = l
while l < n + 1:
	if s[r] - s[l - 1] == t[r] ^ t[l - 1]:
		while True:
			if s[r] - s[l - 1] == t[r] ^ t[l - 1]:
				r += 1
				if r > n:
					ans += r - l
					r = n
					break
			else:
				ans += r - l
				break
	else:
		while True:
			if s[r] - s[l - 1] == t[r] ^ t[l - 1]:
				ans += r - l + 1
				break
			else:
				r -= 1
				if r == l:
					ans += 1
					r = l + 1
					break
	l += 1
print(ans)


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


n = int(input())
A = list(map(int, input().split()))
ans = 0
l = 0
r = 0
bit = A[0]
total = A[0]
while True:
	if bit == total:
		ans += r - l + 1
		r += 1
		if r == n:
			break
		total += A[r]
		bit ^= A[r]
	else:
		total -= A[l]
		bit ^= A[l]
		l += 1
print(ans)


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

def calculate(n, arr):
	right = 0
	sum = arr[0]
	result = 0
	for left in range(0, n):
		while right + 1 < n and sum + arr[right + 1] == sum ^ arr[right + 1]:
			right = right + 1
			sum = sum + arr[right]
		result = result + right - left + 1
		sum = sum - arr[left]
	print(result)
calculate(N, ARR)


n = int(input())
a = list(map(int, input().split()))
count = 0
r = 1
l = 0
now = a[0]
while l < n:
	while True:
		if r < n and now + a[r] == now ^ a[r]:
			now += a[r]
			count += r - l
			r += 1
		else:
			break
	if l == r:
		now = a[l]
		r += 1
	elif l < n:
		now -= a[l]
		l += 1
print(count + n)


n = int(input())
a = [int(i) for i in input().split()]
s = xor = 0
right = 0
ans = 0
for left in range(n):
	while right < n and s + a[right] == xor ^ a[right]:
		s += a[right]
		xor ^= a[right]
		right += 1
	ans += right - left
	if left == right:
		right += 1
	else:
		s -= a[left]
		xor ^= a[left]
print(ans)


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


nim = int(input())
mike = list(map(int, input().split()))
S = [0]
X = [0]
for a in mike:
	S.append(S[-1] + a)
	X.append(X[-1] ^ a)
(l, r) = (1, 1)
result = 0
p = 1
while r <= nim:
	if S[r] - S[l - 1] == X[r] ^ X[l - 1]:
		if p == 0:
			result -= (r - l) * (r - l + 1) // 2
		r += 1
		p = 1
	else:
		if p == 1:
			result += (r - l) * (r - l + 1) // 2
		l += 1
		p = 0
result += (r - l) * (r - l + 1) // 2
print(result)


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


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

def calculate(n, arr):
	result = 0
	right = 0
	sum = arr[0]
	for left in range(0, n):
		while right + 1 < n:
			if sum ^ arr[right + 1] == sum + arr[right + 1]:
				right = right + 1
				sum = sum + arr[right]
			else:
				break
		result = result + right - left + 1
		sum = sum - arr[left]
	print(result)
calculate(N, ARR)


n = int(input())
a = list(map(int, input().split()))
left = 0
ans = 0
xor_sum = 0
normal_sum = 0
for (right, b) in enumerate(a):
	xor_sum ^= b
	normal_sum += b
	while xor_sum < normal_sum:
		xor_sum ^= a[left]
		normal_sum -= a[left]
		left += 1
	ans += right - left + 1
print(ans)


from copy import deepcopy
from operator import add, sub

class TwoPointers:

	def __init__(self, cond, init=0, right=add, left=sub):
		self.cond = cond
		self.init = init
		self.next_right = right
		self.next_left = left

	def __call__(self, A, uniq=True):
		cond = self.cond
		(next_right, next_left) = (self.next_right, self.next_left)
		s = deepcopy(self.init)
		n = len(A)
		X = {}
		r = 0
		for l in range(n):
			if not uniq:
				X[l] = r
			while r < n and cond(s, A[r]):
				s = next_right(s, A[r])
				r += 1
				X[l] = r
			if l == r:
				r += 1
			else:
				s = next_left(s, A[l]) if l + 1 != r else deepcopy(self.init)
		return list(X.items())

	def maximum(self, A):
		X = self.__call__(A)
		return max((r - l for (l, r) in X)) if X else 0

	def count(self, A):
		X = self.__call__(A, False)
		return sum((r - l for (l, r) in X))
(n, *A) = map(int, open(0).read().split())
print(TwoPointers(lambda s, n: s + n == s ^ n).count(A))


N = int(input())
numbers = list(map(int, input().split()))
(summ, right, left) = (0, 0, 0)
ans = 0
for left in range(N):
	while right < N and summ + numbers[right] == summ ^ numbers[right]:
		summ += numbers[right]
		right += 1
	ans += right - left
	if right == left:
		right += 1
	else:
		summ -= numbers[left]
print(ans)


N = int(input())
A = list(map(int, input().split()))
ans = 0
(w_xor, w_sum) = (A[0], A[0])
(l, r) = (0, 0)
while l < N and r < N:
	if w_xor == w_sum:
		if r < N - 1:
			r += 1
			w_xor = w_xor ^ A[r]
			w_sum = w_sum + A[r]
			continue
		else:
			ans += 1 + r - l
	else:
		ans += r - l
	w_xor = w_xor ^ A[l]
	w_sum = w_sum - A[l]
	l += 1
print(ans)


def main():
	N = int(input())
	A = list(map(int, input().split()))
	ret = 0
	right = 0
	tot = 0
	for left in range(0, N):
		while right < N and (tot ^ A[right] == tot + A[right] or left == right):
			tot += A[right]
			right += 1
		ret += right - left
		tot = tot ^ A[left]
	print(ret)

def __starting_point():
	main()
__starting_point()


import sys
DEBUG = False

def read(t):
	return t(sys.stdin.readline().rstrip())

def read_list(t, sep=' '):
	return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]

def dprint(*args, **kwargs):
	if DEBUG:
		print(*args, **kwargs)
	return

def main():
	n = read(int)
	a = read_list(int)
	ans = 0
	l = r = 0
	cur_sum = 0
	for l in range(0, n):
		if r < l:
			r = l
		while r < n and cur_sum | a[r] == cur_sum + a[r]:
			cur_sum += a[r]
			r += 1
		ans += r - l
		if l < r:
			cur_sum -= a[l]
	print(ans)

def __starting_point():
	main()
__starting_point()


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

def main():
	(N, *A) = list(map(int, read().split()))
	s = 0
	ans = 0
	right = 0
	for left in range(N):
		while right < N and s & A[right] == 0:
			s ^= A[right]
			right += 1
		ans += right - left
		if left == right:
			right += 1
		else:
			s ^= A[left]
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list((int(a) for a in input().split()))
ans = 0
x_sum = 0
a_sum = 0
r = 0
for l in range(N):
	while r < N and x_sum ^ A[r] == a_sum + A[r]:
		x_sum ^= A[r]
		a_sum += A[r]
		r += 1
	ans += r - l
	x_sum ^= A[l]
	a_sum -= A[l]
print(ans)


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


import sys
try:
	from typing import List
except ImportError:
	pass

def solve(N: int, A: 'List[int]'):
	ans = 0
	j = 0
	x = 0
	for i in range(N):
		while j < N and x & A[j] == 0:
			x ^= A[j]
			j += 1
		ans += j - i
		x ^= A[i]
	print(ans)

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)

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))
t = 0
ans = 0
l = 0
r = 0
while r <= N - 1:
	if t + L[r] == t ^ L[r]:
		t += L[r]
		r += 1
	else:
		ans += r - l
		t -= L[l]
		l += 1
ans += (r - l) * (r - l + 1) / 2
print(int(ans))


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
ans = 0
xor = 0
(l, r) = (0, 0)
while r < N:
	if xor ^ A[r] == xor + A[r]:
		ans += r - l + 1
		xor ^= A[r]
	else:
		while xor ^ A[r] != xor + A[r]:
			xor ^= A[l]
			l += 1
		xor ^= A[r]
		ans += r - l + 1
	r += 1
print(ans)


import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate
sys.setrecursionlimit(10 ** 6)
INF = 10 ** 12
m = 10 ** 9 + 7

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

def __starting_point():
	main()
__starting_point()


from sys import stdin

def main():
	readline = stdin.readline
	n = int(readline())
	a = list(map(int, readline().split()))
	l = 0
	r = 1
	ans = 0
	now_xor = a[0]
	now_sum = a[0]
	while l < n:
		if r < n:
			now_xor ^= a[r]
			now_sum += a[r]
			while now_xor != now_sum:
				ans += 1
				ans += r - l - 1
				now_xor ^= a[l]
				now_sum -= a[l]
				l += 1
			r += 1
		else:
			l += 1
			ans += 1
			ans += r - l
	print(ans)

def __starting_point():
	main()
__starting_point()


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

def main():
	(N, *A) = list(map(int, read().split()))
	A = [list(map(int, f'{a:0>20b}')) for a in A]
	ans = 0
	right = 0
	digits = [0] * 20
	for left in range(N):
		while right < N and all((d + b <= 1 for (d, b) in zip(digits, A[right]))):
			for i in range(20):
				digits[i] += A[right][i]
			right += 1
		ans += right - left
		if left == right:
			right += 1
		else:
			for i in range(20):
				digits[i] -= A[left][i]
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


from operator import add, sub
from operator import mul, floordiv

class Two_pointer:

	def __init__(self, cond, init=0, right=add, left=sub):
		self.cond = cond
		self.init = init
		self.next_right = right
		self.next_left = left

	def __call__(self, A):
		cond = self.cond
		(next_right, next_left) = (self.next_right, self.next_left)
		s = init = self.init
		n = len(A)
		X = {}
		r = 0
		for l in range(n):
			X[l] = r
			while r < n and cond(s, A[r]):
				s = next_right(s, A[r])
				r += 1
				X[l] = r
			if l == r:
				r += 1
			else:
				s = next_left(s, A[l]) if l + 1 != r else init
		return list(X.items())
(n, *A) = map(int, open(0).read().split())
X = Two_pointer(lambda s, n: s + n == s ^ n)(A)
print(sum((r - l for (l, r) in X)))


n = int(input())
a = list(map(int, input().split()))
total = a[0]
xor = a[0]
ans = 0
l = 0
r = 0
while 1:
	if xor == total:
		ans += r - l + 1
		r += 1
		if r == n:
			break
		total += a[r]
		xor ^= a[r]
	else:
		total -= a[l]
		xor ^= a[l]
		l += 1
print(ans)


def main():
	N = int(input())
	A = list(map(int, input().split()))
	(l, t, n) = (0, 0, 0)
	for (r, a) in enumerate(A):
		while a & t:
			t ^= A[l]
			l += 1
		t |= a
		n += r - l + 1
	return n
print(main())


def main():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(1)
		return
	ans = n
	l = 0
	now = a[0]
	for r in range(1, n):
		if now & a[r] == 0:
			now = now ^ a[r]
			continue
		now = now ^ a[r]
		for new_l in range(r - 1, l - 1, -1):
			if a[new_l] & a[r] != 0:
				break
		new_l += 1
		for i in range(l, new_l):
			now = now ^ a[i]
		ans += (r - l) * (r - l - 1) // 2 - (r - new_l) * (r - new_l - 1) // 2
		l = new_l
	r += 1
	ans += (r - l) * (r - l - 1) // 2
	print(ans)
main()


n = int(input())
a = tuple(map(int, input().split(' ')))
(r, ans, tsum, txor) = (0, 0, 0, 0)
for l in range(n):
	while r < n and txor ^ a[r] == tsum + a[r]:
		txor = txor ^ a[r]
		tsum = tsum + a[r]
		r += 1
	ans += r - l
	if l == r:
		r += 1
	else:
		txor = txor ^ a[l]
		tsum -= a[l]
print(ans)


N = int(input())
a_l = [int(a) for a in input().split()]
ans = 0
right = 0
_sum = 0
for left in range(N):
	while right < N and _sum ^ a_l[right] == _sum + a_l[right]:
		_sum += a_l[right]
		right += 1
	ans += right - left
	if right == left:
		right += 1
	else:
		_sum -= a_l[left]
print(ans)


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


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


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

def main():
	(N, *A) = list(map(int, read().split()))
	csum = [[0] * 20 for _ in range(N + 1)]
	for i in range(N):
		for j in range(20):
			csum[i + 1][j] = csum[i][j] + (1 if A[i] & 1 << j else 0)

	def is_ok(l, r):
		res = True
		for j in range(20):
			if csum[r][j] - csum[l][j] > 1:
				res = False
				break
		return res
	ans = 0
	right = 0
	for left in range(N):
		while right < N and is_ok(left, right + 1):
			right += 1
		ans += right - left
		if left == right:
			right += 1
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
A.append(0)
r = 0
ans = 0
su = 0
for l in range(N):
	while (l == r or su + A[r] == su ^ A[r]) and r < N:
		su += A[r]
		r += 1
	ans += r - l
	su -= A[l]
print(ans)


n = int(input())
a_list = [int(x) for x in input().split()]
ans = 0
temp_xor = a_list[0]
temp_sum = a_list[0]
r = 0
for l in range(n):
	while r < n:
		if temp_xor != temp_sum:
			break
		r += 1
		if r < n:
			temp_xor ^= a_list[r]
			temp_sum += a_list[r]
	ans += r - l
	temp_xor ^= a_list[l]
	temp_sum -= a_list[l]
print(ans)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	n = int(input())
	A = list(map(int, input().split()))
	res = 0
	left = 0
	add_total = 0
	xor_total = 0
	for right in range(n):
		add_total += A[right]
		xor_total ^= A[right]
		while add_total != xor_total:
			add_total -= A[left]
			xor_total ^= A[left]
			left += 1
		res += right - left + 1
	print(res)

def __starting_point():
	resolve()
__starting_point()


n = int(input())
A = list(map(int, input().split()))
ans = R = X = 0
for L in range(n):
	while R < n and (not X & A[R]):
		X ^= A[R]
		R += 1
	ans += R - L
	X ^= A[L]
print(ans)


N = int(input())
A = list(map(int, input().split()))
A.append(0)
right = 0
ans = 0
su = 0
for left in range(N):
	while (left == right or su + A[right] == su ^ A[right]) and right < N:
		su += A[right]
		right += 1
	ans += right - left
	su -= A[left]
print(ans)


from heapq import heapify, heappush, heappop
n = int(input())
a = [int(i) for i in input().split()]
p = 0
ans = 0
cc = 0
cs = 0
chk = []
heapify(chk)
for (i, ai) in enumerate(a):
	heappush(chk, (i, ai))
	cc = cc ^ ai
	cs += ai
	ans += 1
	if cc != cs:
		p += (ans - 1) * ans // 2
		while chk:
			(j, aj) = heappop(chk)
			ans -= 1
			cc = cc ^ aj
			cs -= aj
			if cc == cs:
				p -= (ans - 1) * ans // 2
				cnt = 0
				break
p += ans * (ans + 1) // 2
print(p)


N = int(input())
A = list(map(int, input().split()))
xo = A[0]
l = 0
r = 1
ans = 0
while l < N:
	if r == N:
		ans += r - l
		l += 1
		continue
	if xo ^ A[r] == xo + A[r]:
		xo += A[r]
		r += 1
	else:
		ans += r - l
		xo ^= A[l]
		l += 1
print(ans)


import numpy as np
N = int(input())
A = list(map(int, input().split()))
r = 0
temp = 0
ans = 0
for l in range(N):
	while r < N and temp ^ A[r] == temp + A[r]:
		temp += A[r]
		r += 1
	ans += r - l
	if r == l:
		r += 1
		temp = 0
	else:
		temp -= A[l]
print(ans)


import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
right = 0
xor = 0
ans = 0

def isOk(x, v):
	while x and v:
		if x & 1 and v & 1:
			return False
		x >>= 1
		v >>= 1
	return True
for left in range(N):
	while right < N and isOk(xor, A[right]):
		xor ^= A[right]
		right += 1
	ans += right - left
	if right == left:
		right += 1
	else:
		xor ^= A[left]
print(ans)


n = int(input())
a = list(map(int, input().split()))
ll = 0
rr = 0
llrr = 0
result = 0
for ll in range(n):
	while rr < n and a[rr] & llrr == 0:
		llrr += a[rr]
		rr += 1
	result += rr - ll
	llrr = llrr ^ a[ll]
print(result)


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


def XorSum2():
	n = int(input())
	a = list(map(int, input().split()))
	(ans, tmp0, tmp1) = (0, 0, 0)
	right = 0
	for left in range(n):
		while right < n and tmp0 ^ a[right] == tmp1 + a[right]:
			tmp0 ^= a[right]
			tmp1 += a[right]
			right += 1
		ans += right - left
		if right == left:
			right += 1
			(tmp0, tmp1) = (0, 0)
		else:
			tmp0 ^= a[left]
			tmp1 -= a[left]
	print(ans)

def __starting_point():
	XorSum2()
__starting_point()


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


import sys
input = sys.stdin.readline

def main():
	N = int(input())
	A = [int(x) for x in input().split()]
	r = 0
	b = A[0]
	ans = 0
	for l in range(N):
		while r + 1 < N and A[r + 1] & b == 0:
			r += 1
			b |= A[r]
		ans += r - l + 1
		b = b ^ A[l]
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
(xsum, sum) = (A[0], A[0])
(ans, x, y) = (0, 0, 0)
flag = True
while flag:
	if xsum == sum:
		ans += x - y + 1
		x += 1
		if x == N:
			break
		sum += A[x]
		xsum ^= A[x]
	else:
		sum -= A[y]
		xsum ^= A[y]
		y += 1
print(ans)


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


import sys
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
N = ir()
A = lr()
answer = 0
left = 0
right = 0
temp = A[left]
while left < N:
	while right < N - 1:
		num = A[right + 1]
		if temp ^ num != temp + num:
			break
		temp += num
		right += 1
	right = max(right, left)
	answer += right - left + 1
	temp -= A[left]
	left += 1
print(answer)


N = int(input())
A = [0] + list(map(int, input().split()))
ans = 0
S = 0
X = 0
end = 0
for i in range(1, N + 1):
	S -= A[i - 1]
	X ^= A[i - 1]
	if end == N:
		ans += end - i + 1
		continue
	if end < N:
		end += 1
	for j in range(end, N + 1):
		S += A[j]
		X ^= A[j]
		if S != X:
			S -= A[j]
			X ^= A[j]
			end = j - 1
			break
		if j == N:
			end = j
	ans += end - i + 1
print(ans)


import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def input():
	return sys.stdin.readline().strip()

def main():
	N = int(input())
	A = list(map(int, input().split()))
	ans = 0
	right = 0
	xor = 0
	s = 0
	for left in range(N):
		while right < N and s + A[right] == xor ^ A[right]:
			s += A[right]
			xor ^= A[right]
			right += 1
		ans += right - left
		if right == left:
			right += 1
		else:
			s -= A[left]
			xor ^= A[left]
	print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
aaa = list(map(int, input().split()))
right = 0
sum = 0
cnt = 0
for left in range(n):
	while right < n and sum ^ aaa[right] == sum + aaa[right]:
		sum += aaa[right]
		right += 1
	cnt += right - left
	if left == right:
		right += 1
	else:
		sum -= aaa[left]
print(cnt)


import sys

def input():
	return sys.stdin.readline().strip()
MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)
INF = float('inf')

def main():
	N = int(input())
	A = list(map(int, input().split()))
	(right, ans, tmp) = (0, 0, 0)
	for left in range(N):
		while right < N and tmp ^ A[right] == tmp + A[right]:
			tmp += A[right]
			ans += right - left + 1
			right += 1
		if left == right:
			right += 1
		else:
			tmp -= A[left]
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
rt = 0
res = 0
x = 0
s = 0
for lt in range(N):
	while rt < N and x ^ A[rt] == s + A[rt]:
		x ^= A[rt]
		s += A[rt]
		rt += 1
	res += rt - lt
	x ^= A[lt]
	s -= A[lt]
print(res)


import sys

def solve(N: int, A: 'List[int]'):
	(ans, t, s) = (0, 0, 0)
	for h in range(N):
		while t < N and s ^ A[t] == s + A[t]:
			s += A[t]
			t += 1
		ans += t - h
		s -= A[h]
	return ans

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)]
	print(solve(N, A))

def test():
	import doctest
	doctest.testmod()

def __starting_point():
	main()
__starting_point()


n = int(input())
A = list(map(int, input().split()))
xsum = A[0]
asum = A[0]
ans = 0
(left, right) = (0, 0)
while True:
	if xsum == asum:
		ans += right - left + 1
		right += 1
		if right == n:
			break
		asum += A[right]
		xsum ^= A[right]
	else:
		asum -= A[left]
		xsum ^= A[left]
		left += 1
print(ans)


N = int(input())
A = list(map(int, input().split()))
r = 0
xor = 0
total = 0
cnt = 0
for l in range(N):
	while r < N and total + A[r] == xor ^ A[r]:
		total += A[r]
		xor ^= A[r]
		r += 1
	cnt += r - l
	total -= A[l]
	xor ^= A[l]
print(cnt)


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

def __starting_point():
	main()
__starting_point()


N = int(input())
num = list(map(int, input().split()))
ans = 0
r = 0
sumz = 0
for l in range(N):
	if r < l:
		r = l
	while r < N and num[r] + sumz == sumz ^ num[r]:
		sumz += num[r]
		r += 1
	ans += r - l
	sumz -= num[l]
print(ans)


def main():
	N = int(input())
	A = list(map(int, input().split(' ')))
	ng = 0
	cum_xor = 0
	right = 0
	for left in range(N):
		if left > 0:
			cum_xor ^= A[left - 1]
		while right < N and cum_xor & A[right] == 0:
			cum_xor ^= A[right]
			right += 1
		ng += N - right
	print(N * (N + 1) // 2 - ng)

def __starting_point():
	main()
__starting_point()


def bin20(x):
	bin_x = bin(x)[2:]
	x_len = len(bin_x)
	return list(map(int, '0' * (20 - x_len) + bin_x))

def main():
	N = int(input())
	A = list(map(int, input().split()))
	A = [bin20(a) for a in A]
	ans = 0
	left = 0
	right = 0
	sum20 = [0] * 20
	pre_right = -1
	while True:
		if right > pre_right:
			for k in range(20):
				sum20[k] += A[right][k]
		pre_right = right
		if 2 in sum20:
			for k in range(20):
				sum20[k] -= A[left][k]
			ans += right - left
			left += 1
		else:
			right += 1
		if right == N:
			ans += (N - left) * (N - left + 1) // 2
			return ans
print(main())


N = int(input())
A = [int(i) for i in input().split()]
left = 0
total = 0
xor = 0
ans = 0
for right in range(N):
	total += A[right]
	xor ^= A[right]
	while total != xor:
		total -= A[left]
		xor ^= A[left]
		left += 1
	ans += right - left + 1
print(ans)


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)


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

def __starting_point():
	abc098_d()
__starting_point()