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.

import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
public class Main
{
  static FastScanner in = new FastScanner(System.in);
  static StringBuilder sb = new StringBuilder();
  static DecimalFormat df = new DecimalFormat();
  public static void main(String[] args)
  {
    df.setMaximumFractionDigits(20);
    df.setMinimumFractionDigits(20);
    df.setRoundingMode(RoundingMode.DOWN);
    // String formatted = df.format(0.2);
    // Never sort array of primitive type
    int N = in.nextInt();
    int P[] = new int[N];
    for (int i = 0; i < N; i++)
      P[i] = in.nextInt() - 1;
    int fixed = -1;
    for (int i = 0; i < N; i++)
      if (i == P[i])
        fixed = i;
    if (fixed >= 0)
    {
      System.out.println("YES");
      for (int i = 0; i < N; i++)
      {
        if (i != fixed)
        {
          System.out.println((i + 1) + " " + (fixed + 1));
        }
      }
      return;
    }
    int center = -1;
    for (int i = 0; i < N; i++)
      if (i == P[P[i]])
        center = i;
    if (center == -1)
    {
      System.out.println("NO");
      return;
    }
    boolean seen[] = new boolean[N];
    seen[center] = seen[P[center]] = true;
    sb.append("YES\n");
    sb.append(center + 1);
    sb.append(' ');
    sb.append(P[center] + 1);
    sb.append('\n');
    for (int i = 0; i < N; i++)
    {
      if (seen[i]) continue;
      ArrayList<Integer> ary = new ArrayList<Integer>();
      int cur = i;
      while (!seen[cur])
      {
        ary.add(cur);
        seen[cur] = true;
        cur = P[cur];
      }
      if (ary.size() % 2 == 1)
      {
        System.out.println("NO");
        return;
      }
      for (int j = 0; j < ary.size(); j++)
      {
        sb.append(ary.get(j) + 1);
        sb.append(' ');
        if (j % 2 == 0)
        {
          sb.append(center + 1);
        }
        else
        {
          sb.append(P[center] + 1);
        }
        sb.append('\n');
      }
    }
    System.out.print(sb.toString());
  }
  static BigInteger b(long n) { return BigInteger.valueOf(n);}
  static BigInteger b(String s) { return new BigInteger(s); }
  static BigDecimal bd(double d) { return BigDecimal.valueOf(d);}
  static BigDecimal bd(String s) { return new BigDecimal(s); }
}
class FastScanner
{
  BufferedReader reader;
  StringTokenizer tokenizer;
  FastScanner (InputStream inputStream)
  {
    reader = new BufferedReader(new InputStreamReader(inputStream));
  }
  String nextToken()
  {
    while (tokenizer == null || ! tokenizer.hasMoreTokens())
    {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e){}
    }
    return tokenizer.nextToken();
  }
  boolean hasNext()
  {
    if (tokenizer == null || ! tokenizer.hasMoreTokens())
    {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e){ return false; }
    }
    return true;
  }
  int nextInt()
  {
    return Integer.parseInt(nextToken());
  }
}
