#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 1e6 + 5;
map<int, vector<int>> mp;
int T[maxn];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, x;
cin >> n;
mp[0].push_back(0);
cout<<T[0]<<" ";
for (int i = 1; i <= n; ++i) {
cin >> x;
T[i] = T[i - 1] + x;
mp[T[i]].push_back(i);
cout<<T[i]<<" ";
}
int res = 0;
cout<<endl;
for (int i = 1; i < n; ++i) {
auto it = lower_bound(mp[T[i + 1]].begin(), mp[T[i + 1]].end(), i + 1) - mp[T[i + 1]].begin();
auto it2 = lower_bound(mp[T[i]].begin(), mp[T[i]].end(), i) - mp[T[i]].begin();
res += (it * (mp[T[i]].size() - it2 - 1));
}
cout << res;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSB1bGwgdW5zaWduZWQgbG9uZyBsb25nCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgYWxsKHgpIHguYmVnaW4oKSwgeC5lbmQoKQp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgbWF4biA9IDFlNiArIDU7Cm1hcDxpbnQsIHZlY3RvcjxpbnQ+PiBtcDsKaW50IFRbbWF4bl07CmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiAgICBpbnQgbiwgeDsKICAgIGNpbiA+PiBuOwogICAgbXBbMF0ucHVzaF9iYWNrKDApOwogICAgY291dDw8VFswXTw8IiAiOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgY2luID4+IHg7CiAgICAgICAgVFtpXSA9IFRbaSAtIDFdICsgeDsKICAgICAgICBtcFtUW2ldXS5wdXNoX2JhY2soaSk7CiAgICAgICAgY291dDw8VFtpXTw8IiAiOwogICAgfQogICAgaW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