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()))
B = []
C = []


count = 0
for a in A:
    if a != 0:
        if count != 0:
            B.append(0)
            C.append(count)
        B.append(a)
        C.append(1)
        count = 0
    else:
        count += 1
if count != 0:
    B.append(0)
    C.append(count)




N = len(B)

count = 0
for l in range(N):
    tmp = C[l] 
    tmp_count = 0
    total = B[l]
    xor = B[l]
    for r in range(l + 1, N):
        total += B[r]
        xor ^= B[r]
        if total == xor:
            tmp_count += C[r]
        else:
            break
    
    count += tmp_count * tmp
    count += (tmp * (tmp + 1)) // 2
    




print (count)

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

count = 0
for a in A:
    if a != 0:
        if count != 0:
            B.append(0)
            C.append(count)
        B.append(a)
        C.append(1)
        count = 0
    else:
        count += 1
if count != 0:
    B.append(0)
    C.append(count)




N = len(B)

count = 0
for l in range(N - 1):
    tmp = C[l] 
    tmp_count = 0
    total = B[l]
    xor = B[l]
    for r in range(l + 1, N):
        total += B[r]
        xor ^= B[r]
        if total == xor:
            tmp_count += C[r]
        else:
            break
    
    count += tmp_count * tmp
    count += (tmp * (tmp + 1)) // 2
    

count += (C[-1] * (C[-1] + 1)) // 2

print (count)

Solution (Python):

N = int(input())

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


ans = 0

nows = 0
nowx = 0
l = 0

for r in range(N):

    nows += A[r]
    nowx ^= A[r]

    while nows != nowx:
        nows -= A[l]
        nowx ^= A[l]
        l += 1

    ans += r-l+1

print (ans)

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

ans = 0
xor = 0
sum = 0
r = 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
    if l == r:
        r += 1
    else:
        sum -= a[l]
        xor ^= a[l]

print(ans)

Solution (Python):



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

    l=0
    r=0
    summury=0
    sv=0
    while r<=N-1:
        if sv+A[r] == sv ^ A[r]:
            
            sv+=A[r]
            r+=1

        else:

            cc=r-l
            summury+=cc
            
            if l==r:
                r+=1
            else:
                sv-=A[l]
                l+=1


    cc=r-l+1
    summury+=(cc-1)*cc//2
    print(summury)



if __name__ == "__main__":
    resolve()

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

res = 0
p = 0
cnt = 0

for i in range(n):

    while cnt < n:
        if p&a[cnt] == 0:
            p = p^a[cnt]
            cnt += 1
        else:
            break
    
    p = p^a[i]
    res += cnt-i

print(res)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    x = 0
    s = 0
    r = 0
    res = 0
    for l in range(N):
        while N > r:
            if s & A[r] != 0: break
            s += A[r]
            r += 1

        s -= A[l]
        res += r - l

    print(res)
if __name__ == '__main__':
    main()

Solution (Python):
def shakutori(a):
    left =0
    right = 0
    su = 0
    su1 = 0
    ans = 0
    for left in range(len(a)):
        while right<len(a) and su+a[right]==su1^a[right]:
            su +=a[right]
            su1 = su1^a[right]
            right +=1
        ans+=right -left
        if left==right:
            right+=1
        else:
            su -=a[left]
            su1 ^= a[left]
    return ans
N = int(input())
A = [int(x) for x in input().split()]
print(shakutori(A))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
cur = 0
cnt = 0
cum = A[0]
for i in range(1,N):
    if A[i]&cum==0:
        cum = cum^A[i]
    else:
        cnt += i-cur
        cum = cum^A[cur]
        cur += 1
        while cur<i:
            if cum&A[i]==0:break
            else:
                cnt += i-cur
                cum = cum^A[cur]
                cur += 1
        cum = cum^A[i]
cnt += ((N-cur)*(N-cur+1))//2
print(cnt)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()] + [(1 << 21) - 1]

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

