#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
long long a[N], n, cnt, ans, num, fail[N], sum[N];
int main() {
  scanf("%lld", &n);
  int i;
  int k = (n / 4) * 4;
  for (i = 1; i <= k;) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    if (!sum[i]) ans++;
    for (int j = 1; j < i; j++) {
      if (sum[i] - sum[j] == 0) ans++;
    }
    scanf("%d", &a[i + 1]);
    sum[i + 1] = sum[i] + a[i + 1];
    if (!sum[i + 1]) ans++;
    for (int j = 1; j < i + 1; j++) {
      if (sum[i + 1] - sum[j] == 0) ans++;
    }
    scanf("%d", &a[i + 2]);
    sum[i + 2] = sum[i + 1] + a[i + 2];
    if (!sum[i + 2]) ans++;
    for (int j = 1; j < i + 2; j++) {
      if (sum[i + 2] - sum[j] == 0) ans++;
    }
    scanf("%d", &a[i + 3]);
    sum[i + 3] = sum[i + 2] + a[i + 3];
    if (!sum[i + 3]) ans++;
    for (int j = 1; j < i + 3; j++) {
      if (sum[i + 3] - sum[j] == 0) ans++;
    }
    i += 4;
  }
  if (!(n % 4)) {
    for (i; i <= n; i++) {
      scanf("%d", &a[i]);
      sum[i] = sum[i - 1] + a[i];
      if (!sum[i]) ans++;
      for (int j = 1; j < i; j++) {
        if (sum[i] - sum[j] == 0) ans++;
      }
    }
  }
  cout << ans;
  return 0;
}
