#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];
b[a[0]%n]++;
for(ll i=1;i<n;i++){
cin>>c;a[i]=a[i-1]+c;
b[a[i]%n]++;
}
ll ans=(b[0]*(b[0]+1))/2;
for(ll i=0;i<n;i++){
ans+=(b[i]*(b[i]-1))/2;}
cout<<ans;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiAKaW50IG1haW4oKSB7CmxsIG4seCxjOwpjaW4+Pm47CmxsIGFbbl07bGwgYltuXT17MH07CmNpbj4+YVswXTsKYlthWzBdJW5dKys7CmZvcihsbCBpPTE7aTxuO2krKyl7CiAgICBjaW4+PmM7YVtpXT1hW2ktMV0rYzsKYlthW2ldJW5dKys7CgogICB9CiAgbGwgYW5zPShiWzBdKihiWzBdKzEpKS8yOwogIAogZm9yKGxsIGk9MDtpPG47aSsrKXsKYW5zKz0oYltpXSooYltpXS0xKSkvMjt9CiAKIAogCmNvdXQ8PGFuczsKIAoJcmV0dXJuIDA7Cn0=