#include <bits/stdc++.h>
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
using ll = long long;
using namespace std;
int main() {
  int n;
  long long a[21000] = {};
  cin >> n;
  long long b[21000] = {};
  b[0] = 0;
  int p = 1;
  int ans = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) b[i] = b[i - 1] + a[i - 1];
  sort(b, b + n + 1);
  for (int i = 0; i < n; i++) {
    while (b[i] == b[i + 1]) {
      p++;
      i++;
    }
    ans += p * (p - 1) / 2;
    p = 1;
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << b[i];
}
