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 itertools

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

accum_xor = []
s = 0
for i in lst:
    s = s ^ i
    accum_xor.append(s)

accum_lst = list(itertools.accumulate(lst))


s = 0
e = 0
count = 0
while s <= n-1:
    flg = False
    if s == 0:
        if accum_xor[e] == accum_lst[e]:
            e += 1
            if e >= n:
                break
        else:
            flg = True
    else:
        if accum_xor[e] ^ accum_xor[s-1] == accum_lst[e] - accum_lst[s-1]:
            e += 1
            if e >= n:
                break
        else:
            flg = True
    if flg:
        count += (e-1) - s + 1
        s += 1
        
if e == n:
    for i in range(s, n):
        count += (n-1)-i+1

print(count)

Solution (Python):
import itertools

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

accum_xor = []
s = 0
for i in lst:
    s = s ^ i
    accum_xor.append(s)

accum_lst = list(itertools.accumulate(lst))

def bisearch(start, n, accum_xor, accum_lst):
    low = start
    high = n
    while True:
        i = (low+high)//2
        if start == 0:
            if accum_xor[i] == accum_lst[i]:
                low = i
            else:
                high = i
        else:
            if accum_xor[start-1] ^ accum_xor[i] == accum_lst[i] - accum_lst[start-1]:
                low = i
            else:
                high = i
        if high - low <= 1:
            if start == 0:
                if accum_xor[high] == accum_lst[high]:
                    flg = True
                else:
                    flg = False
            else:
                if accum_xor[start-1] ^ accum_xor[high] == accum_lst[high] - accum_lst[start-1]:
                    flg = True
                else:
                    flg = False
            break
    return high if flg else low

s = 0
for i in range(n):
    a = bisearch(i, n-1, accum_xor, accum_lst) - i + 1
    s += a
print(s)

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

r = 0
l_r_max = []
A_plus = 0
A_xor = 0
flag = 0

for l in range(N):
    while r < N:
        A_plus += (A[r] if flag == 0 else -A[l - 1])
        A_xor ^= (A[r] if flag == 0 else A[l - 1])

        if A_plus == A_xor:
            r += 1
            flag = 0
            continue
        else:
            flag = 1
            break

    l_r_max.append(r - l)

print(sum(l_r_max))

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

for i in range(10**6):
    if F==E:
        
        ans+=(F-E+1)
        S=A[F+1]
        F+=1
        if F==N:
            break
    elif S^A[F+1]==S+A[F+1]:
        
        ans+=(F-E+1)
        S^=A[F+1]
        F+=1
        if F==N:
            break
    else:
        
        S^=A[E+1]
        E+=1
    
print(ans)

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

add_sum = 0
xor_sum = 0
count = 0

left = 0
right = 0
while True:
    while right < N:
        add_sum = add_sum + Ai[right]
        xor_sum = xor_sum ^ Ai[right]
        if add_sum != xor_sum:
            add_sum = add_sum - Ai[right]
            xor_sum = xor_sum ^ Ai[right]
            break
        right += 1
        count += (right - left)
    add_sum = add_sum - Ai[left]
    xor_sum = xor_sum ^ Ai[left]
    left += 1
    if left >= N:
        break

print(count)

Solution (Python):
n = int(input())

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

s = 0
x = 0
SUM = []
XOR = []
for i in range(n):
    s += data[i]
    x ^= data[i]
    SUM.append(s)
    XOR.append(x)
SUM.append(0)
XOR.append(0)


start = 0
end = 0

res = 0
F = [0]*n
while start<n:
    
    while end < n and SUM[end]-SUM[start-1] == XOR[end]^XOR[start-1]:
        end += 1
    F[start] = end
    if end == n:
        for i in range(start,n):
            F[i] = end
        break
    
    while start < n and SUM[end] - SUM[start-1] != XOR[end]^XOR[start-1]:
        F[start] = end
        start += 1
for i in range(n):
    res += F[i]-i 
print(res)

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

add_sum = 0
xor_sum = 0
count = 0

