#include <bits/stdc++.h>
using namespace std;
int a[334334], cnt[334334];
int n, memo = 0, ans = 0, cnta = 0;
signed main() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    memo += a[i];
    cnt[i] = memo;
  }
  sort(cnt, cnt + n);
  for (long long i = 0; i < n; i++) {
    if (cnt[i] == 0) cnta++;
  }
  for (long long i = 0; i < n; i++) {
    if (cnt[i] == cnt[i + 1]) continue;
    ans += (upper_bound(cnt, cnt + n, cnt[i]) -
            lower_bound(cnt, cnt + n, cnt[i])) *
           ((upper_bound(cnt, cnt + n, cnt[i]) -
             lower_bound(cnt, cnt + n, cnt[i])) -
            1) /
           2;
  }
  if (cnt[n - 1] == 0) ans += cnta * (cnta - 1) / 2;
  cout << cnta + ans << endl;
  getchar();
  getchar();
  return 0;
}
