#include <iostream>
#include <bits/stdc++.h>
#define Yosry ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define ll long long
#define int long long
using namespace std;
void solve() {
int n ;
cin >> n ;
vector<int> v(n);
int N = 3e5;
vector<int> freq(N);
freq[0]=1;
int ans{};
for (int i = 0; i < n; ++i) {
cin >> v[i];
if (i)v[i]+=v[i-1];
v[i]%=n;
if (v[i]<0)v[i]+=n;
ans+=freq[v[i]];
freq[v[i]]++;
}
cout << ans ;
}
signed main() {
Yosry
int t=1;
// cin >> t;
while (t--) {
solve();
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBZb3NyeSBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSksIGNpbi50aWUobnVsbHB0ciksIGNvdXQudGllKG51bGxwdHIpOwojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGludCBsb25nIGxvbmcKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgoKdm9pZCBzb2x2ZSgpIHsKICAgIGludCBuIDsKICAgIGNpbiA+PiBuIDsKICAgIHZlY3RvcjxpbnQ+IHYobik7CiAgICBpbnQgTiA9IDNlNTsKICAgIHZlY3RvcjxpbnQ+IGZyZXEoTik7CiAgICBmcmVxWzBdPTE7CiAgICBpbnQgYW5ze307CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIGNpbiA+PiB2W2ldOwogICAgICAgIGlmIChpKXZbaV0rPXZbaS0xXTsKICAgICAgICB2W2ldJT1uOwogICAgICAgIGlmICh2W2ldPDApdltpXSs9bjsKICAgICAgICBhbnMrPWZyZXFbdltpXV07CiAgICAgICAgZnJlcVt2W2ldXSsrOwogICAgfQogICAgY291dCA8PCBhbnMgOwoKCgoKfQoKc2lnbmVkIG1haW4oKSB7CiAgICBZb3NyeQogICAgaW50IHQ9MTsKLy8gICAgY2luID4+IHQ7CiAgICB3aGlsZSAodC0tKSB7CiAgICAgICAgc29sdmUoKTsKICAgIH0KfQo=