left = 0
right = 0
while True:
    while right < N:
        add_sum = add_sum + Ai[right]
        xor_sum = xor_sum ^ Ai[right]
        if add_sum != xor_sum:
            add_sum = add_sum - Ai[right]
            xor_sum = xor_sum ^ Ai[right]
            break
        right += 1
        count += (right - left)
    add_sum = add_sum - Ai[left]
    xor_sum = xor_sum ^ Ai[left]
    left += 1
    if left >= N:
        break

print(count)

Solution (Python):


import sys
import itertools as itr

N = int(input())
As = list(map(int, sys.stdin.readline().rstrip().split()))
As_p = [0] * (N+1)
As_x = [0] * (N+1)

for i in range(N):
  As_p[i+1] = As_p[i] + As[i]
  As_x[i+1] = As_x[i] ^ As[i]

i_l,i_r = 0,1
ans = 0
while i_r <= N:
  p = As_p[i_r] - As_p[i_l]
  x = As_x[i_r] ^ As_x[i_l]
  if p == x:
    if i_r - i_l > 1:
      ans += i_r - i_l - 1
    i_r += 1
  else:
    i_l += 1

print(ans+N)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    return


def B():
    return


def C():
    return


def D():
    n = I()
    a = LI()
    ans = 0
    l = 0
    r = 0
    s = 0
    while l < n and r < n:
        while s&a[r] == 0:
            s += a[r]
            r += 1
            ans += r-l
            if r == n:break
        if l==r:
            s += a[r]
            r += 1
        s -= a[l]
        l += 1
    print(ans)

def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    D()

Solution (Python):
def sigmaN(n: int) -> int:
    """sigma{i=1}{n} i = n * (n+1) / 2
    """
    return n * (n+1) // 2


def xor_sum_2(N: int, A: list) -> int:
    """Al + ... + Ar = Al ^ ... ^ Ar
    が成り立つとき、l <= i <= j <= r を満たす全ての
    (i, j) の組について
    Ai + ... + Aj = Ai ^ ... ^ Aj
    が成り立つ。
    また、
    Al + ... + Ar != Al ^ ... ^ Ar
    のとき、
    A{l-1} + Al + ... + Ar != A{l-1} ^ Al ^ ... ^ Ar
    Al + ... + Ar + A{r+1} != Al ^ ... ^ Ar ^ A{r+1}
    が成り立つ。
    したがって、まず l を固定して等式が成り立たなくなるまで r
    を増やしていき、成り立たなくなったら l を一つ進める、という
    ことを繰り返す尺取り法で O(N) になる。
    """
    r = 0              
    Sadd, Sxor = 0, 0  
    count = 0          
    overlapped = 0     
    for l in range(N):
        al = A[l]
        if Sadd != Sxor:
            
            Sadd, Sxor = Sadd - al, Sxor ^ al
            overlapped -= 1
            continue

        
        count -= sigmaN(overlapped-1)

        
        while r < N and Sadd == Sxor:
            ar = A[r]
            Sadd, Sxor = Sadd + ar, Sxor ^ ar
            overlapped += 1
            r += 1

        if Sadd == Sxor:
            
            
            
            count += sigmaN(r - l)
            break
        else:
            
            
            overlapped -= 1
            count += sigmaN((r-1) - l)

        
        Sadd, Sxor = Sadd - al, Sxor ^ al

    return count


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = xor_sum_2(N, A)
    print(ans)

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

    if N == 1:
        return 1

    ans = N
    l = 0
    r = 0
    s = A[l]
    while l < N-1:
        if r+1 < N:
            if s & A[r+1] == 0:
                r += 1
                s |= A[r]
                ans += r - l
                continue
        if l == r:
            l += 1
            r += 1
            s = A[l]
        else:
            s &= ~A[l]
            l += 1
    return ans

print(solve())

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

ans, r = 0, 0
SUM, XOR = 0, 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):
import sys
input = sys.stdin.readline

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

left = 0; right = 0; res = 0; xor = 0; ans = 0
for _ in range(N):
    if right == N and left == N:
        break
    for i in range(right,N):
        if res + A[i] == xor ^ A[i]:
            res += A[i]
            xor = xor ^ A[i]
            right += 1
        else:
            break
    ans += right - left
    if left == right:
        right += 1
    else:
        res -= A[left]
        xor -= A[left]
    left += 1

