Language: C++

#include <bits/stdc++.h>
 
#define N 200010
 
using namespace std;
 
typedef long long ll;
 
int a[N], pre[N], nxt[N], val[N];
 
char *p1, *p2, buf[100000];
 
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )
 
int rd() {
    int x = 0;
    char c = nc();
    while (c < 48) {
        c = nc();
    }
    while (c > 47) {
        x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
    }
    return x;
}
 
ll rd2() {
    ll x = 0;
    char c = nc();
    while (c < 48) {
        c = nc();
    }
    while (c > 47) {
        x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
    }
    return x;
}
 
int First[N];
 
int main() {
    int n = rd();
    ll k = rd2();
    for (int i = 1; i <= n; i ++ ) {
        a[i] = rd();
    }
    if (n == 1) {
        if (k & 1) {
            printf("%d\n", a[1]);
        }
        return 0;
    }
    for (int i = n; i; i -- ) {
        First[a[i]] = i;
    }
    for (int i = 1; i <= n; i ++ ) {
        if (pre[a[i]]) {
            nxt[pre[a[i]]] = (i + 1) % n;
            if (!nxt[pre[a[i]]]) {
                nxt[pre[a[i]]] = n;
            }
        }
        pre[a[i]] = i;
    }
    for (int i = 1; i <= n; i ++ )
	{
        if (!nxt[i])
		{
            if (First[a[i]] != i)
                nxt[i] = First[a[i]] + 1;
            else if (i == n)
                    nxt[i] = 1;
                else
                    nxt[i] = i + 1;
            }
        }
    }
    for (int i = 1; i <= n; i ++ )
	{
        if (nxt[i] >= i + 2)
            val[i] = nxt[i] - i;
        else
            val[i] = nxt[i] + n - i;
    }
    if (nxt[n] == 1) {
        val[n] = n + 1;
    }
    ll mdl = 0;
    int now = 1;
    while (1) {
        mdl += val[now];
        now = nxt[now];
        if (now == 1) {
            break;
        }
    }
    ll pre = mdl / n;
    k %= pre;
    if(!k)
        return 0;
    int id = 1;
    now = 1;
    while (1) {
        if (nxt[now] >= now + 2) {
            now = nxt[now];
            continue;
        }
        if (id == k) {
            if (nxt[now] == 1 && now != n) {
                return 0;
            }
            printf("%d ", a[now]);
            if (now == n) {
                return 0;
            }
            now ++ ;
        }
        else {
            id ++ ;
            now = nxt[now];
        }
    }
    return 0;
}

Compiler output:
a.cc:78:5: error: expected unqualified-id before 'for'
   78 |     for (int i = 1; i <= n; i ++ )
      |     ^~~
a.cc:78:21: error: 'i' does not name a type
   78 |     for (int i = 1; i <= n; i ++ )
      |                     ^
a.cc:78:29: error: 'i' does not name a type
   78 |     for (int i = 1; i <= n; i ++ )
      |                             ^
a.cc:85:5: error: expected unqualified-id before 'if'
   85 |     if (nxt[n] == 1) {
      |     ^~
a.cc:90:5: error: expected unqualified-id before 'while'
   90 |     while (1) {
      |     ^~~~~
a.cc:97:8: error: conflicting declaration 'll pre'
   97 |     ll pre = mdl / n;
      |        ^~~
a.cc:9:11: note: previous declaration as 'int pre [200010]'
    9 | int a[N], pre[N], nxt[N], val[N];
      |           ^~~
a.cc:97:20: error: 'n' was not declared in this scope; did you mean 'yn'?
   97 |     ll pre = mdl / n;
      |                    ^
      |                    yn
a.cc:98:5: error: 'k' does not name a type
   98 |     k %= pre;
      |     ^
a.cc:99:5: error: expected unqualified-id before 'if'
   99 |     if(!k)
      |     ^~
a.cc:102:5: error: 'now' does not name a type
  102 |     now = 1;
      |     ^~~
a.cc:103:5: error: expected unqualified-id before 'while'
  103 |     while (1) {
      |     ^~~~~
a.cc:123:5: error: expected unqualified-id before 'return'
  123 |     return 0;
      |     ^~~~~~
a.cc:124:1: error: expected declaration before '}' token
  124 | }
      | ^