fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main() {
  6. ll n,x,c;
  7. cin>>n;
  8. ll a[n];ll b[n]={0};
  9. cin>>a[0];
  10. b[a[0]%n]++;
  11. for(ll i=1;i<n;i++){
  12. cin>>c;a[i]=a[i-1]+c;
  13. b[a[i]%n]++;
  14.  
  15. }
  16. ll ans=(b[0]*(b[0]+1))/2;
  17.  
  18. for(ll i=1;i<n;i++){
  19. ans+=(b[i]*(b[i]-1))/2;}
  20.  
  21.  
  22.  
  23. cout<<ans;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 5292KB
stdin
10
0 0 0 0 0 0 0 0 0 0
stdout
55