fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int Mod(int x, int m) {
  6. x = (x % m);
  7. if (x < 0) {
  8. x += m;
  9. }
  10. return x;
  11. }
  12.  
  13. int main() {
  14. ios_base::sync_with_stdio(0);
  15. cin.tie(0);
  16.  
  17. int n, c, ci, s;
  18. int pos = 0, cnt = 0;
  19. cin >> n >> c >> s;
  20. --s;
  21. if (pos == s) {
  22. ++cnt;
  23. }
  24. for (int i = 0; i < c; ++i) {
  25. cin >> ci;
  26. pos += ci;
  27. pos = Mod(pos, n);
  28. if (pos == s) {
  29. ++cnt;
  30. }
  31. }
  32. cout << cnt << '\n';
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5288KB
stdin
2 2 1
-1 -1
stdout
2