In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.

Note that in this problem you do not have to minimize the number of swaps — your task is to find any sequence that is no longer than n.


-----Input-----

The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of array elements. The second line contains elements of array: a_0, a_1, ..., a_{n} - 1 ( - 10^9 ≤ a_{i} ≤ 10^9), where a_{i} is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.


-----Output-----

In the first line print k (0 ≤ k ≤ n) — the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≤ i, j ≤ n - 1), representing the swap of elements a_{i} and a_{j}. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times.

If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.


-----Examples-----
Input
5
5 2 5 1 4

Output
2
0 3
4 2

Input
6
10 20 20 40 60 60

Output
0

Input
2
101 100

Output
1
0 1

Difficulty: EASY
Tags: Sorting

Implementation

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
import bisect
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	j = min(range(i, n), key=lambda k: a[k])
	if j != i:
		(a[i], a[j]) = (a[j], a[i])
		ans.append((i, j))
print(len(ans))
for (i, j) in ans:
	print(i, j)


n = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(0, n - 1):
	s = min(A[i:])
	y = A[i:]
	(A[i], A[i + y.index(s)]) = (A[i + y.index(s)], A[i])
	ans.append(f'{i} {i + y.index(s)}')
print(len(ans))
for i in ans:
	print(i)


n = int(input())
arr = list(map(int, input().split()))
res = []
for i in range(n):
	smallest = i
	for j in range(n - 1, i, -1):
		if arr[j] < arr[smallest]:
			smallest = j
	if smallest != i:
		(arr[smallest], arr[i]) = (arr[i], arr[smallest])
		res.append([smallest, i])
print(len(res))
for e in res:
	print(e[0], e[1])


(s, n) = ([], int(input()))
t = list(map(int, input().split()))
for (i, k) in enumerate(sorted(t)):
	if t[i] != k:
		j = i + t[i:].index(k)
		s.append(str(i) + ' ' + str(j))
		(t[i], t[j]) = (t[j], t[i])
print(len(s))
print('\n'.join(s))


numero = int(input())
lista = [int(x) for x in input().split()]
listIndex = []
for i in range(len(lista)):
	menor = lista[i]
	index = i
	for j in range(i + 1, len(lista)):
		if lista[j] < menor:
			menor = lista[j]
			index = j
	else:
		if lista[i] != menor:
			listIndex.append([i, index])
			lista[index] = lista[i]
			lista[i] = menor
print(len(listIndex))
for i in range(len(listIndex)):
	print(listIndex[i][0], listIndex[i][1])


import sys
input = sys.stdin.readline
n = int(input())
l = [*map(int, input().split())]
ans = []
for i in range(n - 1):
	m = min(l[i:])
	ind = l.index(m, i)
	if ind != i:
		ans.append([ind, i])
		(l[ind], l[i]) = (l[i], l[ind])
print(len(ans))
for i in ans:
	print(*i)


n = int(input())
A = list(map(int, input().split()))
print(n - 1)
for i in range(n - 1):
	j = i + A[i:].index(min(A[i:]))
	print(i, j)
	(A[i], A[j]) = (A[j], A[i])


n = int(input())
D = list(range(n))
P = list(D)
A = [a[1] for a in sorted(zip(map(int, input().split()), D))]
print(n)
for i in range(n):
	print(D[A[i]], i)
	P[D[A[i]]] = P[i]
	D[P[i]] = D[A[i]]


n = int(input())
arr = list(map(int, input().split()))
s = sorted(list(range(n)), key=lambda x: arr[x])
s = sorted(list(range(n)), key=lambda x: s[x])
sd = {s[i]: i for i in range(n)}
ans = []
for i in range(n):
	if s[i] != i:
		p = s[i]
		k = sd[i]
		ans.append([i, k])
		(s[i], s[k]) = (s[k], s[i])
		sd[i] = i
		sd[p] = k
print(len(ans))
for i in range(len(ans)):
	print(*ans[i])


n = int(input())
alist = list(map(int, input().split()))
if alist == sorted(alist):
	print(0)
	exit()
ans = []
for i in range(n):
	mi = min(alist[i:])
	ind = i + alist[i:].index(mi)
	ans.append([i, ind])
	(alist[i], alist[ind]) = (alist[ind], alist[i])
print(len(ans))
for tup in ans:
	print(*tup)


n = int(input())
a = list(map(int, input().split()))
perms = []
for i in range(n):
	min_i = min(list(range(i, n)), key=lambda x: a[x])
	if min_i != i:
		perms.append([i, min_i])
		(a[i], a[min_i]) = (a[min_i], a[i])
print(len(perms))
for (p1, p2) in perms:
	print(p1, p2)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

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

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

def Lstr():
	return list(sys.stdin.readline().strip())

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

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

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

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def solution():
	n = Int()
	l = List()
	o = []
	for i in range(n):
		temp = i
		for j in range(i + 1, n):
			if l[temp] > l[j]:
				temp = j
		if temp != i:
			o.append([i, temp])
			(l[temp], l[i]) = (l[i], l[temp])
	print(len(o))
	for x in o:
		print(*x)
solution()


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
x = []
y = []
j = 0
for i in range(n):
	if a[i] != b[i]:
		c = a.index(b[i])
		j += 1
		(a[c], a[i]) = (a[i], a[c])
		x.append(i)
		y.append(c)
	a[i] = 10 ** 10
print(j)
for i in range(j):
	print(x[i], y[i])


def swap(list1, i, j):
	(list1[i], list1[j]) = (list1[j], list1[i])
	return list1
n = int(input())
a = list(map(int, input().split()))
p = sorted(a)
ans = []
i = 0
while a != p and i < n:
	j = a.index(a[i])
	m = a.index(p[i], i, n)
	a = swap(a, j, m)
	ans.append([j, m])
	i += 1
print(len(ans))
for it in ans:
	print(*it)


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
print(n - 1)
for i in range(n - 1):
	x = a.index(b[i])
	print(i, x)
	a[x] = 9999999999999
	(a[i], a[x]) = (a[x], a[i])


n = int(input())
x = [int(q) for q in input().split()]
print(n - 1)
for i in range(n - 1):
	s = min(x[i:])
	y = x[i:]
	(x[i], x[i + y.index(s)]) = (x[i + y.index(s)], x[i])
	print(i, i + y.index(s))


