#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <string.h>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
int GCD(int a, int b) {
	return b ? GCD(b, a%b) : a;
}
//sort(a, a + N, greater<int>())   // descend
//sort(a, a+N)                    //  ascend

using ll = long long;
using namespace std;

int main() {
	int n;
	long long a[21000]=0;
	cin >> n;
	long long b[21000]=0;
	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];
}
