# python3

class HeapBuilder:
    def __init__(self):
        self._swaps = []
        self._data = []

    def ReadData(self):
        n = int(input())
        self._data = [int(s) for s in input().split()]
        assert n == len(self._data)

    def WriteResponse(self):
        print(len(self._swaps))
        for swap in self._swaps:
            print(swap[0], swap[1])

    def GenerateSwaps(self):
        # The following naive implementation just sorts 
        # the given sequence using selection sort algorithm
        # and saves the resulting sequence of swaps.
        # This turns the given array into a heap, 
        # but in the worst case gives a quadratic number of swaps.
        #
        # TODO: replace by a more efficient implementation
        n = len(self._data)
        for i in range((n-1)//2, -1, -1):
            while 2*i+1 <= n-1:
                minIdx = i
                lc = 2*i+1
                rc = 2*i+2
                if lc <= n-1 and self._data[lc] < self._data[minIdx]:
                    minIdx = lc
                if rc <= n-1 and self._data[rc] < self._data[minIdx]:
                    minIdx = rc
                if i != minIdx:
                    self._swaps.append((i, minIdx))
                    self._data[i], self._data[minIdx] = self._data[minIdx], self._data[i]
                    i = minIdx
                else:
                    break
        '''
        for i in range(len(self._data)):
            for j in range(i + 1, len(self._data)):
                if self._data[i] > self._data[j]:
                    self._swaps.append((i, j))
                    self._data[i], self._data[j] = self._data[j], self._data[i]
        '''

    def Solve(self):
        self.ReadData()
        self.GenerateSwaps()
        self.WriteResponse()

if __name__ == '__main__':
    heap_builder = HeapBuilder()
    heap_builder.Solve()
