Madeline has an array $a$ of $n$ integers. A pair $(u, v)$ of integers forms an inversion in $a$ if:

  $1 \le u < v \le n$.  $a_u > a_v$. 

Madeline recently found a magical paper, which allows her to write two indices $u$ and $v$ and swap the values $a_u$ and $a_v$. Being bored, she decided to write a list of pairs $(u_i, v_i)$ with the following conditions:

  all the pairs in the list are distinct and form an inversion in $a$.  all the pairs that form an inversion in $a$ are in the list.  Starting from the given array, if you swap the values at indices $u_1$ and $v_1$, then the values at indices $u_2$ and $v_2$ and so on, then after all pairs are processed, the array $a$ will be sorted in non-decreasing order. 

Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them.


-----Input-----

The first line of the input contains a single integer $n$ ($1 \le n \le 1000$) — the length of the array.

Next line contains $n$ integers $a_1,a_2,...,a_n$ $(1 \le a_i \le 10^9)$  — elements of the array.


-----Output-----

Print -1 if no such list exists. Otherwise in the first line you should print a single integer $m$ ($0 \le m \le \dfrac{n(n-1)}{2}$) — number of pairs in the list.

The $i$-th of the following $m$ lines should contain two integers $u_i, v_i$ ($1 \le u_i < v_i\le n$).

If there are multiple possible answers, you may find any of them.


-----Examples-----
Input
3
3 1 2

Output
2
1 3
1 2

Input
4
1 8 1 6

Output
2
2 4
2 3

Input
5
1 1 1 2 2

Output
0



-----Note-----

In the first sample test case the array will change in this order $[3,1,2] \rightarrow [2,1,3] \rightarrow [1,2,3]$.

In the second sample test case it will be $[1,8,1,6] \rightarrow [1,6,1,8] \rightarrow [1,1,6,8]$.

In the third sample test case the array is already sorted.

Difficulty: VERY_HARD

Solutions:
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
n = val()
l = li()
l1 = []
for i in range(n):
	for j in range(i + 1, n):
		if l[i] > l[j]:
			l1.append([l[i], i, j])
print(len(l1))
l1.sort()
l1.sort(reverse=1, key=lambda x: x[-1])
for (_, i, j) in l1:
	print(i + 1, j + 1)


n = int(input())
a = list(map(int, input().split()))
ans = []

def f(l):
	return (-l[1], l[2], l[0])
for i in range(n):
	for j in range(i + 1, n):
		if a[i] > a[j]:
			ans.append((i + 1, j + 1, a[i]))
ans.sort(key=f)
print(len(ans))
for i in ans:
	print(*i[:2])


n = int(input())
s = [int(x) for x in input().split()]
kk = []
for i in range(n):
	h = []
	kk.append(h)
for i in range(0, len(s)):
	for j in range(i + 1, len(s)):
		if s[i] > s[j]:
			kk[j].append((s[i], i))
for i in range(0, n):
	kk[i].sort()
fnl = []
for i in range(n - 1, -1, -1):
	for j in range(0, len(kk[i])):
		fnl.append((i, kk[i][j][1]))
print(len(fnl))
for i in range(0, len(fnl)):
	print(fnl[i][1] + 1, fnl[i][0] + 1)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def issorted(a):
	for i in range(1, len(a)):
		if a[i - 1] > a[i]:
			return False
	return True
n = mint()
a = list(mints())
inv = []
for i in range(1, n):
	for j in range(i):
		if a[i] < a[j]:
			inv.append((i, -a[j], -j))
inv.sort(reverse=True)
r = list(range(len(inv)))
if r is not None:
	print(len(r))
	for z in r:
		(v, _, u) = inv[z]
		u = -u
		print(u + 1, v + 1)
else:
	print('wut')


(n, a, inv) = (int(input()), list(map(int, input().split())), [])
for i in range(1, n):
	for j in range(i):
		if a[i] < a[j]:
			inv.append((i, -a[j], -j))
inv.sort(reverse=True)
r = list(range(len(inv)))
if r is not None:
	print(len(r))
	for z in r:
		(v, _, u) = inv[z]
		u = -u
		print(u + 1, v + 1)
else:
	print('wut')


