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
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N = int(input())
    L = list(map(int, input().split()))

    ans = 0
    l = 0
    r = 0
    tmp_sum = 0
    while l < N:
        while r < N and tmp_sum ^ L[r] == tmp_sum+L[r]:
            tmp_sum ^= L[r]
            r += 1
        ans += r-l
        if(l == r):
            r += 1
        else:
            tmp_sum ^= L[l]
            l += 1
    print(ans)


solve()

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N = int(input())
    L = list(map(int, input().split()))

    ans = 0
    l = 0
    r = 0
    tmp_sum = 0
    while l < N:
        while r < N and tmp_sum ^ L[r] == tmp_sum+L[r]:
            tmp_sum += L[r]
            r += 1
        ans += r-l
        if(l == r):
            r += 1
        else:
            tmp_sum -= L[l]
            l += 1
    print(ans)


solve()

Solution (Python):
from functools import reduce

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N = int(input())
    L = list(map(int, input().split()))

    ans = 0
    l = 0
    r = 0
    tmp_sum = 0
    tmp_bit = 0
    while l < N:
        while r < N and tmp_bit ^ L[r] == tmp_sum+L[r]:
            tmp_bit ^= L[r]
            tmp_sum += L[r]
            r += 1
        ans += r-l
        if(l == r):
            r += 1
        else:
            tmp_bit ^= L[l]
            tmp_sum -= L[l]
            l += 1
    print(ans)


solve()

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

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
dp=[0 for i in range(N)]
AL=A[0]
AR=A[0]
flag0=0
for i in range(1,N):
    AL=AL^A[i]
    AR=AR+A[i]
    if AL!=AR:
        dp[0]=i
        AL=A[i]^AL
        AR-=A[i]
        flag0=1
        break
if flag0==0:
    dp[0]=N
for i in range(1,N):
    AL=AL^A[i-1]
    AR=AR-A[i-1]
    flag=0
    for j in range(dp[i-1],N):
        AL=AL^A[j]
        AR=AR+A[j]
        if AL!=AR:
            dp[i]=j
            AL=A[j]^AL
            AR-=A[j]
            flag=1
            break
    if flag==0:
        dp[i]=N