print(ans)

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


if __name__ == "__main__":
    main()

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


ans, r = 0, 0
SUM, XOR = 0, 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):
from collections import deque
N = int(input())
A = list(map(int, input().split()))
x = deque()
acc = 0
ans = 0
for a in A:
    while acc & a:
        acc ^= x.popleft()
    x.append(a)
    acc ^= a
    ans += len(x)
print(ans)

Solution (Python):
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  A = list(map(int, input().split()))
  
  a = 0
  s = A[0]
  cur = 0
  right = 1
  for left in range(N):
    while right < N and s & A[right] == 0:
      s += A[right]
      right += 1
    cur += right - left
    s -= A[left]

  print(cur)


if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
l = 0
r = 0
count = 0
while(r < n or l < n):
    if r < n and (cum[r] - cum[l]) & a[r] == 0:
        r += 1
    else:
        count += r - l
        l += 1
print(count)

Solution (Python):

n=int(input())
a=[int(i) for i in input().split()]
 
ans=0
b=0
j=0
for i in range(n):
    while j<n and b^a[j]==b+a[j]:
        b^=a[j]
        j=j+1
    ans += j-i
    b^=a[i]
print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
r = 0; sum_ = 0; res = 0; ans = 0
for l in range(N+1):
    for i in range(r,N):
        if res ^ A[i] == sum_ + A[i]:
            r += 1
            res += A[i]
            sum_ += A[i]
        else:
            break
    length = r - l
    ans += length
    if length == 0:
        r += 1
    else:
        res -= A[l]
        sum_ -= A[l]

print(ans)

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

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

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

Solution (Python):
N = int(input())
A = tuple(map(int, input().split()))
if len(A) == 1:
  print(1)
  exit()
r = 1
cnt = 1
T = A[0]
t = 1
flg = False
for l in range(N):
  while True:
    if T ^ A[r] == T + A[r]:
      t += 1
      cnt += t
      T += A[r]
      r += 1
    else:
      T -= A[l]
      t -= 1
      break
    if r == N:
      flg = True
      break
  if flg:
    break
print(cnt)

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

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


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

    ds_list = []
    for k in range(20):
        ds = [-1] * N
        ds_list.append(ds)
        half = 2 ** k
        divider = half * 2
        last = -1
        for i in range(N):
            if half <= A[i] % divider:
                ds[i] = last = i
            else:
                ds[i] = last


    cn = 0
    for r in range(N - 1, -1, -1):
        if r == 0:
            cn += 1
            break

        lp = -1
        for k in range(20):
            p = ds_list[k][r]
            if p <= 0:
                continue
            else:
                lp = max(lp, ds_list[k][p - 1])
        cn += r - lp


    print(cn)


if __name__ == '__main__':
    main()

Solution (Python):
def evaluate(digit):
    _digit = str(format(digit, "b"))
    print(_digit)
    for i in range(len(_digit)):
        if int(_digit[i]) > 1:
            return False
    return True

def func(n, a):
    digit = 0
    count = 0
    i = 0
    j = 0
    while j < n:
        while j < n:
            if digit ^ a[j] == digit + a[j]:
                digit += a[j]
                count += j - i + 1
                
                j += 1
            else:
                break
        while i < j < n:
            digit ^= a[i]
            i += 1
            break
        
    return count
"""
print(func(4, [2, 5, 4, 6]))
print(func(9, [0, 0, 0, 0, 0, 0, 0, 0, 0]))
print(func(19,[885, 8, 1, 128, 83, 32, 256, 206, 639, 16, 4, 128, 689, 32, 8, 64, 885, 969, 1]))
"""
digit = 0
n = int(input())
a = [int(i) for i in input().split()]
print(func(n, a))

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

l = 0
r = 0
sum_A = 0
res = 0

for l in range(N):
    while(r < N):
        if ((sum_A & A[r]) == 0):
            sum_A += A[r]
            r += 1
        else:
            break
    res += (r - l)
    sum_A -= A[l]

print(res)

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

r = 0
ref = 0
ans = 0
for l in range(n):
    while r < n and ref & a[r] == 0:
        ref ^= a[r]
        r += 1

    ans += r-l

    if r == l:
        r += 1
    else:
        
        ref ^= a[l]