length = int(input())
arr = [int(x) for x in input().split()]
sorting_by = []
for num in range(length):
	for i in range(num + 1, length):
		if arr[num] > arr[i]:
			sorting_by.append((arr[num], num + 1, i + 1))
sorting_by.sort()
sorting_by.sort(key=lambda x: -x[2])
print(len(sorting_by))
for pair in sorting_by:
	print(pair[1], pair[2])


n = int(input())
arr = [int(i) for i in input().split()]
inversions = []
for i in range(n):
	for j in range(i + 1, n):
		if arr[i] > arr[j]:
			inversions.append((arr[i], i + 1, j + 1))
inversions.sort(key=lambda tup: (-tup[2], tup[0]))
print(len(inversions))
for i in inversions:
	print(i[1], i[2])


import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split() if i != '\n']
copy = a[:]
copy.sort()
store = defaultdict(list)
for i in range(n - 1, 0, -1):
	for j in range(i):
		if a[i] < a[j]:
			store[i + 1].append([a[j], j + 1])
	store[i + 1].sort()
ans = []
for i in store:
	ok = False
	last = []
	for j in store[i]:
		ans.append([j[1], i])
print(len(ans))
for i in ans:
	print(*i)


inf = int(1000000.0)
n = int(input())
lis = list(map(int, input().split()))
store = []
index = list(range(0, n))
for k in range(1, n):
	for _ in range(k):
		for i in range(1, k + 1):
			if lis[i] < lis[i - 1]:
				(lis[i], lis[i - 1]) = (lis[i - 1], lis[i])
				(index[i], index[i - 1]) = (index[i - 1], index[i])
				store.append((index[i] + 1, index[i - 1] + 1))
store.reverse()
print(len(store))
for i in store:
	print(*i)


n = int(input())
a = [int(i) for i in input().split()]
ans = 0
dc = [[] for i in range(n)]
for i in range(n):
	for j in range(i):
		if a[i] < a[j]:
			dc[i].append((a[j], j))
			ans += 1
print(ans)
for i in range(n - 1, -1, -1):
	dc[i].sort()
	for j in dc[i]:
		print(j[1] + 1, i + 1)


from sys import stdin, stdout

def main():
	n = int(stdin.readline())
	ary = list(map(int, stdin.readline().split()))
	invs = [[False for i in range(n)] for j in range(n)]
	pair = []
	for i in range(n):
		pair.append((ary[i], i))
	pair.sort()
	perm = [-1] * n
	fxa = [-1] * n
	posof = [-1] * n
	for i in range(n):
		perm[pair[i][1]] = i
		fxa[i] = pair[i][0]
		posof[i] = pair[i][1]
	del pair
	answers = []
	for i in range(n - 1, -1, -1):
		for j in range(perm[i] + 1, n):
			if posof[j] < posof[perm[i]]:
				answers.append(' '.join(map(str, (posof[j] + 1, i + 1))))
	stdout.write(str(len(answers)) + '\n')
	stdout.write('\n'.join(answers))
	return
main()


from heapq import *
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def solve():
	ai = [(a, i) for (i, a) in enumerate(aa)]
	ai.sort()
	for (na, (a, i)) in enumerate(ai):
		aa[i] = na
	ans = []
	for i in range(n - 1, 0, -1):
		hp = []
		for j in range(i - 1, -1, -1):
			if aa[j] > aa[i]:
				heappush(hp, (aa[j], j))
		while hp:
			(a, j) = heappop(hp)
			aa[j] = aa[i]
			aa[i] = a
			ans.append((j, i))
	print(len(ans))
	for (i, j) in ans:
		print(i + 1, j + 1)
n = II()
aa = LI()
solve()


length = int(input())
numbers = [int(x) for x in input().split()]
inversions = []
for x in range(length):
	for y in range(x + 1, length):
		if numbers[x] > numbers[y]:
			inversions.append((numbers[x], x + 1, y + 1))
inversions.sort()
inversions.sort(key=lambda tup: -tup[2])
print(len(inversions))
for i in inversions:
	print(i[1], i[2])


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 9
mod = 998244353
step = [(1, 0), (-1, 0), (0, 1), (0, -1)]
n = int(data())
a = mdata()
a1 = []
for i in range(n):
	a1.append((a[i], i))
