let (%) = (lxor)
let () =
  Scanf.scanf "%d" @@ fun n ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let rec ext s i =
    if i >= n then (s, i)
    else if s%a.(i) <> s+a.(i) then (s, i)
    else ext (s+a.(i)) (i+1) in

  let rec loop v s l r =
    if l >= n then v else
      let s', r' = ext s r in
      loop (v + (r'-l)) (s'-a.(l)) (l+1) r'
  in loop 0 0 0 0
  |> Printf.printf "%d\n"