import Data.Bits

f :: Int -> Int ->[Int]->[Int]->Int->Int
f _ _ [] [] ans=ans
f n c (_:xs) [] ans=f n (c-1) xs [] (ans+c)
f n c xs2@(x:xs) ys2@(y:ys) ans
       |(Data.Bits.xor n y)==n+y=f (n+y) (c+1) xs2 ys ans
       |otherwise=f (n-x) (c-1) xs ys2 (ans+c)

main = do
       e<-getLine
       e2<-getLine
       let xs=map read (words e2)::[Int]
       print $ f 0 0 xs xs 0