print(ans)

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

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

    ans += r - l

    if r == l:
        r += 1
    else:
        ref ^= A[l]

print(ans)

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

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

print(ans)

Solution (Python):
n=int(input())
a=[i for i in map(int,(input().strip().split()))]
cnt=0
r=0
s=0
for l in range(n):
    while r<n:
        if s & a[r] == 0:
            s += a[r]
            r += 1
        else:
            break
    cnt += r-l
    s -= a[l]
print(cnt)

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

ans_plus = ans = 0
l = r = 0
sum = A[0]
xorsum = A[0]

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

print(ans)

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

XOR, SUM = 0, 0
r, ans = 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):


"""
参考：http://drken1215.hatenablog.com/entry/2018/05/31/015618
しゃくとり法
・ちょっとだけ整理(smとxorは一致させるから1つでよかった)
"""
 
N = int(input())
aN = list(map(int, input().split()))

l,r,ans = 0,0,0
sm = 0

while l < N:
    
    while r < N and sm + aN[r] == sm ^ aN[r]:
        sm += aN[r]
        r += 1
    
    ans += r - l
    
    sm -= aN[l]
    l += 1
print(ans)

Solution (Python):


"""
しゃくとり法
・前にやったのとか参考にして自力実装
"""
 
N = int(input())
aN = list(map(int, input().split()))

l,r,ans = 0,0,0
sm = xor = 0

while l < N:
    
    while r < N and sm + aN[r] == xor ^ aN[r]:
        sm += aN[r]
        xor ^= aN[r]
        r += 1
    
    ans += r - l
    
    sm -= aN[l]
    xor ^= aN[l]
    l += 1
print(ans)

Solution (Python):


"""
しゃくとり法
・前にやったのとか参考にして自力実装
"""
 
N = int(input())
aN = list(map(int, input().split()))

l,r,ans = 0,0,0
sm = xor = 0

while l < N:
    
    while r < N and sm + aN[r] == xor ^ aN[r]:
        sm += aN[r]
        xor ^= aN[r]
        r += 1
    
    ans += r - l
    
    
    if l == r:
        
        r += 1
    else:
        
        sm -= aN[l]
        xor ^= aN[l]
    l += 1
print(ans)

Solution (Python):


"""
しゃくとり法
・前にやったのとか参考にして自力実装
"""
 
N = int(input())
aN = list(map(int, input().split()))

l,r,ans = 0,0,0
sm = xor = 0

while l < N:
    
    while r < N and sm + aN[r] == xor ^ aN[r]:
        ans += 1
        sm += aN[r]
        xor ^= aN[r]
        r += 1
    
    ans += r - l - 1
    
    
    if l == r:
        
        r += 1
    else:
        
        sm -= aN[l]
        xor ^= aN[l]
    l += 1
print(ans)

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

count = 0
l = 0
r = 0

sum_num = a_list[0]
xor_num = a_list[0]

while l < n and r < n:
    if sum_num == xor_num:
        count += r - l + 1
        r += 1
        if r < n:
            sum_num += a_list[r]
            xor_num ^= a_list[r]
    else:
        if l < n :
            sum_num -= a_list[l]
            xor_num ^= a_list[l]
        l += 1


print(count)

Solution (Python):
n = int(input())
a = input().split()
a = [int(m) for m in a]
k = 1
i = 0
t = a[0]
count = 1
p = 0
if n != 1:
    while i < n:
        if i != 0:
            t -= a[i - 1]
            if p == 1:
                count += k - i + 1
            else:
                count += k - i
        if p != 1:
            for j in range(k, n):
                if t + a[j] == t ^ a[j]:
                    t += a[j]
                    count += 1
                    if j == n - 1:
                        k = j
                        p = 1
                        i += 1
                else:
                    k = j
                    i += 1
                    break
        else:
            i += 1
    print(count)
else:
    print(count)

Solution (Python):

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


ans = 0
l = 0
r = 0
Asum = An[0]
Axor = An[0]
while l < N and r < N:
    if Asum == Axor:
        ans += r-l+1
        r += 1
        if r < N:
            Asum += An[r]
            Axor ^= An[r]
    else:
        if l < N:
            Asum -= An[l]
            Axor ^= An[l]
        l += 1

