fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int mod = 1e9+7;
  4. #define ll long long
  5. const int mx = 2e5+5;
  6. int main()
  7. {
  8. ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  9. ll n;cin>>n;
  10. vector<ll>v(n);
  11. for(int i=0;i<n;++i)
  12. cin>>v[i];
  13. ll m=0,cnt=0;
  14. map<ll,ll>mp;
  15. for(int i=0;i<n;++i)
  16. {
  17. m+=v[i];
  18. if(m%n==0 or v[i]%n==0)cnt++;
  19. if(mp.count(m-((m/n)*n)))
  20. {
  21. cnt+=mp[m-((m/n)*n)];
  22. }
  23. mp[m]++;
  24. }
  25. cout<<cnt<<endl;
  26. return 0;
  27. }
Runtime error #stdin #stdout #stderr 0s 4352KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc