program meow
implicit none

integer(8) :: i,j,k,n,a(300000),bits(0:300000,50)=0,test(50),ans=0,last_success=0

read(*,*) n
read(*,*) (a(i),i=1,n)

do i= 1,n
	do j= 1,50
		if(BTEST(a(i),j-1)) then
			bits(i,j) = bits(i-1,j) + 1
		else
			bits(i,j) = bits(i-1,j)
		endif
	enddo
enddo

i=1
j=1
do
	do
		test(1:50) = bits(j,1:50) - bits(i-1,1:50)
		if(maxval(test(1:50))<=1) then
!			write(*,*) i,j,"o"
			last_success = 1
			if(j==n) then
				!スコア加算
				ans = ans + (j-i+1)
				if(i==n) then
					goto 100
				else
					i = i+1
				endif
			else
				j=j+1
			endif
		else
!			write(*,*) i,j,"x"
			if(last_success==1) then
				ans = ans + (j-i)
			endif
			i=i+1
		endif
	enddo
enddo

100 continue
write(*,*) ans

end program