def find_min(i):
	min = 1000000001
	index = 0
	for j in range(i, n):
		if a[j] < min:
			min = a[j]
			index = j
	return index
n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
k = 0
ans = ()
for i in range(n):
	m = find_min(i)
	if i != m:
		a[i] = a[i] + a[m]
		a[m] = a[i] - a[m]
		a[i] = a[i] - a[m]
		ans += (i, m)
		k += 1
print(k)
for i in range(0, len(ans), 2):
	print(ans[i], ans[i + 1])


n = int(input())
arr = list(map(int, input().split()))
count = 0
ans = []
for i in range(n):
	mins = i
	for t in range(i, n):
		if arr[mins] > arr[t]:
			mins = t
	if i != mins:
		count += 1
		ans.append((i, mins))
	(arr[i], arr[mins]) = (arr[mins], arr[i])
print(count)
for i in ans:
	print(i[0], i[1])


__author__ = 'alexandrun'
import sys
n = int(input())
words = input().split()
i = 0
ini = []
for w in words:
	ini.append((int(w), i))
	i += 1
fin = ini[:]
fin.sort()
pos = {}
i = 0
for pair in ini:
	pos[pair] = i
	i += 1
swaps = []
ifin = 0
for pair in fin:
	swaps.append((ifin, pos[pair]))
	aux = ini[ifin]
	ini[ifin] = ini[pos[pair]]
	ini[pos[pair]] = aux
	p1 = ini[ifin]
	p2 = ini[pos[pair]]
	aux = pos[p1]
	pos[p1] = pos[p2]
	pos[p2] = aux
	ifin += 1
print(len(swaps))
for s in swaps:
	print(s[0], s[1])


n = int(input(''))
arvud = input('').split()
arvud = list(map(int, arvud))
swaps = []
begin = 0
for i in range(n):
	mini = min(arvud)
	index = arvud.index(mini)
	if index != 0:
		(arvud[0], arvud[index]) = (arvud[index], arvud[0])
		swaps.append((begin, index + begin))
	arvud.pop(0)
	begin += 1
print(len(swaps))
for i in range(len(swaps)):
	print(swaps[i][0], ' ', swaps[i][1])


n = int(input())
arr = list(map(int, input().split()))
res = []
for i in range(n):
	x = i
	for j in range(i, n):
		if arr[x] > arr[j]:
			x = j
	if i != x:
		res.append((i, x))
	(arr[i], arr[x]) = (arr[x], arr[i])
if len(res) == 0:
	print('0')
else:
	print(len(res))
	for i in res:
		print(*i)


def input_split(f):
	return map(f, input().split())

def main():
	n = int(input())
	a = list(input_split(int))
	k = 0
	res = []
	for i in range(0, n - 1):
		m = a[i]
		index = 0
		for j in range(i + 1, n):
			if m > a[j]:
				m = a[j]
				index = j
		if m != a[i]:
			k += 1
			(a[i], a[index]) = (m, a[i])
			res.append((i, index))
	print(str(k))
	for v in res:
		print(' '.join(map(str, v)))
main()


n = int(input())
l = list(map(int, input().split()))
ans = []
a = sorted(l)
for i in range(n):
	if a[i] != l[i]:
		j = l.index(a[i], i)
		(l[i], l[j]) = (l[j], l[i])
		ans.append((i, j))
print(len(ans))
for j in ans:
	print(*j)


n = int(input())
a = list(map(int, input().split()))
res = []
for i in range(n):
	x = i
	for j in range(i + 1, n):
		if a[x] > a[j]:
			x = j
	if x != i:
		res.append((i, x))
		(a[x], a[i]) = (a[i], a[x])
print(len(res))
for x in res:
	print(*x)


from collections import deque as de
import math
import re
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

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

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def dupconscount(nums):
	element = []
	freque = []
	if not nums:
		return element
	running_count = 1
	for i in range(len(nums) - 1):
		if nums[i] == nums[i + 1]:
			running_count += 1
		else:
			freque.append(running_count)
			element.append(nums[i])
			running_count = 1
	freque.append(running_count)
	element.append(nums[i + 1])
	return (element, freque)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def si():
	return list(map(str, input()))

def indic():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(index) + 1] = int(value)
	return dic
n = ii()
a = li()
temp = a.copy()
temp.sort()
print(n)
for i in range(n):
	if temp[i] == a[i]:
		print(i, i)
	else:
		j = a[i:].index(temp[i])
		tep = a[i]
		a[i] = a[j + i]
		a[j + i] = tep
		print(i, j + i, end='\n')


n = int(input())
a = list(map(int, input().split()))
c = []
res = 0
for i in range(n - 1, -1, -1):
	max1 = max(a)
	if a[i] == max1:
		a.pop()
	else:
		c.append(i)
		c.append(a.index(max1))
		(a[i], a[a.index(max1)]) = (a[a.index(max1)], a[i])
		res += 1
		a.pop()
print(res)
k = 0
for i in range(res):
	print(c[0 + k], c[1 + k], sep=' ')
	k += 2


n = int(input())
a = list(map(int, input().split()))
n = len(a)
b = []
for i in range(n):
	b.append([a[i], i])
b.sort()
d = [0] * n
for i in range(n):
	d[b[i][1]] = i
b = a.copy()
b.sort()
p = [0] * n
c = []
for i in range(n):
	if p[i] == 0:
		j = i
		k = d[j]
		p[i] = 1
		m = []
		while p[k] == 0 and j != d[j]:
			p[k] = 1
			m.append([j, k])
			j = k
			k = d[j]
		f = len(m)
		for i in range(f - 1, -1, -1):
			c.append(m[i])
n = len(c)
print(n)
for i in range(n):
	print(c[i][0], c[i][1])


n = int(input())
l = [int(x) for x in input().split()]
s = sorted(l)
ans = []
for i in range(n):
	for j in range(i, n):
		if l[j] == s[i]:
			(l[i], l[j]) = (l[j], l[i])
			ans.append(str(i) + ' ' + str(j))
			break
print(n)
print('\n'.join(ans))


n = int(input())
a = [int(x) for x in input().split()]
print(n - 1)
for i in range(n - 1):
	m = i + a[i:].index(min(a[i:]))
	print(i, m)
	c = a[i]
	a[i] = a[m]
	a[m] = c


