#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n, x, c;
cin >> n;
ll a[n];
ll b[n] = {0};
cin >> a[0];
a[0] = ((a[0] % n) + n) % n;
b[a[0]]++;
for (ll i = 1; i < n; i++) {
cin >> c;
a[i] = (a[i - 1] + c % n + n) % n;
b[a[i]]++;
}
ll ans = 0;
ans += (b[0] * (b[0] + 1)) / 2;
for (ll i = 1; i < n; i++) {
ans += (b[i] * (b[i] - 1)) / 2;
}
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCgppbnQgbWFpbigpIHsKICAgIGxsIG4sIHgsIGM7CiAgICBjaW4gPj4gbjsKCiAgICBsbCBhW25dOyAgICAgICAgICAgIAogICAgbGwgYltuXSA9IHswfTsgICAgICAKICAgIGNpbiA+PiBhWzBdOwogICAgYVswXSA9ICgoYVswXSAlIG4pICsgbikgJSBuOwogICAgYlthWzBdXSsrOwoKICAgCiAgICBmb3IgKGxsIGkgPSAxOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgY2luID4+IGM7CiAgICAgICAgYVtpXSA9IChhW2kgLSAxXSArIGMgJSBuICsgbikgJSBuOyAKICAgICAgICBiW2FbaV1dKys7CiAgICB9CgogIAogICAgbGwgYW5zID0gMDsKCiAgIAogICAgYW5zICs9IChiWzBdICogKGJbMF0gKyAxKSkgLyAyOyAKICAgIGZvciAobGwgaSA9IDE7IGkgPCBuOyBpKyspIHsKICAgICAgICBhbnMgKz0gKGJbaV0gKiAoYltpXSAtIDEpKSAvIDI7CiAgICB9CgogICAgY291dCA8PCBhbnMgPDwgZW5kbDsKCiAgICByZXR1cm4gMDsKfQo=