print(sum(dp)-(N*(N-1))//2)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
ans,l,r=[0]*3
ss,xs=[0],[0]
for i in a:
    ss.append(ss[-1]+i)
for i in a:
    xs.append(xs[-1]^i)
    
while l<n:
    if r<n and ss[r+1]-ss[l]==(xs[r+1]^xs[l]):
        r+=1
    else:
        ans+=r-l
        l+=1

print(ans)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
X = [-1] * 20
ans = 0
ma = -1
for i in range(N):
    for j in range(20):
        if A[i] & (1<<j):
            ma = max(ma, X[j])
            X[j] = i
    ans += i - ma
print(ans)

Solution (Python):
N = int(input())
li = [ int(it) for it in input().split() ] 

keta = 0
p = max(li)
for i in range(100000):
  if (p>0):
    keta+=1
    p//=2
  else:
    break

bli = [ [0]*keta for i in range(N) ]

for i in range(len(li)):
  p = li[i]
  for j in range(100000):
    if (p>0):
      bli[i][j]=p%2
      p//=2
    else:
      break
      
sli = [ [0]*(N+1) for i in range(keta) ]
for k in range(keta):
  for i in range(N):
    sli[k][i+1] = sli[k][i] + bli[i][k] 


s = 0
x = 0
y = 1
gli=[]
for i in range(N*N):
    
    flag = True
    for k in range(keta):
      if (sli[k][y] - sli[k][x] < 2):
        pass
      else:
        flag=False


    if flag:
      if ( len(gli) > 0 ):
        if (gli[-1][0]==x):
          gli.pop()
      gli.append([x,y])    

    if (x==N-1 and y==N):
      break
     
    
    if (flag):
      y+=1
      if(y>N):
        x+=1
      y=min(y,N)
    else:
      x+=1
      y-=1
      x = min(N,x)

s=0
for a,b in gli:
  s+=b-a
print(s)

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

ruiseki = [[0]*20 for i in range(n+1)]

for i in range(n):
    for j in range(20):
        ruiseki[i+1][j] = ruiseki[i][j] + a[i] % 2
        a[i] = a[i] >> 1

s = 0
t = 1
ans = 0
while s < n + 1:
    while t < n + 1: 
        flag = False
        for i in range(20):
            if ruiseki[t][i] - ruiseki[s][i] > 1:
                flag = True
        if flag:
            break
        t += 1
    ans += (t - s - 1)
    s += 1
print(ans)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ret = 0
right = 0
flag = 0
for left in range(n):
    while right<n and flag&a[right] == 0:
        flag |= a[right]
        right += 1
    ret += right-left
    flag^= a[left]
print(ret)

Solution (Python):
import sys

import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')

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

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

Solution (Python):
import sys,collections as cl
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a

n = int(input())

a = l()

ans = 0
l = 0
r = 0
su = 0
for i in range(n):
	while(r < n and (su^a[r]) == (su + a[r])):
		su += a[r]
		r += 1
	ans += r - i
	if r == i:
		r += 1
	else:
		su -= a[i]
print(ans)

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

Solution (Python):



import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main_lte(N, An):
    ans = N
    for l in range(N):
        for r in range(l+1, N):
            a = An[l]
            b = An[l]
            for i in range(l+1, r+1):
                a ^= An[i]
                b += An[i]
            if a == b:
                ans += 1
    print(ans)

def main_lte2(N, An):
    ans = N
    for l in range(N):
        a = An[l]
        b = An[l]
        for r in range(l+1, N):
            a ^= An[r]
            b += An[r]
            if a == b:
                ans += 1
            else:
                continue
    print(ans)

def main(N, An):
    ans = 0
    n = 0
    l = 0
    for r in range(N):
        n2 = An[r]
        if n & n2 == 0:
            n += n2
        else:
            while True:
                n -= An[l]
                l += 1
                if n & n2 == 0:
                    n += n2
                    break
        ans += r + 1 - l
    print(ans)

N = i2n()
An = i2nn()
main(N, An)

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

l=1; r=1

XOR = A[0]
SUM = A[0]

answer = 0

while True:
  if r < N: 
    if XOR^A[r] == SUM + A[r]: 
      XOR = XOR ^ A[r]
      SUM = SUM + A[r]
      r+=1
      continue
    else: 
      if l==r: 
        answer +=1
        XOR = A[r]
        SUM = A[r]
        l+=1
        r+=1        
      else: 
        answer += r-(l-1)
        XOR = XOR ^ A[l-1]
        SUM = SUM - A[l-1]
        l+=1
  else:
    answer +=  (N-(l-1))*(N-(l-1)+1) //2 
    break

print(answer)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
d=0
e=0
f=0
for i in range(n):
    while e<n and d&a[e]==0:
        d+=a[e]
        e+=1
    d-=a[i]
    f+=e-i
print(f)

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

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

Solution (Python):
def inpl(): return list(map(int,input().split()))

N = int(input())
A = inpl()

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

print(ans)

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


ans = 0
i = 0
r = 0
tmp_sum = 0 
tmp_xor = 0 
tmp = 0
for i in range(N):
    
    
    while r < N and tmp_sum+A[r] == tmp_xor^A[r]:
        
        tmp_sum += A[r]
        tmp_xor ^= A[r]
        r += 1

    ans += r - i 
    tmp_sum -= A[i]
    tmp_xor ^= A[i]
    tmp ^= A[i]

    
    

print(ans)

Solution (Python):

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

ans = 0
l = 0
r = 0
sumrange = 0
bitcount = 0
sumxor = 0


while   r <= N-1:
    
    
    
    while r <= N-1 and A[r] & bitcount == 0 : 
        sumrange += A[r]
        bitcount ^= A[r]
        length = r - l + 1
        ans += length 
        r += 1

    while l <= r:
        bitcount ^= A[l]
        sumrange -= A[l]
        l += 1
        if bitcount == sumrange:
            break
print(ans)

Solution (Python):

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

ans = 0
l = 0
r = 0
sumrange = 0
bitcount = 0
sumxor = 0


while   r <= N-1:
    
    
    
    while r <= N-1 and A[r] & bitcount == 0 : 
        sumrange += A[r]
        bitcount ^= A[r]
        length = r - l + 1
        ans += length 
        r += 1

    while l <= r:
        bitcount ^= A[l]
        sumrange -= A[l]
        l += 1
        if bitcount == sumrange:
            break
print(ans)

Solution (Python):
N = int(input())
A = [format(int(a), "b").zfill(20) for a in input().split()]

Sum = [0] * 20
start = 0
end = 1
Ans = N
for i in range(20):
    Sum[i] += int(A[0][i])
while end < N:
    for i in range(20):
        Sum[i] += int(A[end][i])
    if 2 in Sum:
        while 2 in Sum:
            Ans += end - start - 1
            for j in range(20):
                Sum[j] -= int(A[start][j])
            start += 1
    end += 1
while start < N and 2 in Sum:
    for j in range(20):
        Sum[j] -= int(A[start][j])
    start += 1
Ans += (N - start - 1) * (N - start) // 2
print(Ans)

Solution (Python):

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

ans = 0
l = 0
r = 0
sumrange = 0
bitcount = 0
sumxor = 0


while   r <= N-1:
    
    
    
    while r <= N-1 and A[r] & bitcount == 0 : 
        sumrange += A[r]
        bitcount ^= A[r]
        length = r - l + 1
        ans += length 
        r += 1

    while l <= r:
        bitcount ^= A[l]
        sumrange -= A[l]
        l += 1
        if bitcount == sumrange:
            break
print(ans)

Solution (Python):


import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
A = LI()

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

    ans += right - left

    if left == right:
        right += 1
    else:
        xor ^= A[left]

    

print(ans)

Solution (Python):


import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
A = LI()

ans = 0
right = 0
num_xor = 0
num_and = 0
for left in range(n):
    while right < n and num_xor ^ A[right] == num_and + A[right]:
        num_xor ^= A[right]
        num_and += A[right]
        right += 1

    ans += right - left

    if left == right:
        right += 1
    else:
        num_xor ^= A[left]
        num_and -= A[left]

    

print(ans)

Solution (Python):
def main():
    n = int(input().rstrip("\b"))
    numbers = [int(x) for x in input().rstrip("\b").split(" ")]
    start_number = numbers.pop(0)
    targets = {start_number:1}
    total = 0
    from collections import defaultdict
    for number in numbers:
        next_targets = defaultdict(int)
        for (target, count) in targets.items():
            total += count
            if (number | target) >= (target + number):
                next_targets[target + number] += count
        next_targets[number] += 1
        targets = next_targets
        
    for (target, count) in targets.items():
        total += count

    print(total)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
bits = [[0 for _ in range(20)] for _ in range(n)]

for i in range(n):
	for j in range(20):
		bits[i][j] = (a[i] >> j) & 1

ans = 0
bits_sum = [0] * 20

r = 0
for l in range(n):
	r = max(r, l)
	while r < n:
		bits_sum = [bits_sum[j] + bits[r][j] for j in range(20)]
		if max(bits_sum) > 1:
			bits_sum = [bits_sum[j] - bits[r][j] for j in range(20)]
			break
		r += 1
	
	ans += r-l
	bits_sum = [bits_sum[j] - bits[l][j] for j in range(20)]
	


print(ans)

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

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

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import heapq
n=i1()
a=i2()
r=0
right=0
sumx=0
sump=0
for left in range(n):

 while right<n and sumx^a[right]==sump+a[right]:
      sumx^=a[right]
      sump+=a[right]
      right+=1
 r+=right-left
 if left==right:
    right+=1
 else:
    sumx-=a[left]
    sump-=a[left]
print(r)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = right = total = 0
for left in range(N):
    while right < N and total ^ A[right] == total + A[right]:
        total += A[right]
        right += 1
    ans += right - left
    if left == right:
        right += 1
    else:
        total -= A[left]
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):

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


