#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int, int> fd[] = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1),
                             make_pair(0, -1)};
signed main() {
  int n;
  cin >> n;
  int a[200000];
  cin >> a[0];
  for (int i = (1); i < (n); i++) {
    int aa;
    cin >> aa;
    a[i] = a[i - 1] + aa;
  }
  a[n] = 0;
  sort(a, a + n + 1);
  for (int i = (0); i < (n); i++) cout << a[i] << (i == n - 1 ? "\n" : " ");
  int ans = 0, seq = 1;
  for (int i = (1); i < (n); i++) {
    if (a[i] == a[i - 1]) {
      seq++;
    }
    if (a[i] != a[i - 1] || i == n - 1) {
      ans += (seq * (seq - 1) / 2);
      seq = 1;
    }
  }
  cout << ans << endl;
}