a1 = sorted(a1)
ans = []
for i in range(n - 1, -1, -1):
	k = 0
	while a1[k][1] != i:
		k += 1
	for j in range(k + 1, n):
		if a1[k][1] > a1[j][1]:
			(a[a1[k][1]], a[a1[j][1]]) = (a[a1[j][1]], a[a1[k][1]])
			ans.append(str(a1[j][1] + 1) + ' ' + str(a1[k][1] + 1))
flag = True
for i in range(n - 1):
	if a[i] > a[i + 1]:
		flag = False
		break
if flag == True:
	out(len(ans))
	out('\n'.join(ans))
else:
	out(-1)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def issorted(a):
	for i in range(1, len(a)):
		if a[i - 1] > a[i]:
			return False
	return True

def stupid(a, inv, was, order):
	if len(order) == len(inv) and issorted(a):
		return order
	for i in range(len(inv)):
		if was[i] == 0:
			was[i] = 1
			order.append(i)
			(x, _, y) = inv[i]
			y = -y
			(a[x], a[y]) = (a[y], a[x])
			r = stupid(a, inv, was, order)
			(a[x], a[y]) = (a[y], a[x])
			was[i] = 0
			if r is not None:
				return r
			order.pop()
	return None
n = mint()
a = list(mints())
inv = []
for i in range(1, n):
	for j in range(i):
		if a[i] < a[j]:
			inv.append((i, -a[j], -j))
inv.sort(reverse=True)
r = list(range(len(inv)))
if r is not None:
	print(len(r))
	for z in r:
		(v, _, u) = inv[z]
		u = -u
		print(u + 1, v + 1)
else:
	print('wut')


n = int(input())
lst = [int(j) for j in input().split()]
inversions = list()
for i in range(1, n):
	for j in range(i):
		if lst[i] < lst[j]:
			inversions.append((i, -lst[j], -j))
inversions.sort(reverse=True)
res = list(range(len(inversions)))
if res:
	print(len(res))
	for elem in res:
		(v, _, u) = inversions[elem]
		u = -u
		print(u + 1, v + 1)
else:
	print(0)


I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
ans = []
for i in range(n):
	for j in range(i + 1, n):
		if l[i] > l[j]:
			ans.append([l[i], i + 1, j + 1])
ans.sort()
ans.sort(reverse=True, key=lambda x: x[2])
print(len(ans))
for i in ans:
	print(i[1], i[2])


n = int(input())
arr = list(map(int, input().split()))
brr = []
for i in range(n):
	for j in range(i + 1, n):
		if arr[i] > arr[j]:
			brr.append((arr[i], i + 1, j + 1))
brr.sort()
brr.sort(reverse=True, key=lambda x: x[2])
print(len(brr))
for (a, b, c) in brr:
	print(b, c)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
B = []
for i in range(n):
	for j in range(i + 1, n):
		if A[i] > A[j]:
			B.append((A[i], i + 1, j + 1))
B.sort()
B.sort(reverse=True, key=lambda x: x[2])
print(len(B))
for (x, y, z) in B:
	print(y, z)


n = int(input())
li = list(map(int, input().split()))
lp = li.copy()
j = 1
lf = []
c = max(lp)
while j <= n:
	a = min(lp)
	i = lp.index(a)
	li[i] = j
	lp[i] = c + j
	j += 1
while n > 1:
	a = li.pop()
	while a < n:
		i = li.index(a + 1)
		li[i] = a
		lf += [f'{i + 1} {n}']
		a = a + 1
	n -= 1
print(len(lf))
for v in lf:
	print(v)


import sys
inpy = [int(x) for x in sys.stdin.read().split()]
n = inpy[0]
arr = inpy[1:]
res = []
for i in range(n - 1, -1, -1):
	x = []
	for j in range(i):
		if arr[j] > arr[i]:
			x.append((arr[j], j))
	x.sort()
	for (a, j) in x:
		res.append((j + 1, i + 1))
print(len(res))
for (i, j) in res:
	print(i, j)


import sys

def input():
	return sys.stdin.readline().rstrip()

def split_input():
	return [int(i) for i in input().split()]

