Language: C++

// #include <bits/stdc++.h>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
#define int long long 

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<LL, LL> PLL;
 
const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF * INF;
const long double PI = acos(-1.);
const double EPS = 1e-6;
LL mod = INF + 7;

const int maxn = 100010;

VI arr[200010];
PII g[200010];
int G[200010];

void main()
{
//  freopen("input.txt","r",stdin);
    LL n,k;
    cin >> n >> k;
    VI A(n);
    FOR(i,0,n)
    {
        int x; cin >> x;
        arr[x].PB(i);
        A[i] = x;
    }
    // cout << "ok" << endl;
    // return 0;
    FOR(i,0,2*maxn)
    {
        FOR(j,0,SZ(arr[i]))
        {
            int to = arr[i][(j+1)%SZ(arr[i])];
            // if(i==1)
            //     cout << to << endl;
            g[arr[i][j]] = MP((to+1)%n,0);
            if(SZ(arr[i])==1 || g[arr[i][j]].f < arr[i][j])
            {
                g[arr[i][j]].s = 1;
            }
        }
    }
    RFOR(i,n,0)
    {
        G[i] = g[i].f;
        if(g[i].s==1)
        {
            continue;
        }
        else
        {
            int to = g[i].f;
            g[i].f = g[to].f;
            g[i].s = 1;
        }
        // cout << g[i].f << " ";
    }
    // cout << endl;
    int lastind = 0;
    int d = 0;
    map<int,int> foo1;
    set<int> foo2;
    int cycle;
    k--;
    // cout << k << endl;
    while(k)
    {
        int to = g[lastind].f;
        // cout << k << " " << lastind << " " << to << endl;
        if(foo2.count(lastind))
        {
            cycle = d-foo1[lastind];
            // cout << cycle << " " << k << endl;
            k %= cycle;
            if(k==0)
                k = cycle;
            break;
        }
        else
        {
            foo1[lastind] = d;
            foo2.insert(lastind);
            lastind = to;
            d++;   
            k--;
        }
    }
    FOR(i,0,k)
        lastind = g[lastind].f;
    // cout << lastind << endl;
    while(G[lastind]>1+lastind)
        lastind = G[lastind];
    // cout << lastind << endl;
    FOR(i,lastind,n)
    {
        if(i+1 < G[i])
        {
            i = G[i]-1;
        }
        else
        {
            if(G[i]==0 && i!=n-1)
            {
                return;
            }
            cout << A[i] << " ";
        }
    }
    return;
}

Compiler output:
a.cc:58:1: error: '::main' must return 'int'
   58 | void main()
      | ^~~~
a.cc: In function 'int main()':
a.cc:147:17: error: return-statement with no value, in function returning 'int' [-fpermissive]
  147 |                 return;
      |                 ^~~~~~
a.cc:152:5: error: return-statement with no value, in function returning 'int' [-fpermissive]
  152 |     return;
      |     ^~~~~~