Solution (Python):
n = int(input())
ls = list(map(int, input().split()))
res = 0
left = 0
right = 0
s0 = 0
s1 = 0
while left < n:
    while right < n and s0 + ls[right] == s1 ^ ls[right]:
        s0 += ls[right]
        s1 ^= ls[right]
        right += 1
    res += right - left
    s0 -= ls[left]
    s1 ^= ls[left]
    left += 1
print(res)

Solution (Python):
import itertools

n = int(input())
ls = [0] + list(map(int, input().split()))
s0 = list(itertools.accumulate(ls))
s1 = list(itertools.accumulate(ls, lambda a, b: a ^ b))
res = 0
left = 0
right = 1
count = 0
while left <= n:
    while left < right - 1:
        a = s0[right] - s0[left]
        b = s1[right] ^ s1[left]
        if a != b:
            left += 1
        else:
            res -= (right - left - 1) * (right - left) // 2
            break
    while right <= n + 1:
        if right == n + 1:
            break
        a = s0[right] - s0[left]
        b = s1[right] ^ s1[left]
        if a == b:
            right += 1
        else:
            break
    res += (right - left - 1) * (right - left) // 2
    if right == n + 1:
        break
print(res)

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

ans = 0
j = 1
k = 0
sum_plus = A[0]
sum_xor = A[0]
while j <= N and k < j:
    if sum_plus == sum_xor:
        ans += j-k
        if j < N:
            sum_plus += A[j]
            sum_xor ^= A[j]
        j += 1
    else:
        sum_plus -= A[k]
        sum_xor ^= A[k]
        k += 1
    
print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split())
l=r=x=s=ans=0
while l<n:
	while r<n and x^a[r]==s+a[r]:
		x^=a[r]
		s+=a[r]
		r+=1
		ans+=1
	x^=a[l]
	s-=a[l]
	l+=1
	ans+=r-l
print(ans)

Solution (Python):
def shakutori(a):
  left =0
  right = 0
  su = 0
  su1 = 0
  ans = 0
  for left in range(len(a)):
    while right<len(a) and su+a[right]==su1^a[right]:
      su +=a[right]
      su1 = su1^a[right]
      right +=1
    ans+=right -left
    if left==right:
      right+=1
    else:
      su -=a[left]
      su1 ^= a[left]
  return ans
N = int(input())
A = [int(x) for x in input().split()]
print(shakutori(A))

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

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N = I()
A = III()

d = defaultdict(list)
for i in range(N):
    A[i] = format(A[i],'b').zfill(20)
    for j,k in enumerate(A[i]):
        if k=='1':
            d[i].append(j)

used = [False]*20
l = 0
r = 0
ans = 0
for j in d[0]:
    used[j] = True

while l<=N-1:
    ans += r-l+1
    for i in range(r+1,N):
        if all([used[j]==False for j in d[i]]):
            for j in d[i]:
                used[j] = True
            r += 1
            ans += 1
        else:
            break
    for j in d[l]:
        used[j] = False
    l += 1
    if l>r:
        r = l
        for j in d[l]:
            used[j] = True
    
print(ans)

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

right = 1
xor = A[0]
sum = A[0]
ans = 0
for left in range(N):
  while right < N and xor ^ A[right] == sum + A[right]:
    xor ^= A[right]
    sum += A[right]
    right += 1
  ans += right - left
  if left == right:
    right += 1
  xor ^=A[left]
  sum -=A[left]
print(ans)

Solution (Python):
import math
import copy
 
def secize(n, k):
    n2=bin(n)
    n3=n2[2:]
    for i in range(k-len(n2)+2):
        n3='0'+n3
    return n3
 
 
n=int(input())
alist = list(map(int,input().split()))
saidai=max(alist)
keta=math.ceil(math.log(saidai+1, 2))
blist=[]
for i in range(n):
    kaz=secize(alist[i], keta)
    blist.append(kaz)
 
now1=0
now2=0
nowarr=[]
for bl in blist[0]:
    nowarr.append(int(bl))