tmpxor = 0
tmpadd = 0
ans = 0
minindex = 0
maxindex = 0
for e,i in enumerate(A):
    tmpadd += i
    tmpxor ^= i
    maxindex = e
    if tmpxor != tmpadd:
        while tmpxor != tmpadd and minindex < e:
            tmpxor ^= A[minindex]
            tmpadd -= A[minindex]
            minindex += 1
            
    ans += maxindex - minindex + 1


        
        
    
print(ans)

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

left = 0
right = 0
ans = 0
s = 0
while left < n and right < n:
    while right < n:
        if s + a[right] == s ^ a[right]:
            s += a[right]
            ans += (right - left + 1)
            right += 1
        else:
            break
    if right > left:
        s -= a[left]
        left += 1
    else:
        right += 1
        left += 1

print(ans)

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

ans = 1
left = 0

now = a[0]
for right in range(1,n):
    while True:
        if now & a[right] == 0:
            now = now | a[right]
            ans += right - left +1
            break
        else:
            now = now^a[left]
            left += 1
print(ans)

Solution (Python):

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

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

Solution (Python):
ai = lambda: list(map(int, input().split()))

n = int(input())
a = ai()

ans = 0
start = 0
s = 0
for i in range(n):
    for j in range(start, n):
        if s + a[j] == s ^ a[j]:
            s += a[j]
        else:
            s -= a[i]
            start = j
            ans += j-i
            break
        if j == n-1:
            for k in range(i,n):
                ans += n-k
            print(ans)
            import sys
            sys.exit()
