#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < (n); i++) cin >> v[i];
  vector<long long> sum(n + 1);
  for (int i = 0; i < (n); i++) {
    sum[i + 1] = sum[i] + v[i];
  }
  map<long long, long long> mp;
  for (int i = 0; i < (n + 1); i++) {
    mp[sum[i]]++;
  }
  for (int i = 0; i < (n + 1); i++) cout << sum[i] << endl;
  long long ans = 0;
  for (auto p : mp) {
    ans += p.second * (p.second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
