#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  long long a[1000001];
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long c = 0;
  long long sub_c = 0;
  long long s = 0;
  for (long long i = 0; i < n; i++) {
    s += a[i];
    if (s == 0) {
      c = c + i + 1;
    }
  }
  cout << c << endl;
}