gi = lambda : list(map(int, input().split()))
(n,) = gi()
L = gi()
M = L[:]
M.sort()
print(n)
for k in range(n):
	swap = L[k:].index(M[k]) + k
	print(str(k) + ' ' + str(swap))
	temp = L[swap]
	L[swap] = L[k]
	L[k] = temp


n = int(input())
a = list(map(int, input().split(' ')))
s = a.copy()
s.sort()
t = 0
r = [[]]
for i in range(n):
	r.append([])
	r[i].append(-1)
	r[i].append(-1)
for i in range(n):
	if a[i] != s[i]:
		for j in range(i + 1, n):
			if a[j] == s[i]:
				temp = a[i]
				a[i] = a[j]
				a[j] = temp
				r[t][0] = i
				t += 1
				r[t - 1][1] = j
				break
print(t)
for i in range(t):
	print('{} {}'.format(r[i][0], r[i][1]))


n = int(input())
line = list(map(int, input().split()))
rest = list()
for i in range(n - 1):
	j = i
	for t in range(i + 1, n):
		if line[j] > line[t]:
			j = t
	rest.append((i, j))
	(line[i], line[j]) = (line[j], line[i])
print(len(rest))
for it in rest:
	print(' '.join(map(str, it)))


from math import *
from collections import *
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	m = 0
	for j in range(n - i):
		if a[j] > a[m]:
			m = j
	if a[m] != a[n - i - 1]:
		ans.append([m, n - i - 1])
		(a[m], a[n - i - 1]) = (a[n - i - 1], a[m])
print(len(ans))
for i in ans:
	print(i[0], i[1])


import sys, math
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	m = min(a[i:])
	j = a[i:].index(m) + i
	if i != j:
		ans.append([i, j])
	(a[i], a[j]) = (a[j], a[i])
print(len(ans))
for i in ans:
	i = map(str, i)
	print(' '.join(i))


n = int(input())
l = [int(i) for i in input().split()]

def swap(i, j):
	li = l[i]
	l[i] = l[j]
	l[j] = li
li = []
for i in range(n - 1):
	m = min(l[i:])
	ind = l.index(m, i)
	if ind != i:
		li.append([ind, i])
		swap(ind, i)
if len(li) == 0:
	print(0)
else:
	print(len(li))
	for i in range(len(li)):
		print(li[i][0], li[i][1])


def getmin(arr, ini, end):
	value = 10 ** 9 + 1
	for i in range(ini, end):
		if arr[i] < value:
			value = arr[i]
			pos = i
	return (value, pos)
n = int(input())
a = input().split(' ')
for i in range(n):
	a[i] = int(a[i])
counter = 0
exchanges = []
for i in range(n):
	(value, pos) = getmin(a, i, n)
	if a[i] != value:
		counter = counter + 1
		aux = a[pos]
		a[pos] = a[i]
		a[i] = aux
		exchanges.append([i, pos])
print(counter)
for i in exchanges:
	print(i[0], i[1])


def urut(l):
	for i in range(len(l) - 1):
		if l[i] > l[i + 1]:
			return False
	return True

def main():
	n = int(input())
	ol = list(map(int, input().split(' ')))
	mi = {}
	i = 0
	l = []
	idx = -1
	if urut(ol):
		print(0)
		return
	for i in range(len(ol)):
		a = min(ol[i:])
		for x in range(i, len(ol)):
			if ol[x] == a:
				idx = x
		(ol[idx], ol[i]) = (ol[i], ol[idx])
		l.append((i, idx))
	print(len(l))
	z = [' '.join(map(str, i)) for i in l]
	print(' '.join(z))
main()


n = int(input())
a = list(map(int, input().split()))
ans = []
for (i, j) in enumerate(sorted(a)):
	if a[i] != j:
		k = i + a[i:].index(j)
		ans.append(str(i) + ' ' + str(k))
		(a[i], a[k]) = (a[k], a[i])
print(len(ans))
print('\n'.join(ans))


n = int(input())
s = list(map(int, input().split()))
ans = []
for i in range(n - 1):
	ab = min(s[i:])
	tmp = s[i:].index(ab) + i
	(s[i], s[tmp]) = (s[tmp], s[i])
	ans.append([tmp, i])
print(len(ans))
for i in ans:
	print(*i)


x = int(input())
s = list(map(int, input().split()))
z = sorted(s)
res = []
for n in range(x):
	if s[n] != z[n]:
		for k in range(n + 1, x):
			if s[k] == z[n]:
				res.append([n, k])
				t = s[n]
				s[n] = s[k]
				s[k] = t
				break
print(len(res))
for n in res:
	print(n[0], n[1])


n = int(input())
a = list(map(int, input().split()))
c = 0
(p, q) = ([], [])
for i in range(n - 1):
	m = a[i:].index(min(a[i:]))
	d = m + i
	if a[i] != a[d]:
		c += 1
		p.append(i)
		q.append(d)
		(a[i], a[d]) = (a[d], a[i])
print(c)
for i in range(c):
	print(p[i], q[i])


n = int(input())
s = [int(i) for i in input().split()]
j = list(s)
j.sort()
if s == j:
	print(0)
else:
	hh = 0
	x = []
	for i in range(n):
		a = s[i]
		b = j[i]
		if a == b:
			s[i] = 10 ** 9 + 1
			continue
		else:
			if s == j:
				break
			h = s.index(b)
			x.append((h, i))
			s[h] = a
			s[i] = 10 ** 9 + 1
			hh += 1
	print(hh)
	for i in x:
		print(*i)


n = int(input())
a = [*map(int, input().split())]
b = sorted(a)
ansnum = 0
ans = []
for i in range(n):
	if a[i] != b[i]:
		p = a[i + 1:].index(b[i]) + i + 1
		ans.append((i, p))
		a[p] = a[i]
		a[i] = b[i]
		ansnum += 1
print(ansnum)
for i in ans:
	print(i[0], i[1])


n = int(input())
a = [int(s) for s in input().split()]
b = sorted(a)
count = 0
swaps = []
for i in range(n):
	if a[i] != b[i]:
		count += 1
		for j in range(i, n):
			if a[j] == b[i]:
				(a[i], a[j]) = (a[j], a[i])
				swaps.append((i, j))
				break
