#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
long long ans = 0;
long long a[2000011];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i) a[i] += a[i - 1];
  }
  sort(a, a + n);
  int isSame = 0;
  long long l = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) ans++;
    if (i) {
      if (a[i] == a[i - 1]) {
        l++;
      } else {
        ans += ((l * (l - 1)) / 2);
        l = 1;
      }
    }
  }
  ans += (l * (l - 1)) / 2;
  for (int i = 0; i < n; i++) cout << a[i] << endl;
  cout << ans << endl;
  return 0;
}
