import Data.Bits ((.&.))
import Data.Array.IArray(Array,listArray,(!))

main = do
    n <- read <$> getLine
    list <- (fmap read . words) <$> getLine
    putStrLn $ show $ solve n 1 1 0 (listArray (1,n) list) 0

solve :: Int -> Int -> Int -> Int -> Array Int Int -> Int -> Int
solve lim l r bsum numls ac
    | l>lim = ac
    | length numls>=r = do
        let target = numls!r
        case bsum.&.target==0 of
            True -> solve lim l (r+1) (bsum+target) numls (ac+r-l+1)
            False -> shiftL
    | otherwise = shiftL
        where
            shiftL = solve lim (l+1) r (bsum-(numls!l)) numls ac