print(count)
for (i, j) in swaps:
	print(i, j)


n = int(input())
l = [int(x) for x in input().split()]
res = []
for i in range(len(l)):
	id = i
	min = l[i]
	for j in range(i + 1, len(l)):
		if l[j] < min:
			min = l[j]
			id = j
	if l[i] != l[id]:
		res.append((i, id))
		(l[i], l[id]) = (l[id], l[i])
print(len(res))
for l in res:
	print(l[0], l[1])


n = int(input())
l = list(map(int, input().split()))
ls = sorted(l)
ans = []
for i in range(n):
	if l[i] == ls[i]:
		continue
	for j in range(i + 1, n):
		if ls[i] == l[j]:
			l[j] = l[i]
			ans.append([i, j])
			break
print(len(ans))
for i in ans:
	print(i[0], i[1])


def main():
	n = int(input())
	l = list(map(int, input().split()))
	l = sorted(((x, i) for (i, x) in enumerate(l)))
	l = sorted(((i, j) for (j, (x, i)) in enumerate(l)))
	l = [j for (x, j) in l]
	index = [0] * n
	for (i, x) in enumerate(l):
		index[x] = i
	res = []
	for (i, x) in enumerate(index):
		y = l[i]
		if i != y:
			res.append((i, x))
			(l[i], l[x]) = (i, y)
			index[y] = x
	print(len(res))
	for a in res:
		print(*a)

def __starting_point():
	main()
__starting_point()


n = int(input())
p = input().rstrip().split(' ')
C = list(p)
C.sort(key=int)
l = []
q = []
D = 0
for i in range(0, len(C)):
	if int(C[i]) != int(p[i]):
		F = p[i:len(p)]
		v = F.index(C[i])
		temp = p[i]
		p[i] = p[v + i]
		p[v + i] = temp
		l.append(i)
		q.append(v + i)
		D += 1
print(D)
for i in range(0, len(l)):
	print(l[i], q[i])


def solve(xs):
	oxs = xs[:]
	oxs.sort()
	res = []
	for i in range(len(xs)):
		if xs[i] != oxs[i]:
			j = i + 1
			while not (oxs[i] == xs[j] and xs[j] != oxs[j]):
				j += 1
			res.append([i, j])
			(xs[i], xs[j]) = (xs[j], xs[i])
	return res
input()
xs = list(map(int, input().split()))
ret = solve(xs)
print(len(ret))
if ret:
	print('\n'.join(('{0[0]} {0[1]}'.format(swp) for swp in ret)))


n = int(input())
a = list(map(int, input().split()))
if a == sorted(a):
	print(0)
	exit()
ans = 0
ans2 = [[] for i in range(n)]
for i in range(n):
	j = i
	for z in range(i, n):
		if a[j] > a[z]:
			j = z
	ans += 1
	ans2[i].append(i)
	ans2[i].append(j)
	(a[i], a[j]) = (a[j], a[i])
	if a == sorted(a):
		break
print(ans)
for x in ans2:
	if len(x) == 0:
		break
	else:
		print(*x)


n = int(input())
a = [int(i) for i in input().split()]
ans = []
for i in range(n):
	j = i
	for t in range(i, n):
		if a[j] > a[t]:
			j = t
	if i != j:
		ans.append([i, j])
	(a[i], a[j]) = (a[j], a[i])
print(len(ans))
for i in range(len(ans)):
	print(*ans[i])


def swapsort(n, a):
	swaps = []
	s = sorted(a)
	for i in range(len(a)):
		if a[i] != s[i]:
			for j in range(i + 1, len(a)):
				if a[j] == s[i]:
					(a[i], a[j]) = (a[j], a[i])
					swaps.append([i, j])
					break
	print(len(swaps))
	for k in range(len(swaps)):
		print(*swaps[k])
n = int(input())
a = [int(x) for x in input().split()]
swapsort(n, a)


n = int(input())
lst = list(map(int, input().strip().split(' ')))
print(n)
for i in range(n):
	j = lst[i:].index(min(lst[i:]))
	(lst[i], lst[j + i]) = (lst[j + i], lst[i])
	print(i, j + i, end=' ')
	print()


size = int(input())
array = list(map(int, input().split()))
ans = []
for i in range(size):
	j = i
	for t in range(i, size):
		if array[j] > array[t]:
			j = t
	if i != j:
		ans.append((i, j))
	t = array[i]
	array[i] = array[j]
	array[j] = t
print(len(ans))
for p in ans:
	print(p[0], p[1])


n = int(input())
l_v = list(map(int, input().split()))
sa = sorted(l_v)
ans = []
for i in range(n):
	if l_v[i] != sa[i]:
		p = l_v[i:].index(sa[i]) + i
		(l_v[i], l_v[p]) = (l_v[p], l_v[i])
		ans.append([i, p])
print(len(ans))
for a in ans:
	print(' '.join((str(x) for x in a)))


def swapsort2(n, a):
	swaps = []
	for i in range(len(a) - 1):
		min = a[i]
		index = i
		for j in range(i + 1, len(a)):
			if a[j] < min:
				min = a[j]
				index = j
		if min < a[i]:
			(a[index], a[i]) = (a[i], a[index])
			swaps.append([i, index])
	print(len(swaps))
	for k in range(len(swaps)):
		print(*swaps[k])
n = int(input())
a = [int(x) for x in input().split()]
swapsort2(n, a)


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
c = []
for i in range(n):
	if a[i] != b[i]:
		r = a.index(b[i])
		l = a[:i + 1].count(b[i])
		for j in range(l):
			r = a.index(b[i], r + 1)
		(a[i], a[r]) = (a[r], a[i])
		c.append([i, r])
print(len(c))
for i in range(len(c)):
	print(*c[i])


def getMin(arr):
	min = arr[0]
	for a in arr:
		if a < min:
			min = a
	return min
numel = input('')
elem = list(map(int, input('').split()))
swaps = []
i = 0
count = 0
while i < len(elem):
	minelem = getMin(elem[i:])
	minindex = elem[i:].index(minelem) + (len(elem) - len(elem[i:]))
	if not elem[i:][0] == minelem:
		temp = elem[i]
		elem[i] = minelem
		elem[minindex] = temp
		swap = [i, minindex]
		swaps += [swap]
		count += 1
	i += 1
