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=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)

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

Solution (Python):
N = int(input())
A = list(int(a) for a in input().split())

ans = 0
x_sum = 0
a_sum = 0
r = -1
for l in range(N):
    while x_sum == a_sum and r < N-1:
        r += 1
        x_sum ^= A[r]
        a_sum += A[r]
    if x_sum != a_sum:
        x_sum ^= A[r]
        a_sum -= A[r]
        r -= 1
    ans += r-l+1
    
    x_sum ^= A[l]
    a_sum -= A[l]

print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))+[0]

su = 0
ans = 0
right = 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)

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = in_nl()

    A_sum = [0] * (N + 1)
    A_xor = [0] * (N + 1)

    for i in range(N):
        A_sum[i + 1] = A_sum[i] + A[i]
        A_xor[i + 1] = A_xor[i] ^ A[i]

    count = 0
    r = 0
    for l in range(N):
        while r < N:
            
            if A_sum[r + 1] - A_sum[l] == A_xor[r + 1] ^ A_xor[l]:
                r += 1
            else:
                break
        count += r - l
        if r == l:
            r += 1

    print(count)


if __name__ == '__main__':
    main()

Solution (Python):

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)

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

Solution (Python):


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)


if __name__ == "__main__":
    main()

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
lis=LI()
zoro=[[0]*20 for i in range(n)]
for i in range(n):
    for j in range(20):
        if (lis[i]>>j) %2==1:
            zoro[i][j]=1
left=0
right=0
table=[0 for i in range(20)]
count=0
while right<n:
    
    flag=True
    for i in range(20):
        table[i]+=zoro[right][i]
        if table[i]>1:
            flag=False
    if flag==False:
        for i in range(20):
            table[i]-=zoro[left][i]
            table[i]-=zoro[right][i]
        left+=1
    elif flag==True:
        
        count+=right-left+1
        right+=1
    
print(count)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    """
    条件成立＝（２進数表示した時に各桁に１が高々1つしか登場しない）
    なので尺取り法でいけそう
    """
    left = 0
    right = 1
    bit = {i for i in range(20) if A[0] & (1 << i)}

    ans = 0
    while right <= N:
        
        ans += right - left
        if right == N:
            print(ans)
            return

        bit_right = {i for i in range(20) if A[right] & (1 << i)}
        while bit & bit_right:
            bit_left = {i for i in range(20) if A[left] & (1 << i)}
            bit -= bit_left
            left += 1
        bit |= bit_right
        right += 1



if __name__ == "__main__":
    main()

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
A = IL()

l = 0
r = 0
now = 0
num = 0
count = 0
while r < N:
  if now & A[r] == 0:
    now += A[r]
    num += 1
    count += num
    r += 1
  else:
    now -= A[l]
    num -= 1
    l += 1
print(count)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
A = IL()

l = 0
r = 1
now = A[0]
num = 1
count = 1
while r < N:
  if now & A[r] == 0:
    now += A[r]
    num += 1
    count += num
    r += 1
  else:
    now -= A[l]
    num -= 1
    l += 1
print(count)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 0
total = A[0]
l=r=0
xor = A[0]

while True:
    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)

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

xorsum = 0
sumz = 0
totallen = 0
right = 0
for left in range(N):
    while right < N and (sumz + num[right]) == (xorsum ^ num[right]):
        sumz += num[right]
        xorsum ^= num[right]
        right += 1

    totallen += (right - left)
    if right <= left:
        right += 1
    else:
        sumz -= num[left]
        xorsum ^= num[left]

print(totallen)

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

total = alst[0]
xor = alst[0]
ans = 0
l = 0
r = 0
while 1:
    if xor == total:
        ans += r - l + 1
        r += 1
        if r == n:
            break
        total += alst[r]
        xor ^= alst[r]
    else:
        total -= alst[l]
        xor ^= alst[l]
        l += 1
print(ans)

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

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

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

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

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