print(ans)

Solution (Python):

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


ans = 0
l = 0
r = 0
Asum = An[0]
Axor = An[0]
while l < N and r < N:
    if Asum == Axor:
        ans += r-l+1
        r += 1
        if r < N:
            Asum += An[r]
            Axor ^= An[r]
    else:
        if l < N:
            Asum -= An[l]
            Axor ^= An[l]
        l += 1

print(ans)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
if A==[0]*N:
  print(N*(N+1)//2)
  exit()
S_xor=[A[0]]
ans=0
left=1
for i in range(1,N):
  S_xor.append(S_xor[i-1]^A[i])
  
S_xor.append(2**31-1)
A.append(2**31-1)

for i in range(N):
  if i==0:
    while S_xor[left-1]&A[left]==0 and left<=N:
      left+=1
  else:
    while (S_xor[left-1]^S_xor[i-1])&A[left]==0 and left<=N-1:
      left+=1
  ans+=left-i
print(ans)

Solution (Python):
def popcount(n):
    return bin(n).count("1")

n=int(input())
a=list(map(int,input().split()))
 
l,r=0,0
ans = 0
nsome = a[0]
nxor = a[0]
while(l < n and r<n):
    if nsome  == nxor:
        ans+=r-l+1
        r+=1
        if(r>=n):
            break
        nsome+=a[r]
        nxor ^=a[r]

    else:
        nsome-=a[l]
        nxor^=a[l]
        l+=1

print(ans)

Solution (Python):

from sys import stdin

d_in = lambda: int(stdin.readline())  
ds_in = lambda: list(map(int, stdin.readline().split()))  


N = d_in()
A_list = ds_in()

ans = 0
s, e = 0, 0
sum_As = A_list[s]
while e < N-1:
    if (sum_As & A_list[e+1]) != 0:
        ans += (e - s + 1)
        sum_As -= A_list[s]
        s += 1
        if s > e:
            e = s
            sum_As = A_list[s]
    else:
        sum_As += A_list[e+1]
        e += 1
ans += (e - s + 1) * (e - s + 2) // 2
print(ans)

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

l = 0
r = 1
num = a[0]
count = n

while r <= n-1:
    if num ^ a[r] == num + a[r]:
        num = num ^ a[r]
        count += r - l
        r += 1
    else:
        num = num & ~a[l]
        l += 1

print(count)

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

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

left = 0
right = 0
cnt = 0
temp = 0
ans = 0

while right < n:
    if temp & a[right] == 0:
        temp += a[right]
        cnt += 1
        ans += cnt
        right += 1
        
    else:
        temp -= a[left]
        cnt -= 1
        left += 1
        
print(ans)

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

r = 0
ans = 0
s = x = 0
for l in range(N):
    r = max(l,r)
    while r < N and (s+A[r]) == (x^A[r]):
        s += A[r]
        x ^= A[r]
        r += 1
    s -= A[l]
    x ^= A[l]
    ans += r - l
print(ans)

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

r = 0
ans = 0
s = x = 0
for l in range(N):
    r = max(l,r)
    while r < N and (s+A[r]) == (x^A[r]):
        s += A[r]
        x ^= A[r]
        r += 1
    s -= A[l]
    x ^= A[l]
    ans += r - l
print(ans)

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

i=0
j=1
NOW=A[0]
ANS=0
while i<N:
    if j==N:
        ANS+=(j-i)
        i+=1
        continue
    if NOW+A[j]==NOW^A[j]:
        NOW=NOW+A[j]
        j+=1
    else:
        ANS+=(j-i)
        NOW=NOW-A[i]
        i+=1      

print(ANS)

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

ans=0
syaku=0
tmp=A[-1]
for i in range(n):
    tmp-=A[i-1]
    while(1):
        if(tmp & A[syaku]):
            break
        else:
            tmp+=A[syaku]
            syaku+=1
            if(syaku==n):
                break
    if(syaku==n):
        ans+=n*(n-i) - (i+n-1)*(n-i)//2
        break
    ans+=syaku-i


print(ans)

Solution (Python):
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))
    

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


        if l >= N:
            break

    print count


