import sys N = int(input()) A = [int(i) for i in input().split()] sys.stdout.flush() def isKadomatsu(a): for i in range(1,len(a) - 1): if a[i - 1] < a[i] > a[i + 1] or a[i - 1] > a[i] < a[i + 1]: return True return False ans = [] while isKadomatsu(A): i = 1 while i < len(A) - 1: if A[i - 1] < A[i] > A[i + 1]: ans.append((i - 1,i)) A[i - 1],A[i] = A[i],A[i - 1] i += 1 print(len(ans)) for i in ans: u,v = i print(u,v) sys.stdout.flush()