atcoder#ARC134D. [ARC134D] Concatenate Subsequences

[ARC134D] Concatenate Subsequences

Score : 600600 points

Problem Statement

Given is an integer sequence aa of length 2N2N.

Snuke is going to make a sequence using a non-empty (not necessarily contiguous) subsequence x=(x1,x2,,xk)x=(x_1,x_2,\ldots,x_k) of (1,2,,N)(1,2, \ldots, N). The sequence will be made by extracting and concatenating the x1x_1-th, x2x_2-th, \ldots, xkx_k-th, (x1+N)(x_{1}+N)-th, \ldots, (xk+N)(x_{k}+N)-th elements of aa in this order.

Find the lexicographically smallest sequence that Snuke can make.

Lexicographical order on sequences

Here is the algorithm to determine the lexicographical order between different sequences SS and TT.

Below, let SiS_i denote the ii-th element of SS. Also, if SS is lexicographically smaller than TT, we will denote that fact as S<TS \lt T; if SS is lexicographically larger than TT, we will denote that fact as S>TS \gt T.

  1. Let LL be the smaller of the lengths of SS and TT. For each i=1,2,,Li=1,2,\dots,L, we check whether SiS_i and TiT_i are the same.
  2. If there is an ii such that SiTiS_i \neq T_i, let jj be the smallest such ii. Then, we compare SjS_j and TjT_j. If SjS_j is smaller than TjT_j in numerical order, we determine that S<TS \lt T and quit; if SjS_j is greater than TjT_j, we determine that S>TS \gt T and quit.
  3. If there is no ii such that SiTiS_i \neq T_i, we compare the lengths of SS and TT. If SS is shorter than TT, we determine that S<TS \lt T and quit; if SS is longer than TT, we determine that S>TS \gt T and quit.

Constraints

  • All values in input are integers.
  • 1N1051 \leq N \leq 10^5
  • 1ai1091 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

NN

a1a_{1} \cdots a2Na_{2N}

Output

Print the lexicographically smallest sequence that Snuke can make.

3
2 1 3 1 2 2
1 2
  • We choose x=(2)x = (2).
  • Then, the resulting sequence will be (1,2)(1,2), the lexicographically smallest possible result.
10
38 38 80 62 62 67 38 78 74 52 53 77 59 83 74 63 80 61 68 55
38 38 38 52 53 77 80 55
12
52 73 49 63 55 74 35 68 22 22 74 50 71 60 52 62 65 54 70 59 65 54 60 52
22 22 50 65 54 52