#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
ull sum(int* p, int len) {
  ull s = 0;
  for (size_t i = 0; i < len; i++) {
    s += *p;
    p++;
  }
  return s;
}
int main() {
  int n;
  cin >> n;
  int* arr = new int[n];
  int* sum = new int[n];
  int* subscore = new int[n];
  ull ans = 0;
  for (size_t i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sum[0] = arr[0];
  subscore[0] = arr[0] == 0 ? 1 : 0;
  for (int i = 1; i < n; i++) {
    subscore[i] = subscore[i - 1];
    sum[i] = sum[i - 1] + arr[i];
    if (sum[i] == 0) {
      subscore[i]++;
    }
  }
  for (size_t i = 0; i < n; i++) {
    ans += subscore[i];
  }
  cout << ans << endl;
  return 0;
}
