Language: C++

//
// Created by Tetsuya Shiota on 2019-04-13.
//

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(e, o) for (auto &&e : o)
#ifdef LOCAL
#define pp(x) cerr << __LINE__ << ' ' << #x << " = " << (x) << endl
#define dump(x)                                                                \
  cerr << __LINE__ << ' ' << #x << " : ";                                      \
  FOR(e, x) cerr << e << ' ';                                                  \
  cerr << endl;
#else
#define pp(x)
#define dump(x)
#endif

using namespace std;

using Int = long long;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int, Int>;

const Int dy[] = {-1, 0, 1, 0};
const Int dx[] = {0, 1, 0, -1};

template <typename T> void reverse(vector<T> &v) {
  reverse(v.begin(), v.end());
}
template <typename T> void sort(vector<T> &v) { sort(v.begin(), v.end()); }
template <typename T> void rsort(vector<T> &v) { sort(v.rbegin(), v.rend()); }
template <typename T> T sum(const vector<T> &v) {
  return accumulate(v.begin(), v.end(), T(0));
}
template <class T> void update_max(T &a, const T &b) { a = max(a, b); }
template <class T> void update_min(T &a, const T &b) { a = min(a, b); }
vector<pair<char, Int>> merge_cont_char(const string &s) {
  vector<pair<char, Int>> ret;
  if (s.empty())
    return ret;
  ret.push_back(make_pair(s[0], 0));
  FOR(c, s) {
    if (ret.back().first == c)
      ret.back().second++;
    else
      ret.push_back(make_pair(c, 1));
  }
  return ret;
}

class Shakutori {
public:
  // 全体の範囲
  // [0, end)
  // 注目している範囲
  // [tail, head)
  Int head, tail, end = 0;
  bool moveHead() {
    if (head == end) {
      return false;
    }
    head++;
    return true;
  }
  void moveTail() { tail++; }
  bool valid() {
    if (head == tail)
      return true;
    // [tail, head)
    // が解として適当か検証する
    return true;
  }
  void solve() {
    head = tail = 0;
    Int ans = 0;
    while (moveHead()) {
      while (!valid()) {
        moveTail();
      }
      // ここで解を更新する
    }
  }
};

class Solver {
public:
  Int N, K;
  vi A;
  vi ans;
  vector<set<Int> > VS;
  Solver() {}
  void input() {
    cin >> N >> K;
    A = vi(N);
    FOR(a, A)cin >> a;
  }
  void solve() {
    if(N == 1){
      if(K % 2 == 0){
        return;
      }
      ans.push_back(A[0]);
      return;
    }
    // VS = vector<set<Int>>(2 * Int(1e5) + 1);
    VS = vector<set<Int>>(3 * 100000 + 1);
    rep(i, N){
      VS[A[i]].insert(i);
    }

    vi path = {0};
    {
      set<Int> visited;
      Int now = 0;

      while (visited.count(now) == 0) {
        visited.insert(now);
        bool loopFlag = 0;
        auto it = VS[A[now]].upper_bound(now);
        if (it == VS[A[now]].end()) {
          it = VS[A[now]].begin();
          loopFlag= true;
        }
        now = (*it + 1)%N;
        if(now == 0)break;
        if(loopFlag){
          path.push_back(now);
        }
      }
    }

    K--;
    dump(path);
    pp(path.size());
    K %= path.size();

    Int start = path[K];
    pp(start);
    REP(i, start, N){
      auto it = VS[A[i]].upper_bound(i);
      if(it == VS[A[i]].end()){
        ans.push_back(A[i]);
      }else{
        i = *it;
      }
    }
  }
  void output() {
    string sep = "";
    FOR(a, ans){
      cout << sep << a;
      sep = " ";
    }
    cout <<endl;
  }
};

void initilization() {
  struct BoolName : numpunct<char> {
    string t, f;
    BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
    string do_truename() const { return t; }
    string do_falsename() const { return f; }
  };
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(15) << boolalpha;
  cout.imbue(locale(cout.getloc(), new BoolName));
}

int main() {
  initilization();
#ifdef LOCAL
  while (1) {
    Solver s;
    s.input();
    if (cin.eof())
      break;
    s.solve();
    s.output();
  }
#else
  Solver s;
  s.input();
  s.solve();
  s.output();
#endif
  return 0;
}
/*
11 97
3 1 4 1 5 9 2 6 5 3 5
=> 9 2 6
 last: 5

11 96
3 1 4 1 5 9 2 6 5 3 5
=> 5
 last: 0

11 95
3 1 4 1 5 9 2 6 5 3 5
 =>
 last: 8


11 94
3 1 4 1 5 9 2 6 5 3 5

11 93
3 1 4 1 5 9 2 6 5 3 5

11 92
3 1 4 1 5 9 2 6 5 3 5
 *

Compiler output:
a.cc:210:1: error: unterminated comment
  210 | /*
      | ^