#AGC036B. [AGC036B] Do Not Duplicate

[AGC036B] Do Not Duplicate

Score : 700700 points

Problem Statement

We have a sequence of N×KN \times K integers: X=(X0,X1,,XN×K1)X=(X_0,X_1,\cdots,X_{N \times K-1}). Its elements are represented by another sequence of NN integers: A=(A0,A1,,AN1)A=(A_0,A_1,\cdots,A_{N-1}). For each pair i,ji, j (0iK1, 0jN10 \leq i \leq K-1,\ 0 \leq j \leq N-1), Xi×N+j=AjX_{i \times N + j}=A_j holds.

Snuke has an integer sequence ss, which is initially empty. For each i=0,1,2,,N×K1i=0,1,2,\cdots,N \times K-1, in this order, he will perform the following operation:

  • If ss does not contain XiX_i: add XiX_i to the end of ss.
  • If ss does contain XiX_i: repeatedly delete the element at the end of ss until ss no longer contains XiX_i. Note that, in this case, we do not add XiX_i to the end of ss.

Find the elements of ss after Snuke finished the operations.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1K10121 \leq K \leq 10^{12}
  • 1Ai2×1051 \leq A_i \leq 2 \times 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

A0A_0 A1A_1 \cdots AN1A_{N-1}

Output

Print the elements of ss after Snuke finished the operations, in order from beginning to end, with spaces in between.

3 2
1 2 3
2 3

In this case, X=(1,2,3,1,2,3)X=(1,2,3,1,2,3). We will perform the operations as follows:

  • i=0i=0: ss does not contain 11, so we add 11 to the end of ss, resulting in s=(1)s=(1).
  • i=1i=1: ss does not contain 22, so we add 22 to the end of ss, resulting in s=(1,2)s=(1,2).
  • i=2i=2: ss does not contain 33, so we add 33 to the end of ss, resulting in s=(1,2,3)s=(1,2,3).
  • i=3i=3: ss does contain 11, so we repeatedly delete the element at the end of ss as long as ss contains 11, which causes the following changes to ss: (1,2,3)(1,2)(1)()(1,2,3) \to (1,2) \to (1) \to ().
  • i=4i=4: ss does not contain 22, so we add 22 to the end of ss, resulting in s=(2)s=(2).
  • i=5i=5: ss does not contain 33, so we add 33 to the end of ss, resulting in s=(2,3)s=(2,3).
5 10
1 2 3 2 3
3
6 1000000000000
1 1 2 2 3 3

ss may be empty in the end.

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