For a permutation $p$, $f(p)$ is defined as follows:
- For an element $p_i$ in the permutation, let $a_i$ be the length of the longest increasing subsequence ending at $p_i$, and $b_i$ be the length of the longest decreasing subsequence starting at $p_i$. Define its coordinate as the ordered pair $(a_i, b_i)$.
- $f(p)$ is the set of coordinates of all elements in $p$.
For example, $f(\{1, 2, 5, 4, 3, 6\}) = \{(1, 1), (2, 1), (3, 1), (3, 2), (3, 3), (4, 1)\}$.
Given a positive integer $n$ and $n$ distinct ordered pairs $(x_1, y_1), (x_2, y_2), \dots, (x_n, y_n)$, where $x_i$ and $y_i$ are positive integers not exceeding $n$.
Construct a permutation $p$ of minimum length such that $f(p)$ contains all $n$ given pairs. $f(p)$ may contain elements other than the $n$ given pairs.
If there are multiple permutations of minimum length, output any one of them. It can be proven that under the given conditions, there always exists a permutation of length at most $3n$.
If the permutation you output is not of minimum length, but its length does not exceed the given parameter $lim$, you can still receive partial points.
Input
The first line contains two positive integers $n$ and $lim$, representing the number of pairs and the upper bound on the length of the permutation you construct, respectively.
The next $n$ lines each contain two positive integers $x_i, y_i$, indicating that $f(p)$ must contain $(x_i, y_i)$.
Output
Output two lines. The first line contains a positive integer $m$, representing the length of the permutation you constructed, where you must ensure $n \le m \le lim$.
The second line contains $m$ positive integers, representing the permutation $p$ you constructed.
Examples
Input 1
2 6 2 1 1 2
Output 1
3 2 1 3
Input 2
2 6 2 2 2 1
Output 2
3 1 3 2
Input 3
3 9 1 1 2 1 3 3
Output 3
5 1 4 5 3 2
Input 4
4 12 3 1 2 4 1 4 2 3
Output 4
7 4 6 3 5 2 1 7
Input 5
6 18 1 1 4 2 1 4 2 4 1 5 4 1
Output 5
9 5 4 6 3 2 7 9 1 8
Input 6
8 24 1 3 3 1 2 5 2 4 5 3 3 2 1 1 4 2
Output 6
10 5 9 8 1 2 4 7 10 6 3
Input 7
10 30 3 3 5 10 5 8 8 7 2 6 3 4 2 2 7 3 4 4 10 10
Output 7
22 2 9 4 6 12 15 16 18 20 21 22 14 13 11 19 10 8 7 5 17 3 1
Constraints
For all test cases, it is guaranteed that $1 \le n \le 5000$, $3n \le lim \le 15000$, and $1 \le x_i, y_i \le n$.
There are 6 subtasks in total:
| Subtask | Score | Additional Constraints |
|---|---|---|
| $1$ | $5$ | $n \le 4$ |
| $2$ | $15$ | $n \le 100, lim \ge n^2$ |
| $3$ | $25$ | $n \le 300$ |
| $4$ | $25$ | The minimum length permutation is exactly $n$ |
| $5$ | $10$ | $(x_n, y_n) = (n, n)$ |
| $6$ | $20$ | No additional constraints |
For each test case, if you successfully construct a permutation with length at most $lim$, you receive $40\%$ of the points; if you successfully construct a permutation of minimum length, you receive $100\%$ of the points. For each subtask, your score is the minimum score obtained across all test cases within that subtask.
The chk.cpp file provided in the download can be used to verify your output.