Problem: 2052A - Adrenaline Rush
Language: python

Solution 1 (runtime: 1186 ms):
n = int(input())

a = [int(i) for i in input().split()]

inds = [0 for i in range(n+1)]

for i in range(n):

    inds[a[i]] = i



total = 0

changes = []



l = [i+1 for i in range(n)]

for i in range(n):

    ind = l.index(a[i])



    for j in range(ind+1, n):

        changes.append([l[j], a[i]])

    for j in range(n-1, ind, -1):

        changes.append([a[i], l[j]])



    for j in range(ind-1, i-1, -1):

        changes.append([a[i], l[j]])



    l = [l[ind]] + l[:ind] + l[ind+1:]





print(len(changes))

for i in changes:

    print(*i)

Solution 2 (runtime: 2562 ms):
import os
import sys
from collections import *
from heapq import *
from math import gcd, floor, ceil, sqrt
from copy import deepcopy
from itertools import permutations, combinations, product
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
import operator
from random import getrandbits
from itertools import accumulate
from io import BytesIO, IOBase
from types import GeneratorType

input = lambda: sys.stdin.readline().rstrip("\r\n")
flush = lambda: sys.stdout.flush()
print = lambda *args, **kwargs: sys.stdout.write(' '.join(map(str, args)) + kwargs.get("end", "\n")) and flush()

sys.setrecursionlimit(100000)

def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
            else:
                stack.pop()
                if not stack:
                    break
                to = stack[-1].send(to)
        return to

    return wrappedfunc


def ints(): return map(int, input().split())
def strs(): return input().split()
def chars(): return list(input().strip())
def mat(n): return [list(ints()) for _ in range(n)]

INF = float('inf')
MOD = 1000000007
abcd = "abcdefghijklmnopqrstuvwxyz"

def add(x, y, mod=MOD): return (x + y) % mod
def sub(x, y, mod=MOD): return (x - y) % mod
def mul(x, y, mod=MOD): return (x * y) % mod

def invmod(a, mod=MOD): return powmod(a, mod - 2, mod)

def lcm(a, b): return a * b // gcd(a, b)

RANDOM = getrandbits(32)

class Wrapper(int):
    def __init__(self, x):
        int.__init__(x)
    def __hash__(self):
        return super(Wrapper, self).__hash__() ^ RANDOM

# wx = Wrapper(x)
# cnt[wx] = cnt.get(wx, 0) + 1



# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


#sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


# endregion

def main():
    n = int(input())
    a = list(ints())
    index = {it: i for i, it in enumerate(a)}
    placed = 0
    ans = []
    aux = list(range(1, n + 1))
    index_aux = {i:i for i in range(1, n + 1)}
    for placed, i in enumerate(a[::-1]):
        start = index_aux[i]
        end = aux[0]
        for j in range(start - 1, 0, -1):
            ans.append((aux[index_aux[i] - 1], aux[j - 1]))
            aux[index_aux[i] - 1], aux[j - 1] = aux[j - 1], aux[index_aux[i] - 1]
            index_aux[aux[index_aux[i] - 1]], index_aux[aux[j - 1]] = index_aux[aux[j - 1]], index_aux[
                aux[index_aux[i] - 1]]
        start = index_aux[i]
        for j in range(start + 1, (n - placed) + 1):
            ans.append((aux[j - 1], aux[index_aux[i] - 1]))
            aux[index_aux[i] - 1], aux[j - 1] =aux[j - 1], aux[index_aux[i] - 1]
            index_aux[aux[index_aux[i] - 1]], index_aux[aux[j - 1]] = index_aux[aux[j - 1]], index_aux[aux[index_aux[i] - 1]]
    print(len(ans))
    for u, v in ans:
        print(u, v)
if __name__ == "__main__":
    main()