print(ans)

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

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

    ans += r - l
    XOR ^= A[l]
    SUM -= A[l]

print(ans)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

D = 20

N = read()
A = reads()

psum = [[0]*(N+1) for _ in range(D)]
for d in range(D):
  for i in range(N):
    psum[d][i+1] = psum[d][i] + (A[i] >> d & 1)

r = 0
count = 0
for l in range(N):
  while r < N and all(psum[d][r+1] - psum[d][l] <= 1 for d in range(D)):
    r += 1
  count += r - l
print(count)

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

    count = 1

    l = 0
    r = 1
    x = A[0]
    s = A[0]

    while r < N:
        s += A[r]
        x ^= A[r]
        while s != x:
            s -= A[l]
            x ^= A[l]
            l += 1
        r += 1
        count += r-l

    print(count)

Solution (Python):


def read():
    n = int(input())
    ai = list(map(int, input().split()))
    assert len(ai) == n
    return n, ai

def shakutori(n, ai):
    l = 0
    r = 1  
    res = 1
    su = ai[0]
    xo = ai[0]
    while r < n:
        su += ai[r]
        xo ^= ai[r]
        while su != xo:
            su -= ai[l]
            xo ^= ai[l]
            l += 1
        r += 1
        res += r - l
    return res

def main():
    n, ai = read()
    print(shakutori(n, ai))

main()

Solution (Python):


N = int(input())
A = [int(w) for w in input().split()]
if len(A) != N: raise

x = A[0]
s = A[0]
left = [0] * N  
for i in range(1, N):
    x ^= A[i]
    s += A[i]
    left[i] = left[i-1]
    while x != s:
        x ^= A[left[i]]
        s -= A[left[i]]
        left[i] += 1


numl = [i - left[i] + 1 for i in range(N)]

print(sum(numl))

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






count = 0
sum = line[0]
r = 1
count_tmp = 1

