fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, m, s, data[202], fate = -1;
  6. string fates[] = {"magic", "left", "right", "cycle"};
  7. bool visited[202];
  8. cin >> n >> m >> s;
  9. memset(visited, false, sizeof(visited));
  10. for(int i = 1; i <= n; i++)
  11. cin >> data[i];
  12. int moves = 0;
  13. while(fate == -1) {
  14. moves++;
  15. m += data[m];
  16. if(m < 1) fate = 1;
  17. if(m > n) fate = 2;
  18. if(visited[m]) fate = 3;
  19. if(data[m] == s) fate = 0;
  20. if(fate != 3)
  21. visited[m] = true;
  22. }
  23. cout << fates[fate] << endl;
  24. cout << moves << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5280KB
stdin
8 2 13
7 5 4 2 13 -2 -3 6
stdout
cycle
4