fork 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.  
  9. ll a[n];
  10. ll b[n] = {0};
  11. cin >> a[0];
  12. a[0] = ((a[0] % n) + n) % n;
  13. b[a[0]]++;
  14.  
  15.  
  16. for (ll i = 1; i < n; i++) {
  17. cin >> c;
  18. a[i] = (a[i - 1] + c % n + n) % n;
  19. b[a[i]]++;
  20. }
  21.  
  22.  
  23. ll ans = 0;
  24.  
  25.  
  26. ans += (b[0] * (b[0] + 1)) / 2;
  27. for (ll i = 1; i < n; i++) {
  28. ans += (b[i] * (b[i] - 1)) / 2;
  29. }
  30.  
  31. cout << ans << endl;
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 5288KB
stdin
4
5 -65 -67 -67
stdout
2