import java.util.Scanner

import scala.collection.mutable

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val as = Array.fill(n)(sc.nextLong)
  val map = mutable.Map.empty[(Int, Int), Long] // (Int から Int 個) の合計
  var count = 0
  for {
    len <- 0 until n // + 1 to use
  } {
    for {
      idx <- 0 until n - len
    } {
      val aa = len + 1 match {
        case 1 =>
          as(idx)
        case ll =>
          val half = ll / 2
          val rest = ll - half
          map(idx -> half) + map(idx + half -> rest)
      }
      map.put(idx -> (len + 1), aa)
      if (aa == 0) {
        count += 1
      }
    }
  }
  println(count)
}
