Problem: 2052A - Adrenaline Rush
Language: python

Solution 1 (runtime: 1218 ms):
def ii():
    return int(input())
def li():
    return list(map(int,input().split()))
def si():
    return input()
def ti():
    return map(int,input().split())
def di():
    return deque((map(int,input().split())))
from math import *
from bisect import bisect_left,bisect_right
from heapq import heapify,heappop,heappush
from itertools import permutations
from collections import deque,defaultdict,Counter
def maxsubarraysum(arr,k):
    sumi=0
    best=0
    for i in range(k):
        sumi=max(arr[i],arr[i]+sumi)
        best=max(best,sumi)
    return best
def mod_inverse(a, m):
    m0 = m
    y = 0
    x = 1
    if m == 1:
        return 0
    while a > 1:
        q = a // m
        t = m
        m = a % m
        a = t
        t = y
        y = x - q * y
        x = t
    if x < 0:
        x = x + m0
    return x
def prefixsum(l,n):
    if n==0:
        return []
    array=[l[0]]
    for i in range(1,n):
        array.append(array[-1]+l[i])
    return array
def suffixsum(l,n):
    array=[0]*n
    temperory=0
    for i in range(n):
        temperory+=l[n-1-i]
        array[n-1-i]=temperory
    return array
def prime(x):
    if x==1:
        return(0)
    elif x==2:
        return(1)
    else:
        t=(sqrt(x))+1
        t=int(t)
        for i in range(2,t):
            if x%i==0:
                return(0)
        else:
            return(1)
def prefixmax(l,n):
    array=[l[0]]
    for i in range(1,n):
        array.append(max(array[-1],l[i]))
    return array
def prefixmin(l,n):
    array=[l[0]]
    for i in range(1,n):
        array.append(min(array[-1],l[i]))
    return array
def BinarySearch(a, x):
 
    i = bisect_left(a, x)
 
    if i != len(a) and a[i] == x:
 
        return i
 
    else:
 
        return -1
def sortremoveDuplicates(arr, n):
    if n == 0 or n == 1:
        return arr
 
    temp = []
    j = 0
    for i in range(0, n-1):
        if arr[i] != arr[i+1]:
            temp += [arr[i]]
            j += 1
    temp += [arr[n-1]]
    return temp
def decimalToBinary(n):
    return bin(n).replace("0b", "")
def ato1(chr):
    return ord(chr)-ord("A")
def permutationindex(l,n):
    arr=[0]*(n)
    for i in range(n):
        arr[l[i]-1]=i
    return arr
def issubsequence(s, s2):
 
    n, m = len(s), len(s2)
    i, j = 0, 0
    while (i < n and j < m):
        if (s[i] == s2[j]):
            i += 1
        j += 1
 
    # If i reaches end of s,that mean we found all
    # characters of s in s2,
    # so s is subsequence of s2, else not
    return i == n
def def_value():
    return -1
def primef(n):
    l1=[]
    i=2
    while i*i<=n:
        if n%i!=0:
            i+=1
        else:
            l1.append(i)
            while(n%i==0):
                n//=i
    if n>1:
        l1.append(n)
    return l1
"""
def search( k) :
        global ans
        if (k == len(l)) :
           if len(subset)%2==0 and len(subset)>0:
               ans+=maxi//product(subset)
           elif len(subset)>0:
               ans-=maxi//product(subset)
        else:
           search(k+1)
           subset.append(l[k])
           search(k+1)
           subset.pop()
"""
def seive(n):
    ans=[0]*(n+1)
    #primes=[]
    for i in range(2,n+1):
        if ans[i]==0:
            #primes.append(i)
            for j in range(2*i,n+1,i):
                ans[j]=i
    return ans
def inte(s,s2):
    if s[1]<s2[0] or s2[1]<s[0]:
        return 0
    return [max(s[0],s2[0]),min(s[1],s2[1])]
def checksq(x):
    z=isqrt(x)
    if z<0:
        return False
    if z*z==x:
        return True
    return False
def counti(l,n):
    l1=[]
    z=1
    for i in range(1,n):
        if l[i]==l[i-1]:
            z+=1
        else:
            l1.append([l[i-1],z])
            z=1
    l1.append([l[-1],z])
    return l1
def next(arr, target):
    start = 0; 
    end = len(arr) - 1; 
    # Minimum size of the array should be 1
    if (end == 0):
        return -1
    '''
    If target lies beyond the max element, than the index of strictly smaller
    value than target should be (end - 1)
    '''
    if (target > arr[end]):
        return end
   
    ans = -1; 
    while (start <= end): 
        mid = (start + end) // 2; 
        if (arr[mid] >= target): 
            end = mid - 1; 
        else: 
            ans = mid; 
            start = mid + 1; 
 
    return ans; 
def next1(arr, target):
    start = 0
    end = len(arr) - 1
 
    ans = -1
    while (start <= end):
        mid = (start + end) // 2
 
        # Move to right side if target is
        # greater.
        if (arr[mid] <= target):
            start = mid + 1
 
        # Move left side.
        else:
            ans = mid
            end = mid - 1
 
    return ans
def next_greatest_indices(arr):
    result = [len(arr)] * len(arr)
    stack = []
    for i in range(len(arr) - 1, -1, -1):
        while stack and arr[stack[-1]] < arr[i]:
            stack.pop()
        if stack:
            result[i] = stack[-1]
        stack.append(i)
    return result
def find_largest_index(arr, k):
    left, right = 0, len(arr) - 1
    result = -1

    while left <= right:
        mid = (left + right) // 2

        if arr[mid] < k:
            result = mid
            left = mid + 1
        else:
            right = mid - 1

    return result

import sys
input=sys.stdin.readline
for _ in range(1):
    n=ii()
    a=li()
    cur=[i for i in range(1,n+1)]
    l=[]
    for i in range(n):
        ind=0
        for j in range(n):
            if (cur[j]==a[i]):
                ind=j
                break
        for j in range(ind+1,n):
            l.append([cur[j],a[i]])
        for j in range(n-1,ind,-1):
            l.append([a[i],cur[j]])
        for j in range(ind-1,i-1,-1):
            l.append([a[i],cur[j]])
        cur.pop(ind)
        cur.insert(i,a[i])
    print(len(l))
    for i in l:
        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()