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):
N = int(input())
A = [int(x) for x in input().split(" ")]

ans=0
r = 0
for i,a in enumerate(A):
    if (i == 0) or (r + 1 == i):
        l = i+1
        a_xor = A[i]
    else:
        a_xor -= A[i-1]
    while(l < len(A)):
        if (a_xor ^ A[l]) == (a_xor + A[l]):
            a_xor += A[l]
            l += 1
        else:
            break
    r = l-1
    ans += l - i
print(ans)

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

Ans = 0
j,xorA = 0,0
for i in range(N):
    while j < N and xorA&A[j] == 0:
        xorA |= A[j]
        j += 1
    Ans += j-i
    xorA ^= A[i]

print(Ans)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    n_satisfied = 0
    sum_lr = 0
    xor_lr = 0
    left, length = 0, 0

    while True:
        while left + length != N and \
                sum_lr + A[left + length] == xor_lr ^ A[left + length]:
            sum_lr += A[left + length]
            xor_lr ^= A[left + length]
            length += 1

        n_satisfied += length

        if left == N:
            break

        sum_lr -= A[left]
        xor_lr -= A[left]
        left += 1
        length -= 1

    print(n_satisfied)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    
    

    n_satisfied = 0
    sum_lr = 0
    xor_lr = 0
    l, length = 0, 0

    while True:
        while l + length != N and \
                sum_lr + A[l + length] == xor_lr ^ A[l + length]:
            sum_lr += A[l + length]
            xor_lr ^= A[l + length]
            length += 1

        
        n_satisfied += length

        if l == N:
            break

        sum_lr -= A[l]
        xor_lr -= A[l]
        l += 1
        length -= 1

    print(n_satisfied)

Solution (Python):


n = int(input())
a = [int(x) for x in input().split()]

count = 0
xor_result = 0
sum_result = 0
r = 0

for l in range(0, n):
    while r < n:
        x = a[r]
        if sum_result & x != 0:
            break
        xor_result ^= x
        sum_result += x
        r += 1
    count += r - l
    xor_result ^= a[l]
    sum_result -= a[l]

print(count)

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

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

r = 0
std_sum = 0 
xor_sum = 0 
count = 0

for l in range(N):
    while (r != N and std_sum + A[r] == xor_sum ^ A[r]):
        std_sum += A[r]
        xor_sum ^= A[r]
        r += 1
 
    count += r - l
    std_sum -= A[l]
    xor_sum ^= A[l]
 
print(count)

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

ans = N
if N == 1:
    print(1)
    sys.exit()
j = 1
s = A[0] + A[1]
x = A[0] ^ A[1]
for i, a in enumerate(A):
    if j == i:
        j += 1
        if j == N:
            break
        x = x ^ A[j]
        s += A[j]

    while True:
        if j == N:
            break
        if s == x:
            ans += j-i
            j += 1
            if j == N:
                break
            s += A[j]
            x = x ^ A[j]
        else:
            s -= a
            x = x ^ a
            break
    if j == N:
        break

print(ans)

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

lp = [0]
nowlp = 0

for x in range( len(a) ):
  nowlp += a[x]
  lp.append(nowlp)

ans = 0
prev = [ [0,0] ]

for l in range(0,n-1):
  r = prev[l][1] + 1
  ans += prev[l][1]-l
  now = lp[r] - lp[l]

  while r <= n-1 and now^a[r] == now+a[r]:
    ans += 1
    now += a[r]
    r += 1
  prev.append( [l,r-1] )

ans += n
print ans

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

ans = 0
p = 0
used = False
count = 1
for i in range(n):
    if a[i]^p == a[i]+p:
        if used:
            count += 1
        used = True
        p += a[i]
    else:
        c = count
        for j in range(i-c, i):
            count -= 1
            p -= a[j]
            if p^a[i] == p+a[i]:
                break
        if count == 0:
            p = a[i]
            count = 1
        else:
            count += 1
            p += a[i]
    ans += count
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
counter = n
prev = [[0,0]]

total = [0]
for i in range(n):
	total.append(total[i]+a[i])

for i in range(n-1):
	k = prev[i][1]+1
	counter += prev[i][1]-i
	cumsum = total[k]-total[i]
	while k <= n-1 and cumsum^a[k] == cumsum+a[k]:
		counter += 1
		cumsum += a[k]
		k += 1
	prev.append([i,k-1])
print(counter)

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

f = []
for i in range(n):
    f.append(0)
f[0]=1

state = state ^ a[0]

left = 0
for j in range(1,n):
    s = f[j-1]
    while state + a[j] != state ^ a[j]:
        s = s - 1
        state = state - a[left]
        left = left + 1
    f[j] = s + 1
    state = state + a[j]

ans = sum(f)
print(ans)

Solution (Python):
from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

N = ri()
A = ria()

ret = 0
l = 0
lr = 0

acc = 0
while l < len(A) and lr < len(A):
  if acc & A[lr] == 0:
    ret += 1
    acc |= A[lr]
    lr += 1
    if lr == len(A):
      for i in range(len(A) - l):
        ret += i
      break
  else:
    acc ^= A[l]
    l += 1
    if l != lr:
      ret += lr - l

print(ret)

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

def resolve(a):
    cnt = 0
    base = 0
    skip = 0

    for i in range(len(a)):
        c, base = resolve_1(a, i, skip, base)

        skip = c - 1
        base = base ^ a[i]
        cnt += c

    
    return cnt

def resolve_1(a, i, skip, base):
    cnt = skip

    for j in range(i + skip, len(a)):
        if a[j] & base != 0:
            break
        
        cnt += 1
        base |= a[j]

    return (cnt, base)

main()

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

r = 0
xorsum = 0
sum = 0
count = 0
for l in range(N):
    while (r != N and sum + A[r] == xorsum ^ A[r]):
        sum += A[r]
        xorsum ^= A[r]
        r += 1

    count += r - l
    sum -= A[l]
    xorsum ^= A[l]

print(count)

Solution (Python):

N = int(input())

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

ans = 0
ans_plus = 0
l = 0
r = 0
xor_sum = A[0]
sum = A[0]
while 1:
	if xor_sum == sum:
		ans_plus += 1
		ans += ans_plus
		if r == N-1:
			break
		else:
			r += 1
		xor_sum ^= A[r]
		sum += A[r] 
	else:
		ans_plus -= 1
		xor_sum ^= A[l]
		sum -= A[l]
		l += 1

print(ans)