Language: C++

4 5
3 2 4 1#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    set<ll> b;
    ll cnt = 0;
    ll cnter = 0;
    ll start = 0;
    vector<ll> tel;
    while (1)
    {
        if (b.count(cnt) || cnt == 1)
        {

            for (ll i = 0; i < tel.size(); i++)
            {
                if (tel[i] == cnt + 1)
                    start = i;
            }
            break;
        }

        cnt = a[cnt] - 1;
        b.insert(cnt);
        tel.emplace_back(a[cnt]);
    }
    vector<ll> s;
    if (cnt == 0)
        s.push_back(1);
    for (ll i = start; i < tel.size(); i++)
    {
        s.emplace_back(tel[i]);
    }
    cout << (k < start ? tel[k] : s[(k - start) % s.size() == 0 ? s.size() - 1 : (k - start) % s.size() == s.size() - 1 ? 0 : (k - start) % s.size() + 1]) << endl;
}

Compiler output:
a.cc:2:8: error: stray '#' in program
    2 | 3 2 4 1#include <bits/stdc++.h>
      |        ^
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 4 5
      | ^
a.cc: In function 'int main()':
a.cc:7:5: error: 'ios' has not been declared
    7 |     ios::sync_with_stdio(false);
      |     ^~~
a.cc:8:10: error: 'cin' is not a member of 'std'
    8 |     std::cin.tie(nullptr);
      |          ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | 4 5
a.cc:10:5: error: 'cin' was not declared in this scope
   10 |     cin >> n >> k;
      |     ^~~
a.cc:11:5: error: 'vector' was not declared in this scope
   11 |     vector<ll> a(n);
      |     ^~~~~~
a.cc:11:14: error: expected primary-expression before '>' token
   11 |     vector<ll> a(n);
      |              ^
a.cc:11:16: error: 'a' was not declared in this scope
   11 |     vector<ll> a(n);
      |                ^
a.cc:16:5: error: 'set' was not declared in this scope
   16 |     set<ll> b;
      |     ^~~
a.cc:16:11: error: expected primary-expression before '>' token
   16 |     set<ll> b;
      |           ^
a.cc:16:13: error: 'b' was not declared in this scope
   16 |     set<ll> b;
      |             ^
a.cc:20:14: error: expected primary-expression before '>' token
   20 |     vector<ll> tel;
      |              ^
a.cc:20:16: error: 'tel' was not declared in this scope
   20 |     vector<ll> tel;
      |                ^~~
a.cc:38:14: error: expected primary-expression before '>' token
   38 |     vector<ll> s;
      |              ^
a.cc:38:16: error: 's' was not declared in this scope
   38 |     vector<ll> s;
      |                ^
a.cc:45:5: error: 'cout' was not declared in this scope
   45 |     cout << (k < start ? tel[k] : s[(k - start) % s.size() == 0 ? s.size() - 1 : (k - start) % s.size() == s.size() - 1 ? 0 : (k - start) % s.size() + 1]) << endl;
      |     ^~~~
a.cc:45:159: error: 'endl' was not declared in this scope
   45 |     cout << (k < start ? tel[k] : s[(k - start) % s.size() == 0 ? s.size() - 1 : (k - start) % s.size() == s.size() - 1 ? 0 : (k - start) % s.size() + 1]) << endl;
      |                                                                                                                                                               ^~~~