#include <bits/stdc++.h>
using namespace std;
int A[100010];
long long S[100010];
int main() {
  ifstream in("Text.txt");
  cin.rdbuf(in.rdbuf());
  int N;
  cin >> N;
  for (int i = 0; i < (int)N; i++) cin >> A[i];
  S[0] = 0;
  for (int i = 0; i < N; i++) {
    S[i + 1] = S[i] + A[i];
  }
  sort(S, S + N + 1);
  for (int i = 0; i < (int)(S + N + 1 - S); i++) {
    cout << *(S + i) << ' ';
  }
  cout << endl;
  int cou = 0, subcou = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == S[i + 1]) {
      subcou++;
      cou += subcou;
    } else
      subcou = 0;
  }
  cout << cou << endl;
}
