import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Bits

main :: IO ()
main = readLn >>= main'
    where
        main' n = breads >>= print . solve n 

solve :: Int -> [Int] -> Int 
solve n as = count bs bs newVec 
    where
        bs = zip [1..] as

        newVec = 0

        count (x@(ix, vx) : xs) (y@(iy, vy) : ys) vs
            | isSatisfy vy vs = count (x : xs) ys ws
            | otherwise = calc ix iy + count xs (y : ys) us
            where
                us = sub vx vs 
                ws = add vy vs 
        count ((ix, _) : _) _ _ = calc2 ix n

        isSatisfy v vs = v .&. vs == 0 

        calc x y = y - x
        calc2 x y = (v * (v + 1)) `div` 2
            where
                v = y - x + 1

        add = (.|.)
        sub = xor

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine