Problem: 2052A - Adrenaline Rush
Language: python

Solution 1 (runtime: 1311 ms):
import math
mod=1000000007
mod1=998244353
inf=10**18+10

def swap(l1,x,y):
    a=l1[x]
    l1[x]=l1[y]
    l1[y]=a

t=1
for i in range(t):
    n=int(input())
    l1=list(map(int,input().split()))

    ind=[-1]*(n+1)
    for j in range(n):
        ind[l1[j]]=j

    l2=[j+1 for j in range(n)]
    st=set()

    ans=[]
    flag=1
    # print(l1)
    while flag:
        flag=0
        x=-1
        y=-1
        for j in range(n):
            for j1 in range(n-1):
                if l1[j1]<l1[j1+1]:
                    ans.append([l1[j1], l1[j1+1]])
                    swap(l1, j1, j1+1)
                if ind[l2[j1+1]]<ind[l2[j1]] and flag==0 and (l2[j1], l2[j1+1]) not in st:
                    # flag=1
                    x,y=j1, j1+1
                if ind[l2[j1+1]]>ind[l2[j1]]:
                    if (l2[j1], l2[j1+1]) not in st:
                        st.add((l2[j1+1],l2[j1]))
                        st.add((l2[j1],l2[j1+1]))
        # print(l1)
        for j in range(n):
            for j1 in range(n-1-j):
                if l1[j1]>l1[j1+1]:
                    ans.append([l1[j1], l1[j1+1]])
                    swap(l1, j1+1, j1)
        ans.reverse()
        if x!=-1:
            st.add((l2[y], l2[x]))
            # print(l2, ans)
            swap(l2, x, y)

    print(len(ans))
    for j in ans:
        print(*j)
    # print(ans)

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()