print(count)
for k in swaps:
	print(k[0], ' ', k[1])


n = int(input())
a = list(map(int, input().split()))
print(n)
for i in range(n):
	ind = i + a[i:].index(min(a[i:]))
	(a[i], a[ind]) = (a[ind], a[i])
	print(i, ind)


import functools
n = input()
arr = list(map(int, input().split()))
print(len(arr))
for i in range(len(arr)):
	val = min(arr[i:])
	ind = arr[i:].index(val) + i
	print(i, ind)
	(arr[i], arr[ind]) = (arr[ind], arr[i])


import os
import sys
from io import BytesIO, IOBase
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')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
n = int(input())
arr = list(map(int, input().split()))
sarr = arr[:]
sarr.sort()
ans = []
for i in range(n):
	if sarr[i] == arr[i]:
		ans.append((i, i))
	else:
		for j in range(i, n):
			if arr[j] == sarr[i]:
				ans.append((i, j))
				(arr[i], arr[j]) = (arr[j], arr[i])
				break
print(n)
for i in range(n):
	print(ans[i][0], ans[i][1])


n = int(input())
x = [int(q) for q in input().split()]
y = sorted(x)
l = []
if y == x:
	print(0)
else:
	print(n)
	for i in range(n):
		m = min(x[i:])
		if m == x[i]:
			print(i, i)
		else:
			j = i + 1 + x[i + 1:].index(m)
			(x[i], x[j]) = (x[j], x[i])
			print(i, j)


n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	j = i
	for t in range(i, n):
		if a[j] > a[t]:
			j = t
	if i != j:
		ans.append((i, j))
	t = a[i]
	a[i] = a[j]
	a[j] = t
print(len(ans))
for p in ans:
	print(p[0], p[1])


n = int(input())
a = list(map(int, input().split()))
k = 0
r = ''
for i in range(n, 0, -1):
	x = a.index(max(a[:i]))
	if a[i - 1] == a[x] or i == x:
		continue
	(a[i - 1], a[x]) = (a[x], a[i - 1])
	r += str(x) + ' ' + str(i - 1) + '\n'
	k += 1
print(k)
print(r)


x = int(input())
arr = [int(i) for i in input().split()]
answers = []
sortarr = sorted(arr)
for x in range(len(arr)):
	if arr[x] != sortarr[x]:
		ans = arr[x:].index(sortarr[x])
		answers.append([str(x), str(ans + x)])
		arr.insert(x + ans, arr[x])
		arr.insert(x, sortarr[x])
		arr.pop(x + 1)
		arr.pop(ans + x + 1)
print(len(answers))
for ans in answers:
	print(ans[0], ans[1])


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	swap = 0
	ind = 0
	i_s = []
	while ind < len(arr):
		mi = min(arr[ind:])
		if mi != arr[ind]:
			for i in range(ind, n):
				if arr[i] == mi and i != ind:
					(arr[ind], arr[i]) = (arr[i], arr[ind])
					i_s.append((ind, i))
					swap += 1
					break
		ind += 1
	print(swap)
	for i in range(swap):
		print(*i_s[i])
main()


n = int(input())
a = [int(_) for _ in input().split()]
print(n - 1)
for i in range(n - 1):
	swap = i
	for j in range(i + 1, n):
		if a[swap] > a[j]:
			swap = j
	print(str(i) + ' ' + str(swap))
	(a[i], a[swap]) = (a[swap], a[i])


n = int(input())
t = 0
T = []
z = [int(a) for a in input().split()]
for i in range(n):
	j = i
	for m in range(i, n):
		if z[j] > z[m]:
			j = m
	if j != i:
		t += 1
		T.append('%d %d' % (i, j))
		(z[j], z[i]) = (z[i], z[j])
print(t)
for i in T:
	print(i)


n = int(input())
l = list(map(int, input().split()))
swaps = 0
ans = []
for i in range(n):
	t = i
	for j in range(i, n):
		if l[t] > l[j]:
			t = j
	if i != t:
		ans.append([i, t])
	(l[i], l[t]) = (l[t], l[i])
print(len(ans))
for i in ans:
	print(*i)


n = int(input())
a = [int(m) for m in input().split()]
counter = 0
exit_list = []
i = 0
while i < n:
	sublist = a[i:]
	minimum = sublist.index(min(sublist)) + i
	if i != minimum:
		exit_list.append((i, minimum))
		c = a[minimum]
		a[minimum] = a[i]
		a[i] = c
		counter += 1
	i += 1
print(counter)
for x in exit_list:
	print(x[0], x[1])


(n, a) = (int(input()), list(map(int, input().split())))
(d, left) = (dict(map(lambda x: (x[1], x[0]), enumerate(sorted(range(n), key=lambda i: a[i])))), set(range(n)))
print(n)
while left:
	i = left.pop()
	print(i, d[i])
	left.add(i)
	left.discard(d[i])
	j = d[i]
	(d[i], d[j]) = (d[j], j)


n = int(input())
a = list(map(int, input().split(' ')))
ans = []
for x in range(n):
	temp = x
	for y in range(x + 1, n):
		if a[y] < a[temp]:
			temp = y
	ans.append([x, temp])
	(a[x], a[temp]) = (a[temp], a[x])
print(len(ans))
for x in ans:
	print(x[0], x[1])


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
a = gil()
b = sorted(a)
ans = []
for i in range(n):
	if a[i] == b[i]:
		continue
	for j in range(i + 1, n):
		if a[j] == b[i] and a[j] != b[j]:
			break
	ans.append(str(i) + ' ' + str(j) + '\n')
	(a[i], a[j]) = (a[j], a[i])
print(len(ans))
print(''.join(ans), end=' ')


n = int(input())
x = list(map(int, input().split()))
z = []
c = 0
for i in range(n):
	(a, b) = (i, x[i])
	for j in range(i, n):
		if x[j] < b:
			a = j
			b = x[j]
	(x[i], x[a]) = (x[a], x[i])
	if a != i:
		c += 1
		z.append([i, a])
print(c)
for i in z:
	for j in i:
		print(j, end=' ')
	print('')


