#include <bits/stdc++.h>
int search(int array[], int n, int find) {
  int down = 0, up = n - 1;
  while (down < up)
    if (array[(up + down) / 2] < find)
      down = (up + down) / 2 + 1;
    else
      up = (up + down) / 2;
  return array[down] == find ? down : -1;
}
int main() {
  int N;
  int A[400000];
  int sum[400000];
  int cnt = 0;
  int map[400000] = {0};
  int mapcnt[400000];
  int index = 1;
  int tmp;
  scanf("%d", &N);
  scanf("%d", &A[0]);
  sum[0] = A[0];
  for (int n = 1; n < N; n++) {
    scanf("%d", &A[n]);
    sum[n] = sum[n - 1] + A[n];
  }
  for (int n = 0; n < N; n++) {
    tmp = search(map, index, sum[n]);
    if (tmp == -1) {
      for (int i = index++ - 1; i >= 0; i--) {
        if (map[i] < sum[n]) {
          map[i + 1] = sum[n];
          mapcnt[i + 1] = 0;
          break;
        } else {
          map[i + 1] = map[i];
          mapcnt[i + 1] = mapcnt[i];
        }
      }
    } else
      cnt += ++mapcnt[tmp];
  }
  printf("%d\n", cnt);
  return 0;
}