for L in range(N-1):
  
  for r in range(r,N):
    if sum+line[r] == sum ^ line[r]:
      sum += line[r]
      count_tmp += 1
      if r == N-1:
        r += 1
    else:
      break
  count += count_tmp
  count_tmp -= 1
  sum -= line[L]


print(count+1)

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






count = 0
sum = line[0]
r = 1
count_tmp = 1

for L in range(N-1):
  
  for r in range(r,N):
    sum_tmp = sum+line[r]
    if sum_tmp == sum ^ line[r]:
      sum = sum_tmp
      count_tmp += 1
      if r == N-1:
        r += 1
    else:
      break
  count += count_tmp
  count_tmp -= 1
  sum -= line[L]


print(count+1)

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


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

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

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

count=0
right=0
m=0
for left in range(n):
    while right<n and m^a[right]==m+a[right]:
        m+=a[right]
        right+=1
    count+=right-left
    m-=a[left]
print(count)

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

result = 0
Right = 0
tmp = 0
for left in range(N):
    for right in range(Right,N):
        if not (tmp & A[right]):
            tmp += A[right]
            Right = right + 1
        else:
            break
    tmp -= A[left]
    result += Right - left
print(result)

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

cur = A[0]
ans = 0
rp = 1
for lp in range(N):
    while rp < N and cur & A[rp] == 0:
        cur += A[rp]
        rp += 1
    ans += rp - lp
    cur -= A[lp]
    
print(ans)

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

ans = 0
xor = 0
tempSum = 0
l, r = 0, 0
while True:
    if xor ^ a[r] == tempSum + a[r]:
        xor ^= a[r]
        tempSum += a[r]
        r += 1
        ans += (r - l)
        if r == n:
            break
    else:
        xor ^= a[l]
        tempSum -= a[l]
        l += 1

print(ans)

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

ans = 0
xor = 0
tempSum = 0
l, r = 0, 0
while r < n:
    if xor ^ a[r] == tempSum + a[r]:
        xor ^= a[r]
        tempSum += a[r]
        r += 1
        ans += (r - l)
    else:
        xor ^= a[l]
        tempSum -= a[l]
        l += 1

print(ans)

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

res = 0
asum = [0]
axor = [0]

for i in A:
    asum.append(asum[-1] + i)
    axor.append(axor[-1] ^ i)

for l in range(N):
    ok = l+1
    ng = N+1
    while(ng - ok > 1):
        r = (ok + ng) // 2
        s = (axor[r] ^ axor[l])
        t = (asum[r] - asum[l])
        if s == t:
            ok = r
        else:
            ng = r
    
    res += ok - l
         
print(res)

Solution (Python):



def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    ss, xs = 0, 0
    
    ans = 0
    last_index = 0
    length = 0
    for i in range(n):
        ss += al[i]
        xs ^= al[i]
        length += 1
        while ss != xs:
            ss -= al[last_index]
            xs ^= al[last_index]
            last_index += 1
            length -= 1
        ans += length
    print(ans)

if __name__=="__main__":
    solve()

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

i = 0
j = 0
x = 0

result = 0

while i < N or j < N:
    while j < N and x & A[j] == 0:
        x |= A[j]
        j += 1
    result += j - i
    x &= ~A[i]
    i += 1
    
print(result)

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

ans, delta_ans = 0, 0
l, r = 0, 0
xor_sum, plus_sum = A[0], A[0]

while True:
    if xor_sum == plus_sum:
        delta_ans += 1
        ans += delta_ans
        if r == N-1:
            break
        else:
            r += 1
        xor_sum ^= A[r]
        plus_sum += A[r] 
    else:
        delta_ans -= 1
        xor_sum ^= A[l]
        plus_sum -= A[l]
        l += 1

print(ans)

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

r = 0
tempSum = 0
xor = 0
count = 0

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

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

print(count)

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