a = int(input())
b = list(map(int, input().split()))
print(a)
for i in range(a):
	if b[i] > min(b):
		print(i, b.index(min(b)))
		b[b.index(min(b))] = b[i]
	else:
		print(i, i)
	b[i] = 10000000000000000000


x = int(input())
sort = list(map(int, input().split(' ')))
print(x)
for i in range(x):
	indx = sort[i:].index(min(sort[i:]))
	print(i, i + indx)
	(sort[i], sort[i + indx]) = (sort[i + indx], sort[i])


import math

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	index_arr = []
	i = 0
	while i < n:
		temp = arr[i + 1:]
		if len(temp) > 0:
			min_of_temp = min(temp)
			for j in range(i + 1, len(arr)):
				if arr[j] == min_of_temp:
					index_of_min = j
					break
			if arr[i] > arr[index_of_min]:
				index_arr.append([i, index_of_min])
				(arr[i], arr[index_of_min]) = (arr[index_of_min], arr[i])
		i += 1
	if len(index_arr) > 0:
		print(len(index_arr))
		for val in index_arr:
			print(val[0], end=' ')
			print(val[1])
	else:
		print(0)
solve()


def min_index(start, array):
	min_v = array[start]
	min_i = start
	for i in range(start + 1, len(array)):
		if min_v > array[i]:
			min_v = array[i]
			min_i = i
	return min_i
n = int(input())
numbers = list(map(int, input().split()))
result = []
for i in range(n - 1):
	index = min_index(i + 1, numbers)
	if numbers[index] < numbers[i]:
		(numbers[i], numbers[index]) = (numbers[index], numbers[i])
		result.append(str(i) + ' ' + str(index))
print(len(result))
for s in result:
	print(s)


n = int(input())
lis = input().split()
for i in range(len(lis)):
	lis[i] = int(lis[i])
lis1 = sorted(lis)
print(n)
for i in range(n):
	j = lis[i:].index(lis1[i]) + i
	print(i, j)
	(lis[i], lis[j]) = (lis[j], lis[i])


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
d = {}
for i in range(n):
	try:
		d[a[i]].append(i)
	except:
		d[a[i]] = [i]
print(n)
for i in range(n):
	if a[i] == b[i]:
		print(i, i)
		d[a[i]].pop(0)
		continue
	i1 = d[a[i]].pop(0)
	i2 = d[b[i]].pop(0)
	print(i1, i2)
	d[a[i]].append(i2)
	d[a[i]].sort()
	(a[i1], a[i2]) = (a[i2], a[i1])


n = int(input())
arr = list(map(int, input().split()))
ans = []
for i in range(n):
	k = i
	for j in range(i + 1, n):
		if arr[j] < arr[k]:
			k = j
	if k != i:
		(arr[k], arr[i]) = (arr[i], arr[k])
		ans.append([i, k])
print(len(ans))
if len(ans) > 0:
	for i in ans:
		print(*i)


n = int(input())
A = [int(x) for x in input().split()]
transpositions = []
for i in range(n):
	argmin = -1
	for j in range(i, n):
		if argmin < 0 or A[argmin] > A[j]:
			argmin = j
	if i < argmin:
		transpositions.append((i, argmin))
	(A[i], A[argmin]) = (A[argmin], A[i])
print(len(transpositions))
for t in transpositions:
	print(t[0], t[1])


def arr_inp():
	return [int(x) for x in input().split()]
from collections import *
from copy import *
(n, a, out, l) = (int(input()), arr_inp(), [], 0)
a_sort = sorted(a.copy())
for i in range(n):
	if a[i] == a_sort[i]:
		continue
	ix = a.index(min(a[i:]), i + 1, n)
	(a[i], a[ix]) = (a[ix], a[i])
	out.append([i, ix])
	l += 1
print(l)
for i in range(l):
	print(out[i][0], out[i][1])


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
n = sInt()
a = lInt()
ans = []
for i in range(n):
	if a[i] == min(a[i:]):
		pass
	else:
		m = a.index(min(a[i:]), i, n)
		ans.append([i, m])
		(a[i], a[m]) = (a[m], a[i])
print(len(ans))
for i in range(len(ans)):
	print(*ans[i], sep=' ')


lens = int(input())
arrs = [int(x) for x in input().split()]
to_swap = []
answer = 0
for i in range(lens):
	if arrs[i] == min(arrs[i:]):
		continue
	x = arrs.index(min(arrs[i:]), i)
	(arrs[x], arrs[i]) = (arrs[i], arrs[x])
	to_swap.append([i, x])
	answer += 1
print(answer)
for i in to_swap:
	print(*i)


n = int(input())
a = list(map(int, input().split()))
swa = []
for i in range(n):
	pp = a[i:]
	val = min(pp)
	if val != a[i]:
		index = pp.index(val)
		swa.append((i, index + i))
		(a[i], a[index + i]) = (a[index + i], a[i])
print(len(swa))
for i in swa:
	print(i[0], i[1])


n = int(input())
y = 0
s = 0
la = []
p = list(map(int, input().split()))
for x in range(n - 1):
	tam = p[y:]
	kam = min(tam)
	sa = p.index(kam)
	if y == sa:
		pass
	else:
		(p[y], p[sa]) = (p[sa], p[y])
		la.append(y)
		la.append(sa)
		s += 1
	p[y] = 5555555
	y += 1
sa = 0
if la == list():
	print(0)
