#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (N); i++) cin >> A[i];
  vector<pair<int, int>> B;
  int a = 0;
  pair<int, int> zero(0, 0);
  for (int i = 0; i < N; i++) {
    if (a == 0) {
      a += A[i];
      zero.second = i;
    } else {
      a += A[i];
      zero.second = i;
      if (a == 0) {
        B.push_back(zero);
        a -= A[zero.first];
        zero.first++;
        continue;
      }
      if (a - A[i] > 0 && A[i] < 0) {
        while (a < 0 && A[zero.first] < 0) {
          a -= A[zero.first];
          zero.first++;
          if (a == 0) {
            B.push_back(zero);
            a -= A[zero.first];
            zero.first++;
            break;
          }
        }
      } else if (a - A[i] < 0 && A[i] > 0) {
        while (a > 0 && A[zero.first] > 0) {
          a -= A[zero.first];
          zero.first++;
          if (a == 0) {
            B.push_back(zero);
            a -= A[zero.first];
            zero.first++;
            break;
          }
        }
      }
    }
  }
  for (int i = zero.first; i < zero.second; i++) {
    a -= A[i];
    zero.first = i + 1;
    if (a == 0) {
      B.push_back(zero);
    }
  }
  int n = int(B.size());
  vector<bool> C(n, true);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (C[i]) {
      long long v = 1;
      C[i] = false;
      int aa = i;
      while (aa + 1 < n) {
        if (B[aa].second + 1 == B[aa + 1].first && C[aa + 1]) {
          C[a + 1] = false;
          aa++;
          v++;
        } else if (aa + 2 < n) {
          if (B[aa].second + 1 == B[aa + 2].first && C[aa + 2]) {
            C[a + 2] = false;
            aa++;
            v++;
          } else
            break;
        } else
          break;
      }
      ans += v * (v + 1) / 2;
    }
  }
  cout << ans << endl;
  return 0;
}
