#include <bits/stdc++.h>
using namespace std;
int main(int, char**) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = 0;
  vector<long long> minusMaxs(n + 1, 0);
  long long minMax = 0;
  for (int i = n - 1; 0 < i; --i) {
    minMax += a[i];
    if (minMax < 0) {
      minusMaxs[i] = minMax;
    } else {
      minMax = 0;
    }
  }
  vector<int> b(n + 1, 0);
  for (int i = 0; i < n; ++i) {
    long long sum = a[i];
    long long bef = b[i];
    if (sum == 0) {
      b[i + 1] += bef + 1;
      ans += bef + 1;
      continue;
    }
    if (0 < sum + minusMaxs[i + 1]) continue;
    for (int j = i + 1; j < n; ++j) {
      sum += a[j];
      if (sum == 0) {
        b[j + 1] += bef + 1;
        ans += bef + 1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
