576_B. Invariance of Tree_13629
A tree of size n is an undirected connected graph consisting of n vertices without cycles.

Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the condition holds: "vertices u and v are connected by an edge if and only if vertices pu and pv are connected by an edge".

You are given permutation p of size n. Find some tree size n, invariant relative to the given permutation.

Input

The first line contains number n (1 ≤ n ≤ 105) — the size of the permutation (also equal to the size of the sought tree).

The second line contains permutation pi (1 ≤ pi ≤ n).

Output

If the sought tree does not exist, print "NO" (without the quotes).

Otherwise, print "YES", and then print n - 1 lines, each of which contains two integers — the numbers of vertices connected by an edge of the tree you found. The vertices are numbered from 1, the order of the edges and the order of the vertices within the edges does not matter.

If there are multiple solutions, output any of them.

Examples

Input

4
4 3 2 1


Output

YES
4 1
4 2
1 3


Input

3
3 1 2


Output

NO

Note

In the first sample test a permutation transforms edge (4, 1) into edge (1, 4), edge (4, 2) into edge (1, 3) and edge (1, 3) into edge (4, 2). These edges all appear in the resulting tree.

It can be shown that in the second sample test no tree satisfies the given condition.
from collections import defaultdict

n = int(raw_input())
p = [int(v) - 1 for v in raw_input().split()]

was = [False] * n
cyc = defaultdict(list)

for i in xrange(n):
	if was[i]:
		continue

	was[i] = True
	c = [i]
	cur = p[i]
	while cur != i:
		was[cur] = True
		c.append(cur)
		cur = p[cur]

	cyc[len(c)].append(c)

lengths = cyc.keys()
lengths.sort()

roots = []
parents = {}

for i in xrange(len(lengths) - 1, -1, -1):
	for j in xrange(i - 1, -1, -1):
		if lengths[i] % lengths[j] == 0:
			cyc[lengths[i]][0].append(lengths[j])
			break
	else:
		cyc[lengths[i]][0].append(None)
		roots.append(lengths[i])

if len(roots) > 1 or roots[0] > 2:
	print("NO")
	exit()

print("YES")

ans = []
if roots[0] == 2:
	ans.append((cyc[2][0][0], cyc[2][0][1]))
	for k in xrange(1, len(cyc[2])):
		ans.append((cyc[2][0][0], cyc[2][k][0]))
		ans.append((cyc[2][0][1], cyc[2][k][1]))
else:
	for k in xrange(1, len(cyc[1])):
		ans.append((cyc[1][0][0], cyc[1][k][0]))

for l in lengths:
	if l == roots[0]:
		continue
	parent = cyc[l][0].pop()
	for cc in cyc[l]:
		for i in xrange(len(cc)):
			ans.append((cyc[parent][0][i % parent], cc[i]))

print('\n'.join('%d %d' % (p[0] + 1, p[1] + 1) for p in ans))