result = 0
counter = 1
temp = 0
for i in range(n):
    counter -= 1
    start = i + counter
    for j in range(start, n):
        if a[j] ^ temp != a[j] + temp:
            temp -= a[i]
            break
        else:
            temp += a[j]
            counter += 1
    result += counter


print(result)

Solution (Python):


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

Solution (Python):
N = int(input())
A= [int(x) for x in input().split()]
A.append(0)
count = N
s = 0
t = 1
xor = A[0]
while s < N - 1:
  while t < N:
    if not A[t] or not (xor & A[t]):
      xor ^= A[t]
      t += 1
    else:
      break
  count += t - s - 1
  while s < t:
    xor ^= A[s]
    s += 1
    if xor & A[t]:
      count += t - s - 1
      continue
    else:
      break
  if s == t:
    xor = A[s]
    t += 1
print(count)

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

r = 0
ans = 0

current_sum = A[0]

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

print(ans)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    r, d, count = 0, 0, 0
    for l in range(n):
        while True:
            if r == n or d & a[r] > 0:
                break
            d += a[r]
            r += 1
        d -= a[l]
        count += r - l

    print(count)


main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
r, d, count = 0, 0, 0
for l in range(n):
    while True:
        if r == n or d & a[r] > 0:
            break
        d += a[r]
        r += 1
    d -= a[l]
    count += r - l

print(count)

Solution (Python):
N = int(input())
ints = [int(x) for x in input().split()]

ans = 0
r = 0
s = 0
xs = 0
for l in range(N):
    while r < N and s + ints[r] == xs ^ ints[r]:
        s += ints[r]
        xs ^= ints[r]
        r += 1
    ans += (r - l)
    s -= ints[l]
    xs ^= ints[l]

print(ans)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
import time
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    S = 0
    X = 0
    r = 0
    for l in range(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]

    return ans


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()

Solution (Python):

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

Solution (Python):

"""
Contents   : ARC D問題
Author     : Kitaura Hiromi
LastUpdate : 20180527
Since      : 20180526
"""
from operator import xor
from functools import reduce

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

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

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

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

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

l, r = 0, 0
SUM, XOR = 0, 0
ans = 0

for l in range(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]
    
print(ans)

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

l, r = 0, 0
SUM, XOR = 0, 0
ans = 0

for l in range(N):
    while r < N and SUM == XOR:
        SUM += A[r]
        XOR ^= A[r]
        r += 1

    if SUM == XOR:
        r = N+1

    ans += r-l-1

    SUM -= A[l]
    XOR ^= A[l]

print(ans)

Solution (Python):


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

ans=0
l=0;r=0
s=0
xsum=0
for l in range(0,n):
    while(r < n and s == xsum):
        
        s+=A[r]
        xsum^=A[r]
        r+=1
    if s == xsum: 
        r=n+1
    
    
    ans += r-l-1
    
    s -= A[l] 
    xsum ^= A[l] 

print(ans)

Solution (Python):
N = int(input())
A=[int(i) for i in input().split()]
L = []
asum=A[0]
ans = 0
r=1
for i in range(N):
    while True:
        if (r==N):
            break
        if (asum & A[r])>0:
            break
        asum += A[r]   
        r += 1
    asum -= A[i]
    ans += r-i
print(ans)

Solution (Python):
N = int(input())
A=[int(i) for i in input().split()]
L = []
asum=A[0]
axor=A[0] 
i=0
j=0
while (i<N):
    while (asum ==axor) and (j<N-1):
        j = j+1
        asum += A[j]
        axor ^= A[j]
    if (j<N-1):
        L.append((i,j-1))
        asum -= A[i]
        axor ^= A[i] 
        i += 1
    elif (asum ==axor):
        L.append((i,N-1))
        i += 1 
    else:
        L.append((i,j-1))
        asum -= A[i]
        axor ^= A[i] 
        i += 1
ans = 0
for l,r in L:
    ans += r-l+1
print(ans)