#include <bits/stdc++.h>
int kaijo(int n) {
  if (n <= 0) return 0;
  return n == 1 ? 1 : n * kaijo(n - 1);
}
int main(void) {
  int N;
  int a[200001];
  std::cin >> N;
  for (int i = 0; i < N; i++) std::cin >> a[i];
  int ret = 0;
  for (int ib = 0; ib < N; ib++) {
    int cret = 0;
    int csum = 0;
    for (int ic = ib; ic < N; ic++) {
      csum += a[ic];
      if (!csum) {
        cret++;
      } else {
        ret += kaijo(cret);
        cret = 0;
      }
    }
    ret += kaijo(cret);
  }
  std::cout << ret << "\n";
  return 0;
}
