#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T1, class T2>
void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <class T1, class T2>
void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;
const ll IMF = 1LL << 29;
const double PI = 3.14159265358979323846;
int fact(int x) {
  if (x == 1) return 1;
  return x * fact(x - 1);
}
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  vector<int> sum(N + 1, 0);
  for (int i = 0; i < N; i++) {
    sum[i + 1] = sum[i] + a[i];
  }
  sort((sum).begin(), (sum).end());
  int cnt = 0, ans = 0, tmp = sum[0];
  for (int i = 0; i <= N; i++) {
    if (tmp == sum[i]) {
      cnt++;
      continue;
    } else {
      if (cnt >= 3) {
        int x = fact(cnt);
        int y = fact(cnt - 2);
        ans += x / (2 * y);
      } else if (cnt == 2)
        ans += 1;
      cnt = 1;
      tmp = sum[i];
    }
  }
  cout << ans << endl;
  return 0;
}