def allpos(a):
	n = len(a)
	m = len(a[0])

	def onBoard(i, j):
		return i >= 0 and j >= 0 and (i < n) and (j < m)
	dirs = [(1, 0), (0, 1), (-1, 0), (0, -1)]
	for i in range(n):
		for j in range(m):
			for d in dirs:
				newi = i + d[0]
				newj = j + d[1]
				if onBoard(newi, newj):
					pass

def isSorted(a):
	for i in range(1, len(a)):
		if a[i] < a[i - 1]:
			return False
	return True
tests = 1
for _ in range(tests):
	n = int(input())
	a = split_input()
	d = {}
	for i in range(len(a)):
		if a[i] not in d:
			d[a[i]] = 1
		else:
			num = d[a[i]] * 0.001
			d[a[i]] += 1
			a[i] += num
	ops = []
	for i in range(n - 1, -1, -1):
		l = []
		for j in range(i):
			if a[j] > a[i]:
				l.append((a[j], j))
		l.sort()
		for elem in l:
			ops.append('%d %d' % (elem[1] + 1, i + 1))
			(a[elem[1]], a[i]) = (a[i], a[elem[1]])
	if isSorted(a):
		print(len(ops))
		print(*ops, sep='\n')
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
import threading
from math import cos, sin, pi

def main():
	for _ in range(1):
		n = int(input())
		arr = list(map(int, input().split()))
		arr = list(zip(arr, range(n)))
		ai = arr.copy()
		ans = []
		for i in range(n - 1, 0, -1):
			can = []
			for j in range(0, i):
				if arr[j] > arr[i]:
					can.append((arr[j], j))
			can.sort()
			prev = arr[i]
			for (val, ind) in can:
				arr[ind] = prev
				prev = val
				ans.append((ind, i))
			arr[i] = prev
	print(len(ans))
	for (i, j) in ans:
		print(i + 1, j + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, 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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


it = lambda : list(map(int, input().strip().split()))

def solve():
	N = int(input())
	A = it()
	inversions = []
	for i in range(N):
		inversion = []
		for j in range(i):
			if A[j] > A[i]:
				inversion.append(j)
		inversions.append(inversion)
	R = []
	B = [[a, i] for (i, a) in enumerate(A)]
	for i in range(N - 1, -1, -1):
		inversion = inversions[i]
		inversion.sort(key=lambda x: B[x])
		for j in inversion:
			R.append([j + 1, i + 1])
			(B[i], B[j]) = (B[j], B[i])
	print(len(R))
	for (i, j) in R:
		print(i, j)
solve()


n = int(input())
arr = list(map(int, input().split()))
ans = []
for i in range(n):
	for j in range(n - 1, i, -1):
		if arr[i] > arr[j]:
			ans.append((arr[i], i + 1, j + 1))
ans = sorted(ans, key=lambda x: x[0])
ans = sorted(ans, reverse=True, key=lambda x: x[2])
print(len(ans))
for (_, u, v) in ans:
	print(u, v)


from sys import stdin, stdout

def inversion_swapsort(n, a):
	I = []
	for i in range(n):
		for j in range(i + 1, n):
			if a[i] > a[j]:
				I.append([a[i], i + 1, j + 1])
	I.sort()
	I.sort(key=lambda x: x[2], reverse=True)
	print(len(I))
	if len(I) > 0:
		for i in I:
			j = i[1:]
			print(*j)
	return
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
inversion_swapsort(n, a)


from sys import stdin, stdout

def main():
	n = int(stdin.readline())
	ary = list(map(int, stdin.readline().split()))
	pair = []
	for i in range(n):
		pair.append((ary[i], i))
	pair.sort()
	perm = [-1] * n
	pos = [-1] * n
	for i in range(n):
		perm[pair[i][1]] = i
		pos[i] = pair[i][1]
	del pair
	answers = []
	for i in range(n - 1, -1, -1):
		for j in range(perm[i] + 1, n):
			if pos[j] < pos[perm[i]]:
				answers.append(' '.join(map(str, (pos[j] + 1, i + 1))))
	stdout.write(str(len(answers)) + '\n')
	stdout.write('\n'.join(answers))
	return
main()