#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N], s[N + 1];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  s[0] = 0;
  for (int i = 0; i < N; i++) {
    s[i + 1] = s[i] + A[i];
  }
  sort(s, s + N + 1);
  int t = s[0];
  int k = 0;
  int c[N + 1];
  for (int i = 0; i < N + 1; i++) {
    c[i] = 0;
  }
  for (int i = 0; i < N + 1; i++) {
    if (t < s[i]) {
      t = s[i];
      k++;
      c[k]++;
    } else {
      c[k]++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < N + 1; i++) {
    if (c[i] == 0) {
      break;
    }
    ans += (long long)c[i] * (c[i] - 1) / 2;
  }
  cout << ans;
  cout << endl;
  return 0;
}
