CSES - Aalto Competitive Programming 2024 - wk4 - Wed - Pair sort
  • Time limit: 1.00 s
  • Memory limit: 512 MB

You are given an array with 2n2n numbers; each number between 1n1\dots n occurs exactly twice. Your task is to sort the array so that each pair of duplicates occurs next to each other. The only operation you can use is swapping any two elements (not necessarily adjacent).

Show how to do sorting with at most n1n-1 swaps.

Input

The first input line has one integer nn. The second line has 2n2n numbers: the contents of the array.

Output

First print an integer kk: the number of swaps

Then, print kk lines that describe the swaps. You can print any valid solution.

Constraints

  • 1n1051 \le n \le 10^5

Example 1

Input:

3
1 2 1 3 2 3

Output:

2
1 5
3 6

Explanation:

You start with:

1 2 1 3 2 3

You swap elements in positions 11 and 55 to get:

2 2 1 3 1 3

Then you swap elements in positions 33 and 66 to get:

2 2 3 3 1 1

And now you are done.