import Data.Bits
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
main=print.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(n:as)=f 0 0 0 0 where
  vs=V.fromList as
  f s x l r
    |r>=n=let k=(r-l)in s+k*(k+1)`div`2
    |x .&. a==0=f s(xor x a)l(r+1)
    |otherwise=f(s+r-l)(xor x$vs V.! l)(l+1)r
    where a=vs V.! r