Under construction

Still being built. Things may change

Hakuna Matata Sort

Time limit2sMemory limit1024 MB

Summary
Given a permutation of masses 1 to n, output swaps between beetles whose masses differ by at most one that sort the row in increasing order.
Level

Medium5 of 10

Topics
Sorting, Implementation, Array
Solved
No attempts yet

Problem

After a pleasant walk through the African valley, Timon and Pumbaa decided to have lunch. They took nn beetles out from under a rock and placed them on a nearby log. The beetles have distinct integer masses from 11 to nn. To make lunch more enjoyable, Pumbaa suggested eating the beetles in increasing order of mass.

To sort the beetles by increasing mass, Timon and Pumbaa use Hakuna Matata sort. In each move, they pick two beetles whose masses differ by at most one, and then swap them. For example, if Pumbaa picks the beetle with mass 2, Timon can take the beetle with mass 1 or mass 3. The two friends have used this sort many times, so they know it always works.

Zazu watched the whole process closely. He had never seen anything like it and wondered how beetles could be sorted this way. Your task is to write a program that takes the initial arrangement of the beetles and prints a sequence of moves that sorts them by increasing mass.

Input

The first line contains the number of beetles nn (1≤n≤1001 \le n \le 100). The second line contains nn distinct integers mim_i (1≤mi≤n1 \le m_i \le n) separated by spaces, where mim_i is the mass of the beetle with number ii.

Output

Print the number of moves tt on the first line. On each of the next tt lines, print two integers ii and jj, meaning that on move ss Pumbaa took the beetle at position ii and Timon took the beetle at position jj. Any sequence of moves that uses at most 50000 operations is accepted.

Examples1

  1. Example 1

    Input
    3
    2 3 1
    
    Expected output
    2
    1 3
    2 3