fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ms(s,n) memset(s,n,sizeof(s))
  5. #define all(a) a.begin(),a.end()
  6. #define present(t, x) (t.find(x) != t.end())
  7. #define sz(a) int((a).size())
  8. #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
  9. #define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
  10. #define pb push_back
  11. #define pf push_front
  12. #define fi first
  13. #define se second
  14.  
  15. typedef long long ll;
  16. typedef unsigned long long ull;
  17. typedef long double ld;
  18. typedef pair<int,int> pi;
  19. typedef vector<int> vi;
  20. typedef vector<pi> vii;
  21.  
  22. const int MOD = (int) 1e9+7;
  23. const int INF = (int) 1e9+1;
  24. inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
  25. inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
  26.  
  27.  
  28. int main(){
  29. #ifndef ONLINE_JUDGE
  30. freopen("input.txt", "r", stdin);
  31. freopen("output.txt", "w", stdout);
  32. #endif
  33. int n; cin >> n;
  34. ll sum = 0;
  35. ll ans = 0;
  36. int cnt[n+1] ={0};
  37. cnt[0] = 1;
  38. for(int i = 0; i < n; i++){
  39. int x; cin >> x;
  40. sum += x;
  41. int remain = (sum % n + n) % n;
  42. if(cnt[remain]) ans += cnt[remain];
  43. cnt[remain]++;
  44. }
  45. cout << ans << endl;
  46. return 0;
  47. }
Runtime error #stdin #stdout 0.65s 2095788KB
stdin
Standard input is empty
stdout
Standard output is empty