#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
#define ll long long
const int mx = 2e5+5;
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;cin>>n;
vector<ll>v(n);
for(int i=0;i<n;++i)
cin>>v[i];
ll m=0,cnt=0;
map<ll,ll>mp;
for(int i=0;i<n;++i)
{
m+=v[i];
if(m%n==0 or v[i]%n==0)cnt++;
if(mp.count(m-((m/n)*n)))
{
cnt+=mp[m-((m/n)*n)];
}
mp[m]++;
}
cout<<cnt<<endl;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IG1vZCA9IDFlOSs3OwojZGVmaW5lIGxsIGxvbmcgbG9uZwpjb25zdCBpbnQgbXggPSAyZTUrNTsKaW50IG1haW4oKQp7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiAgICBsbCBuO2Npbj4+bjsKICAgIHZlY3RvcjxsbD52KG4pOwogICAgZm9yKGludCBpPTA7aTxuOysraSkKICAgIAljaW4+PnZbaV07CiAgICBsbCBtPTAsY250PTA7CiAgICBtYXA8bGwsbGw+bXA7CiAgICBmb3IoaW50IGk9MDtpPG47KytpKQogICAgewogICAgCW0rPXZbaV07CiAgICAJaWYobSVuPT0wIG9yIHZbaV0lbj09MCljbnQrKzsKICAgIAlpZihtcC5jb3VudChtLSgobS9uKSpuKSkpCiAgICAJewogICAgCQljbnQrPW1wW20tKChtL24pKm4pXTsKCQl9CgkJbXBbbV0rKzsKCX0KCWNvdXQ8PGNudDw8ZW5kbDsKCXJldHVybiAwOwp9