if '__main__' == __name__:
    resolve()

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import accumulate

    n = int(readline())
    a = list(map(int, readline().split()))
    ans = 0

    sum_cur = 0
    xor_cur = 0
    idx = 0

    for i, x in enumerate(a):
        sum_cur += x
        xor_cur ^= x

        while idx <= i:
            if sum_cur == xor_cur:
                ans += (i + 1) - idx
                break
            else:
                sum_cur -= a[idx]
                xor_cur ^= a[idx]
                idx += 1

    print(ans)


if __name__ == '__main__':
    main()

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

bit_len = 20
memo = [[] for i in range(bit_len)]
ans = 0

for i, ai in enumerate(a):
    li = 0
    for j in range(bit_len):
        if ai & (1 << j):
            if len(memo[j]) >= 1:
                li = max(li, memo[j][-1] + 1)
            memo[j].append(i)
        else:
            if len(memo[j]) >= 2:
                li = max(li, memo[j][-2] + 1)
    ans += i - li + 1

print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7






N = getN()
A = getList()

r, tmp = 0, 0

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

    if l == r:
        r += 1
        tmp -= A[l]
    else:
        tmp -= A[l]
print(cnt)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7






N = getN()
A = getList()

r, tmp = 0, A[0]

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

    if r + 1 < N and l == r:
        r += 1
        tmp = A[r]
    else:
        
        tmp -= A[l]
print(cnt)

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


if __name__ == '__main__':
    resolve()

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

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
from decimal import Decimal



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


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


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

    N = ii()
    A = il()

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

        ret += r - l
        if l == r:
            r += 1
        else:
            sm -= A[l]
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
from decimal import Decimal



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


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


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

    N = ii()
    A = il()

    ret, r, sm = 0, 0, 0
    for l in range(N):
        while r < N and (l == r or A[r] ^ sm == sm + A[r]):
            sm += A[r]
            r += 1

        ret += r - l
        if l == r:
            r += 1
        else:
            sm -= A[l]
    print(ret)


if __name__ == '__main__':
    main()

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

l = len(bin(max(a))[2:])

cumsums = [[0] for _ in range(l)]
for i in range(n):
    for j in range(l):
        if a[i] & (1 << j):
            cumsums[j].append(cumsums[j][-1] + 1)
        else:
            cumsums[j].append(cumsums[j][-1])

ans = 0
left = 0
for i in range(1, n+1):
    while left < i:
        f = True
        for j in range(l):
            if cumsums[j][left] < cumsums[j][i] - 1:
                f = False

        if f:
            break
        else:
            left += 1

    ans += i - left
print(ans)

Solution (Python):

import sys

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


N = ir()
A = lr()
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)

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

if __name__=="__main__":
    main()

Solution (Python):









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)

if __name__ == '__main__':
    main()

Solution (Python):


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



res = 0
right = 0
sum_a = 0
for left in range(N):
    while right < N and (sum_a ^ A[right]) == (sum_a + A[right]):
        sum_a += A[right]
        right += 1
    res += right - left
    
    
    if left == right:
        right += 1
    else:
        sum_a ^= A[left]

print(res)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
CSum=[[0 for i in range(N+1)] for j in range(21)]

for i in range(1,N+1):
    nowA = A[i-1]
    for j in range(21):
        CSum[j][i] = CSum[j][i-1]
        CSum[j][i] += nowA%2
        nowA //= 2

l = 0
r = 1
ans = 0
while r <= N :
    ok = True
    for i in range(21):
        if CSum[i][r] - CSum[i][l] >= 2:
            ok = False
    
    if ok:
        ans += r-l
        r += 1
    else:
        l += 1

print(ans)

Solution (Python):
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

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

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

print(ans)

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

ans = 0
s = 0
x = 0

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

Solution (Python):
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
    else:
        s -= A[l]

print(c)

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

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

def ischeck(amount, target):
    for i in range(30):
        a = (amount >> i) & 1
        b = (target >> i) & 1
        if a & b:
            return False
    return True

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

print(ans)

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

Solution (Python):

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)

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

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

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