else:
	print(s)
	for x in range(len(la) // 2):
		print(*la[sa:sa + 2])
		sa += 2


n = int(input())
a = list((int(i) for i in input().split(' ')))
print(n - 1)
for i in range(n - 1):
	min_elem = a[i]
	min_index = i
	for j in range(i + 1, n):
		if a[j] < min_elem:
			min_elem = a[j]
			min_index = j
	print('%d %d' % (i, min_index))
	tmp_elem = a[i]
	a[i] = min_elem
	a[min_index] = tmp_elem


n = int(input())
temp = 0
arr = []
l = list(map(int, input().split()))
s = sorted(l)
print(n)
for i in range(len(l)):
	for j in range(i, len(l)):
		if l[j] == s[i]:
			temp = l[i]
			l[i] = l[j]
			l[j] = temp
			arr.append(str(i) + ' ' + str(j))
			break
print('\n'.join(arr))


import operator
n = int(input())
xs = list(map(int, str.split(input())))
if xs == sorted(xs):
	print(0)
else:
	swaps = []
	counter = 0
	while xs:
		i = xs.index(min(xs))
		if i:
			swaps.append(str.format('{} {}', counter, i + counter))
		(xs[0], xs[i]) = (xs[i], xs[0])
		xs.pop(0)
		counter += 1
	print(len(swaps))
	print(str.join('\n', swaps))


IL = lambda : list(map(int, input().split()))
IS = lambda : input().split()
I = lambda : int(input())
S = lambda : input()
n = I()
aArr = IL()
ans = []
for i in range(n, 1, -1):
	iMax = aArr[:i].index(max(aArr[:i]))
	(aArr[iMax], aArr[i - 1]) = (aArr[i - 1], aArr[iMax])
	ans.append([iMax, i - 1])
print(len(ans))
for line in ans:
	print(line[0], line[1])


n = int(input())
arr = list(map(int, input().split()))

def find_min(a):
	index_min = -1
	min_val = 10 ** 9 + 1
	for j in range(len(a)):
		if a[j] < min_val:
			min_val = a[j]
			index_min = j
	return (index_min, min_val)
swaps = []
for i in range(n):
	(index, val) = find_min(arr[i:])
	swaps.append('{} {}'.format(i, index + i))
	(arr[i], arr[index + i]) = (arr[index + i], arr[i])
print(n)
print(*swaps, sep='\n')


import sys, os, io, time, copy, math
from collections import deque
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	sor = sorted(arr)
	ans = []
	for i in range(n):
		if arr[i] != sor[i]:
			for j in range(i + 1, n):
				if arr[j] == sor[i]:
					(arr[i], arr[j]) = (arr[j], arr[i])
					ans.append((i, j))
					break
	print(len(ans))
	for (x, y) in ans:
		print(x, y)
main()


n = int(input())
l = list(map(int, input().split()))
d = sorted(l)
x = []
c = 0
for i in range(n - 1):
	if l[i] == d[i]:
		continue
	for j in range(i + 1, n):
		if l[j] == d[i]:
			l[j] = l[i]
			x.append([i, j])
			c = c + 1
			break
print(c)
for i in x:
	print(*i)


import sys
import os.path
if os.path.exists('input_file.txt'):
	sys.stdin = open('input_file.txt', 'r')
	sys.stdout = open('output_file.txt', 'w')
n = int(input())
a = list(map(int, input().split()))
aa = sorted(a)
i = 0
f = 1
l = []
while i < n:
	if a[i] == aa[i]:
		i += 1
	else:
		f = 0
		s = aa[i]
		for j in range(i, n):
			if a[j] == s:
				l.append((i, j))
				(a[i], a[j]) = (a[j], a[i])
				break
if f:
	print(0)
else:
	print(len(l))
	for i in l:
		(a, b) = i
		print(a, b)


def key_function(num):

	def key(i):
		return num[i]
	return key

def main():
	n = 0
	ans = 0
	line = input()
	n = int(line)
	line = input()
	line = line.split()
	num = [int(line[i]) for i in range(n)]
	id = [i for i in range(n)]
	id.sort(key=key_function(num))
	map = dict()
	for i in range(n):
		map[id[i]] = i
	pp = list()
	for i in range(n):
		j = 0
		for j in range(n):
			if map[j] == i:
				break
		if i != j and j < n:
			pp.append((i, j))
			ans = ans + 1
			(map[i], map[j]) = (map[j], map[i])
	print(ans)
	for i in range(ans):
		print(pp[i][0], pp[i][1])
main()


n = int(input())
temp = 0
arr = []
l = [int(x) for x in input().split()]
s = sorted(l)
for i in range(n):
	for j in range(i, n):
		if l[j] == s[i]:
			(l[i], l[j]) = (l[j], l[i])
			arr.append(str(i) + ' ' + str(j))
			break
print(n)
print('\n'.join(arr))


n = int(input())
a = list(map(int, input().split()))
chn = []
for i in range(n):
	ind = n - 1 - a[::-1].index(min(a[i:]))
	if ind != i and a[i] != a[ind]:
		(a[ind], a[i]) = (a[i], a[ind])
		chn.append((i, ind))
print(len(chn))
for item in chn:
	print(*item)


n = int(input())
l = list(map(int, input().split()))
p = l.copy()
p.sort()
print(n)
for i in range(n):
	j = l[i:].index(p[i]) + i
	print(i, j)
	(l[i], l[j]) = (l[j], l[i])


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
ans = []
for i in range(n):
	if a[i] != b[i]:
		where = a[i:].index(b[i]) + i
		(a[i], a[where]) = (a[where], a[i])
		ans.append([i, where])
print(len(ans))
print('\n'.join(list(map(lambda x: ' '.join(list(map(str, x))), ans))))


n = int(input())
l1 = list(map(int, input().strip().split()))
l2 = sorted(l1)
d = []
for i in range(n):
	if l1[i] != l2[i]:
		a = l1.index(l2[i], i)
		d.append([a, i])
		(l1[i], l1[a]) = (l1[a], l1[i])
print(len(d))
for i in d:
	print(*i)


n = int(input())
a = list(map(int, input().split()))
print(n - 1)
for i in range(n - 1):
	m = i + a[i:].index(min(a[i:]))
	print(i, m)
	(a[i], a[m]) = (a[m], a[i])


n = int(input())
l = list(map(int, input().split()))
print(n - 1)
for i in range(n - 1):
	w = i + l[i:].index(min(l[i:]))
	(l[i], l[w]) = (l[w], l[i])
	print(i, w)


read = lambda : map(int, input().split())
n = int(input())
a = list(read())
ans = []
for i in range(n - 1):
	Min = float('inf')
	ind = -1
	for j in range(i, n):
		if a[j] < Min:
			Min = a[j]
			ind = j
	if i != ind:
		(a[i], a[ind]) = (a[ind], a[i])
		ans.append((i, ind))
print(len(ans))
[print(*i) for i in ans]


from sys import stdin as Si, maxsize as m
from math import floor as F
from collections import defaultdict as dt, Counter as Co
from operator import itemgetter as ig
from math import pi
from itertools import product as P
n = int(Si.readline())
A = list(map(int, Si.readline().split()))
(count, swap) = (0, [])
for i in range(n - 1):
	Min = min(A[i + 1:])
	In = i + 1 + A[i + 1:].index(Min)
	if A[i] > Min:
		(A[i], A[In]) = (Min, A[i])
		count += 1
		swap.append((i, In))
print(count)
for s in swap:
	print(s[0], s[1])


from collections import Counter
from math import cos, e
import sys
import bisect as bs
from math import *
mod = 1000000007

def pro(arr):
	n = len(arr)
	f = 1
	ans = []
	for i in range(n):
		mini = arr[i]
		ind = i
		for j in range(i, n):
			if mini > arr[j]:
				ind = j
				mini = arr[j]
		if i != ind:
			f = 0
			ans.append((i, ind))
			(arr[i], arr[ind]) = (arr[ind], arr[i])
	if f:
		print(0)
		return
	print(len(ans))
	for (i, j) in ans:
		print(i, j)
t = 1
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	pro(list(arr))


n = int(input())
a = [int(x) for x in input().split()]
N = 1000000000
ind = []
b = a.copy()
b.sort()
for i in range(n):
	aii = b.index(a[i])
	ind.append(aii)
	b[aii] = N + 1
good = 0
count = 0
swaplist = []
while good < n:
	good = 0
	for i in range(n):
		exp_ind = ind[i]
		if exp_ind == i:
			good += 1
			continue
		(a[i], a[exp_ind]) = (a[exp_ind], a[i])
		(ind[i], ind[exp_ind]) = (ind[exp_ind], ind[i])
		swaplist.append([i, exp_ind])
		count += 1
print(count)
for s in swaplist:
	print(*s, sep=' ')


from sys import stdin
lines = list(filter(None, stdin.read().split('\n')))

def parseline(line):
	return list(map(int, line.split()))
lines = list(map(parseline, lines))
(n,) = lines[0]
ai = lines[1]
assert len(ai) == n
sai = sorted(((x, i) for (i, x) in enumerate(ai)))
pos = list(range(n))
iai = list(range(n))
print(n)
for (j, e) in enumerate(sai):
	(x, i) = e
	print(j, pos[i])
	alpha = j
	beta = pos[i]
	assert pos[iai[j]] == j
	(pos[i], pos[iai[j]]) = (j, pos[i])
	(iai[alpha], iai[beta]) = (iai[beta], iai[alpha])


n = int(input())
arr = list(map(int, input().split()))
swaps = []
print(n)
for i in range(n):
	m = i + arr[i:].index(min(arr[i:]))
	print(i, m)
	(arr[i], arr[m]) = (arr[m], arr[i])


import sys
input = sys.stdin.readline
t = int(input())
a = list(map(int, input().split()))
k = 0
out = []
for i in range(t):
	swap = i
	for j in range(i, t):
		if a[swap] > a[j]:
			swap = j
	if swap == i:
		continue
	(a[i], a[swap]) = (a[swap], a[i])
	out.append([i, swap])
print(len(out))
for i in out:
	print(i[0], i[1])


def sorted(l):
	for i in range(len(l) - 1):
		if l[i] > l[i + 1]:
			return False
	return True

def main():
	n = int(input())
	ol = list(map(int, input().split(' ')))
	mi = {}
	i = 0
	l = []
	idx = -1
	if sorted(ol):
		print(0)
		return
	while True:
		a = min(ol[i:])
		for x in range(i, len(ol)):
			if ol[x] == a:
				idx = x
		(ol[idx], ol[i]) = (ol[i], ol[idx])
		l.append((i, idx))
		i += 1
		if sorted(ol):
			break
	print(len(l))
	for (i, j) in l:
		print(i, j)
main()


def swap(x, y):
	temp = lg[x]
	lg[x] = lg[y]
	lg[y] = temp
n = int(input())
lg = list(map(int, input().split()))
so = lg.copy()
so.sort()
co = 0
pr = ''
for i in range(n - 1):
	x = lg.index(so[i])
	if i != x:
		pr += f'{i} {x} \n'
		co += 1
	lg[x] = 99999999999
	swap(i, x)
print(co)
print(pr)


k = int(input())
inp = [int(j) for j in input().split()]
flag = 0
lis = []
for j in range(k):
	mini = min(inp[j:])
	ind = j + inp[j:].index(mini)
	if inp[j] != inp[ind]:
		(inp[j], inp[ind]) = (inp[ind], inp[j])
		lis.append([j, ind])
if len(lis) == 0:
	print('0')
else:
	print(len(lis))
	for i in range(len(lis)):
		print(lis[i][0], lis[i][1])


def findmin(lst, i):
	minn = i
	minval = lst[i]
	for j in range(i, len(lst)):
		if minval > lst[j]:
			minval = lst[j]
			minn = j
	return minn
n = int(input())
lst = list(map(int, input().split()))
ans = []
for i in range(n):
	j = findmin(lst, i)
	if i != j:
		(lst[i], lst[j]) = (lst[j], lst[i])
		ans.append([i, j])
print(len(ans))
for i in range(len(ans)):
	print(ans[i][0], ' ', ans[i][1])


n = input()
src = list((int(x) for x in input().split()))
cp = src.copy()
cp.sort()

def search(arr, val, border):
	for x in range(border, len(arr)):
		if arr[x] == val:
			return x
	print('ERROR!')
pairs = list()

def main():
	for (index, val) in enumerate(cp):
		tmp = src[index]
		if val != tmp:
			swap = search(src, val, index)
			pairs.append((index, swap))
			src[index] = src[swap]
			src[swap] = tmp
	print(len(pairs))
	for (x, y) in pairs:
		print(x, y)
main()


n = int(input())
a = list(map(int, input().split()))
if a == sorted(a):
	print(0)
	exit()
ans = 0
ans2 = [[] for i in range(n)]
for i in range(n):
	cur = min(a[i:])
	yep = a[i:].index(cur) + i
	ans += 1
	ans2[i].append(i)
	ans2[i].append(yep)
	(a[i], a[yep]) = (a[yep], a[i])
	if a == sorted(a):
		break
print(ans)
for x in ans2:
	if len(x) == 0:
		break
	else:
		print(*x)