answer=0
swit=0
while now1<=n-2 and now2<=n-2:
    """
    maearr=copy.deepcopy(nowarr)
    for i in range(keta):
        if blist[now2+1][i]=='1':
            if nowarr[i]==1:
                swit=1
            else:
                nowarr[i]=1
    """
    for i in range(keta):
        if blist[now2+1][i]=='1':
            if nowarr[i]==1:
                swit=1
            else:
                nowarr[i]=2
    if swit==1:
        for i in range(keta):
            if nowarr[i]==2:
                nowarr[i]=0
        answer+=(now2-now1+1)
        
        for i in range(keta):
            if blist[now1][i]=='1':
                nowarr[i]=0
        if now1==now2:
            nowarr=[]
            for bl in blist[now1+1]:
                nowarr.append(int(bl))
            now1+=1
            now2+=1
            if now1==n-1:
                answer+=1
        else:
            now1+=1
        swit=0
    else:
        for i in range(keta):
            if nowarr[i]==2:
                nowarr[i]=1
        if now2!=n-2:
            now2+=1
        else:
            wa=now2-now1+2
            answer+=(wa*(wa+1)//2)
            now2+=1
 

if n!=1:
    print(answer)
else:
    print(1)

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

r = 1
xor = an[0]
sums = an[0]

cnt = 0
for l in range(n):
  while xor == sums:
    if r >= n:
      r = n + 1
      break
    xor ^= an[r]
    sums += an[r]
    r += 1
    
  cnt += ((r-1) - l)
  xor ^= an[l]
  sums -= an[l]

print(cnt)

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

for left in range(n):
  while(right < n):
    if(tmp & a[right]):
      break
    tmp += a[right]
    right += 1
  ans += (right - left)
  tmp -= a[left]
  
print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
x = r = res = 0
for l in range(N):
	while r < N:
		if x & A[r]: break
		x += A[r]
		r += 1
	res += r - l
	x -= A[l]
print(res)

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

c = 0
add = 0
xor = 0
r = 0
for l in range(N):
    
    while r < N and add+A[r] == xor^A[r]:
        add += A[r]
        xor ^= A[r]
        r += 1
        
    
    c += r - l
    if l == r:
        r += 1
    else:
        add -= A[l]
        xor ^= A[l]
    

print(c)

Solution (Python):
from itertools import groupby

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

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

print(c)

Solution (Python):
def main():

    N = int(input())
    A = list(map(int, input().split()))
    v1 = 0
    v2 = 0
    i, j = 0, 0
    ans = 0
    
    while i < N:

        while i < N and v1 + A[i] == v2 ^ A[i]:
            v1 += A[i]
            v2 ^= A[i]
            i += 1

        if i < N:
            v1 += A[i]
            v2 ^= A[i]
            while j < i and v1!= v2:
                v1 -= A[j]
                v2 ^= A[j]
                ans += i-j
                j += 1
            i += 1
    ans += (i-j)*(i-j+1)//2
    return ans

if __name__ == '__main__':
    print(main())

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

r = -1; s = 0
ans = 0
for i in range(N):
    while r < N - 1 and not (s & L[r+1]):
        s ^= L[r + 1]; r += 1
    ans += r - i + 1
    s ^= L[i]
print(ans)

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

r = -1
s = 0

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

print(ans)

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

r = 0
s = 0

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

print(ans)

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

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
cumsum = [0]
cumsumx = [0]
for i in range(N):
  cumsum.append(cumsum[i] + A[i])
  cumsumx.append(cumsumx[i] ^ A[i])
res = 0
"""
for i in range(1, N + 1):
  for j in range(i, N + 1):
    
    if cumsum[j] - cumsum[i - 1] == cumsumx[j] ^ cumsumx[i - 1]:
      res += 1
"""   
for i in range(1, N + 1):
  l = i
  r = N
  j = (l + r) / 2

  while True:
    j = (l + r) // 2
    if r - l < 2:
      
      break
    if cumsum[j] - cumsum[i - 1] == cumsumx[j] ^ cumsumx[i - 1]:
      l = j
    else:
      r = j
  
  if j < N:
    if cumsum[j + 1] - cumsum[i - 1] == cumsumx[j + 1] ^ cumsumx[i - 1]:
        j += 1
  res += j - i + 1
    
print(res)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
cumsum = [0]
cumsumx = [0]
for i in range(N):
  cumsum.append(cumsum[i] + A[i])
  cumsumx.append(cumsumx[i] ^ A[i])
res = 0
"""
for i in range(1, N + 1):
  for j in range(i, N + 1):
    
    if cumsum[j] - cumsum[i - 1] == cumsumx[j] ^ cumsumx[i - 1]:
      res += 1
"""   
for i in range(1, N + 1):
  l = i
  r = N
  j = (l + r) / 2

  while True:
    j = (l + r) // 2
    if r - l < 2:
      
      break
    if cumsum[j] - cumsum[i - 1] == cumsumx[j] ^ cumsumx[i - 1]:
      l = j
    else:
      r = j
  
  if j < N:
    if cumsum[j + 1] - cumsum[i - 1] == cumsumx[j + 1] ^ cumsumx[i - 1]:
        j += 1
  res += j - i + 1
    
print(res)

Solution (Python):
def resolve():
    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
        if l==r: r+=1 
        else:
            ans+=r-l
            xor^=A[l]
            sum-=A[l]
    print(ans)
resolve()

Solution (Python):
n=int(input())
b=[int(i) for i in input().split()]
ind=1
ans=0
tmp=b[0]
for i in range(n):
    ans+=ind-i
    while ind<n:
        if tmp+b[ind]!=tmp^b[ind]:
            tmp-=b[i]
            break
        else:
            tmp+=b[ind]
            ind+=1
            ans+=1
print(ans)

Solution (Python):
n=int(input())
b=[bin(int(i))[2:] for i in input().split()]
ind=0
i=0
l=[0]*20
ans=0
tmp=0
for i in range(n):
    if i>0 and ind<n:
        for j in range(len(b[i-1]))[::-1]:
            if b[i-1][j]=="1":
                l[j-len(b[i-1])]-=1
        for j in range(len(b[ind]))[::-1]:
            if b[ind][j]=="1":
                l[j-len(b[ind])]-=1
    ans+=ind-i
    while ind<n:
        for j in range(len(b[ind]))[::-1]:
            if b[ind][j]=="1":
                l[j-len(b[ind])]+=1
        if 2 in l:
            break
        else:
            ind+=1
            ans+=1
print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = [0] + LI()
b = list(accumulate(a))
l,r,tmp,ans = 0,0,0,0
while r < n:
    if b[r+1] - b[l] == tmp ^ a[r+1]:
        tmp ^= a[r+1]
        r += 1
        ans += r-l
    elif l == r:
        tmp ^= a[l]
        l += 1
        r += 1
    else:
        l += 1
        tmp ^= a[l]
print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = [0] + LI()
b = list(accumulate(a))
l,r,tmp,ans = 0,0,0,n
while r < n:
    if b[r+1] - b[l] == tmp ^ a[r+1]:
        tmp ^= a[r+1]
        ans += r-l
        r += 1
    elif l == r:
        tmp ^= a[l]
        l += 1
        r += 1
    else:
        l += 1
        tmp ^= a[l]
print(ans)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return


def B():
    n = II()
    s = S()
    ans = 0
    for i in range(n + 1):
        s1 = list(set(s[i:]))
        s2 = list(set(s[:i]))
        b = 0
        for si in s1:
            b += si in s2
        ans = max(ans, b)
    print(ans)
    return


def C():
    n = II()
    s = S()
    dp = [0 for i in range(n)]
    for num,si in enumerate(s):
        if si == "E":
            dp[num] = dp[num-1]+1
        else:
            dp[num] = dp[num - 1]
    ans = float("INF")
    a = max(dp)
    for i in range(n):
        ans = min(ans,  a - dp[i] + i - dp[i] + (s[i] == "E"))
    
    print(ans)
    return


def D():
    n = II()
    a = LI()
    bitlength = len(bin(max(a))) - 2
    a = list(map(lambda x: bin(x)[:1:-1], a))
    cumulativebit = [[0] * bitlength for i in range(n)]
    for i in range(n):
        for bi in range(bitlength):
            cumulativebit[i][bi] += cumulativebit[i - 1][bi] + (0 if len(a[i]) <= bi else 1 if int(a[i][bi]) else 0)
    r = 0
    ans = 0
    for l in range(n):
        f = False
        cumulativebitl = cumulativebit[l]
        al = a[l]
        for r in range(r, n):
            cumulativebitr = cumulativebit[r]
            ar = a[r]
            for bi in range(bitlength):
                if cumulativebitr[bi] - cumulativebitl[bi] >= 2 or (l != r and len(ar) > bi and len(al) > bi and int(ar[bi]) and int(al[bi])):
                    f = True
                    break
            if f:
                break
        if f:
            ans += r - l
        else:
            ans += r - l + 1
    print(ans)
    return




if __name__ == '__main__':
    D()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return


def B():
    n = II()
    s = S()
    ans = 0
    for i in range(n + 1):
        s1 = list(set(s[i:]))
        s2 = list(set(s[:i]))
        b = 0
        for si in s1:
            b += si in s2
        ans = max(ans, b)
    print(ans)
    return


def C():
    n = II()
    s = S()
    dp = [0 for i in range(n)]
    for num,si in enumerate(s):
        if si == "E":
            dp[num] = dp[num-1]+1
        else:
            dp[num] = dp[num - 1]
    ans = float("INF")
    a = max(dp)
    for i in range(n):
        ans = min(ans,  a - dp[i] + i - dp[i] + (s[i] == "E"))
    
    print(ans)
    return


def D():
    n = II()
    a = LI()
    bitlength = len(bin(max(a))) - 2
    a = list(map(lambda x: bin(x)[:1:-1], a))
    cumulativebit = [[0] * bitlength for i in range(n)]
    for i in range(n):
        for bi in range(bitlength):
            cumulativebit[i][bi] += cumulativebit[i - 1][bi] + (0 if len(a[i]) <= bi else 1 if int(a[i][bi]) else 0)
    r = 0
    ans = 0
    for l in range(n):
        f = False
        for r in range(r, n):
            for bi in range(bitlength):
                if cumulativebit[r][bi] - cumulativebit[l][bi] >= 2 or (l != r and len(a[r]) > bi and len(a[l]) > bi and int(a[r][bi]) and int(a[l][bi])):
                    f = True
                    break
            if f:
                break
        if f:
            ans += r - l
        else:
            ans += r - l + 1
    print(ans)
    return




if __name__ == '__main__':
    D()

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
def xor(L):
  r = L[0]
  for i in range(1, len(L)):
    r ^= L[i]
  return r
re = 0
r = 0
s = 0
x = 0
for l in range(0, N):
  
  
  while r < N:
    
    if s+As[r] == x^As[r]:
      s += As[r]
      x ^= As[r]
    
      r += 1
    else:
      break
  s -= As[l]
  x ^= As[l]
  
  re += r-l
print(re)

Solution (Python):
N, *A = map(int, open(0).read().split())

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

    ans += r - l

    if l == r:
        r += 1
    else:
        acc -= A[l]

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
xor = 0
total = 0
cur = 0
cnt = 0
for i in range(n):
    xor = xor ^ a[i]
    total += a[i]
    if xor != total:
        while True:
            total -= a[cur]
            xor = xor ^ a[cur]
            cur += 1
            if total == xor:
                break
    cnt += (i - cur + 1)
print(cnt)

Solution (Python):
n = int(input())
aa = list(map(int, input().split()))
bit = [[0] * 21 for _ in range(n)]
for i, a in enumerate(aa):
    for j in range(21):
        a, m = divmod(a, 2)
        if m: bit[i][j] = 1


last = [-1] * 21
L = R = 0
ans = 0
while R < n:
    out = []
    nextL = []
    for j in range(21):
        if bit[R][j]:
            if last[j] == -1:
                last[j] = R
            else:
                out.append(j)
                nextL.append(last[j])
                last[j] = R
    
    if out:
        
        d1 = R - L
        L = max(nextL) + 1
        d2 = R - L + 1
        
        ans += (d1 + d2) * (d1 - d2 + 1) // 2
        for j in range(21):
            if last[j] < L:
                last[j] = -1
    R += 1
d = n - L
ans += d * (d + 1) // 2
print(ans)

Solution (Python):
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue

Mod = 1000000007




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

    print(ans)
if __name__ == "__main__":
    main() 





def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

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

ans = 0

l = 0
r = 0
s = 0
while l <= N-1 and r <= N-1:
    if s + A[r] == s ^ A[r]:
        s += A[r]
        ans += r-l+1
        r += 1
    else:
        s -= A[l]
        l += 1
            

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = 0
l,r = 0, 0
xor = a[0]
add = a[0]

while r < n and l <= r:
    if xor == add:
        ans += r - l + 1
        r += 1
        if r< n:
            xor ^= a[r]
            add += a[r]
    else:
        if l < n:
            xor ^= a[l]
            add -= a[l]
        l += 1

print(ans)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
ans=0
l,r=0,0
x,s=A[0],A[0]
while l!=n-1 or r!=n-1:
  if x==s:
    ans+=r-l+1
    if r<n-1:
      r+=1
      x^=A[r]
      s+=A[r]
    else:
      break
  else:
    l+=1
    x^=A[l-1]
    s-=A[l-1]
if l==n-1 and r==n-1:
  ans+=1
print(ans)

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

S = [0]*(N+1)
X = [0]*(N+1)
for i,a in enumerate(A,1):
    S[i] = S[i-1] + a
    X[i] = X[i-1] ^ a

l = 0
r = 0
ans = 0
while r<N:
    s = S[r+1]-S[l]
    x = X[r+1]^X[l]
    if s==x:
        r+=1
    else:
        ans += r-l
        l+=1
while l<N:
    ans += r-l
    l+=1
print(ans)

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

start = 0
end = 0
ans = 0
a_sum = A_array[0]
a_xor = A_array[0]

for start in range(N):
    while end != (N-1):
        
        a_sum_new = a_sum + A_array[end+1]
        a_xor_new = a_xor ^ A_array[end+1]
        if a_sum_new == a_xor_new:
            end += 1
            a_sum = a_sum_new
            a_xor = a_xor_new
        else:
            break
    
    ans += (end-start+1)
    a_sum -= A_array[start]
    a_xor = a_xor ^ A_array[start]

print(ans)

Solution (Python):
import math

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

m = 20

ans = n
index = 0
cs = [[0 for i in range(m)] for i in range(n+1)]
bit = [0 for i in range(m)]
for i in range(n):
    for j in range(m):
        cs[i+1][j] = cs[i][j] + ((a[i]>>j)&1)

    bit = [cs[i+1][j] - cs[index][j] for j in range(m)]
    if max(bit) >= 2:
        while max(bit) >= 2:
            k = max(i - index - 1, 0)
            ans += k
            index += 1
            bit = [cs[i+1][j] - cs[index][j] for j in range(m)]

    

k = max(n - index - 1, 0)
ans += k * (k+1) // 2

print(ans)

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

right = 0
left = 0
sumEx = 0
sumNo = 0
ans = 0

while left < N :
    while right < N :
        if (sumEx ^ A[right]) == (sumNo + A[right]) :
            sumEx += A[right]
            sumNo += A[right]
            right += 1
            continue
        break
    ans += right - left
    sumEx ^= A[left]
    sumNo -= A[left]
    left += 1

print(ans)

Solution (Python):
N = int(input())
A = [int(s) for s in input().split()]
S = [[0] * 20 for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(20):
        S[i][j] = S[i-1][j] + (1 if A[i-1] & (1 << j) else 0)

ans = 0
i = 0
for j in range(N):
    while not all(S[j + 1][v] - S[i][v] < 2 for v in range(20)):
        i += 1
    ans += j + 1 - i
print(ans)