if __name__ == '__main__':
    main()

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

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
X = [0] * (N + 1)
S = [0] * (N + 1)
for i in range(N):
  X[i + 1] = X[i] ^ A[i]
  S[i + 1] = S[i] + A[i]
cnt = 0
s = 0
t = 1
while True:
  while t <= N:
    if X[t] ^ X[s] == S[t] - S[s]:
      t += 1
    else:
      t -= 1
      break
  if t > N:
    t -= 1
  cnt += t - s
  if s == N - 1:
    break
  while True:
    s += 1
    if X[t] ^ X[s] == S[t] - S[s]:
      break
  if s == t:
    t += 1
print(cnt)

Solution (Python):
def run(N, A):
    r = 0
    A_sum = 0
    A_xor = 0
    A_and = 0
    r = -1
    cnt = 0
    for l in range(N):
        while (A_sum - A_xor == 2*A_and) and r < N-1:
            r += 1
            A_sum += A[r]
            A_xor ^= A[r]
            A_and &= A[r]
        if A_sum - A_xor == 2*A_and:
            cnt += r - l + 1
        else:
            cnt += r - l
        '''
        元に戻す
        xor:
        0 0 => 0
        0 1 => 1
        1 0 => 1
        1 1 => 0
        '''
        A_sum -= A[l]
        A_xor ^= A[l]
        A_and = 2*(A_sum - A_xor)
    return cnt


def main():
    N = int(input())
    A = list(map(int, input().split()))
    print(run(N, A))


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())

sum_=0
A =list(map(int,input().split()))
j=0
ans=0
sum_=0
for i in range(N):
    k=0
    while j<N and sum_+A[j]==sum_^A[j]:
        sum_+=A[j]
        ans+=j-i+1
        j+=1
    sum_-=A[i]
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
s = 0
num = 0
l = 0
for i in range(N):
    while l < N and s + A[l] == s ^ A[l]:
        s += A[l]
        l += 1
    num += l - i
    s -= A[i]

print(num)

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

XOR, SUM = 0, 0
ans, r = 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):


INF = float('inf')


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


N = int(input())

A = inpl()

right = 0
res = 0
ans = 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
    else:
        res -= A[left]

print(ans)

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

ri=0
co=0
su=0

for le in range(n):
    while ri<n and su+A[ri]==su^A[ri] :
        su+=A[ri]
        ri+=1
    co+=ri-le
    if le==ri :
        ri+=1
    else:
        su-=A[le]

print(co)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
atoz = [chr(i) for i in range(97,97+26)]

N = inp()
aa = inpl()
xorSUM = SUM = 0
r = 0
ans = 0
for l in range(N):
	while xorSUM == SUM:
		ans += r-l
		r += 1
		if r > N:
			break
		xorSUM ^= aa[r-1]
		SUM += aa[r-1]
	else:
		SUM -= aa[l]
		xorSUM ^= aa[l]
		continue
	break
print(ans)

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


def ok(l, r, on, a):
    n2 = format(a[r], '20b')
    out = -1
    for i in range(20):
        if n2[i]=='1':
            if on[i]<l:
                on[i]=r
            else:
                if out<on[i]:
                    out = on[i]
                on[i]=r
    return out

s = 0
l = 0
r = 0
on = [-1 for i in range(20)]
while True:
    if r==n:
        s += (r-l)*(r-l-1)/2 + r-l
        break
    o = ok(l, r, on, a)
    if o == -1:
        r += 1
    else:
        s += (o-l+1)*(o-l)/2 + o-l+1
        s +=(o-l+1)*(r-o-1)
        l = o+1
        r += 1
        
        
print(int(s))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
r = 0
now = 0
ans = 0
for i in range(N):
    while N > r:
        if now & A[r] != 0:
            break
        now += A[r]
        r += 1
    now -= A[i]
    ans += r-i
print(ans)

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

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

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

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


ri=0
co=0
su=0

for le in range(n):
    while ri<n and (su+A[ri]==su^A[ri]) :
        su+=A[ri]
        ri+=1
        
        
    co+=ri-le
    if le==ri :
        ri+=1
    else:
        su-=A[le]

print(co)