A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. For example, the square of q = [4, 5, 1, 2, 3] is p = q2 = [2, 3, 4, 5, 1].

This problem is about the inverse operation: given the permutation p you task is to find such permutation q that q2 = p. If there are several such q find any of them.

Input

The first line contains integer n (1 ≤ n ≤ 106) — the number of elements in permutation p.

The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the elements of permutation p.

Output

If there is no permutation q such that q2 = p print the number "-1".

If the answer exists print it. The only line should contain n different integers qi (1 ≤ qi ≤ n) — the elements of the permutation q. If there are several solutions print any of them.

Examples

Input

4
2 1 4 3


Output

3 4 2 1


Input

4
2 1 3 4


Output

-1


Input

5
2 3 4 5 1


Output

4 5 1 2 3
import java.io.*;
import java.util.*;

import javax.xml.crypto.dsig.keyinfo.KeyValue;

public class Solution {

  static ArrayList<Integer> getCycle(int[] numbers, int startNumber) {
    ArrayList<Integer> cycle = new ArrayList<Integer>();
    int next = numbers[startNumber];
    for (int number = startNumber; numbers[number] != 0; number = next) {
      cycle.add(numbers[number]);

      next = numbers[number];
      numbers[number] = 0;
    }
    return cycle;
  }

  static HashMap<Integer, ArrayList<ArrayList<Integer>>> getCyclesBySize(int[] numbers) {
    HashMap<Integer, ArrayList<ArrayList<Integer>>> cyclesBySize =
        new HashMap<Integer, ArrayList<ArrayList<Integer>>>();
    for (int i = 1; i < numbers.length; ++i) {
      if (numbers[i] != 0) {
        ArrayList<Integer> cycle = getCycle(numbers, i);
        if (!cyclesBySize.containsKey(cycle.size())) {
          cyclesBySize.put(cycle.size(), new ArrayList<ArrayList<Integer>>());
        }
        cyclesBySize.get(cycle.size()).add(cycle);
      }
    }
    return cyclesBySize;
  }

  static boolean doesSquareRootExist(HashMap<Integer, ArrayList<ArrayList<Integer>>> cyclesBySize) {
    for (Map.Entry<Integer, ArrayList<ArrayList<Integer>>> entry : cyclesBySize.entrySet()) {
      if (entry.getKey() % 2 == 0 && entry.getValue().size() % 2 == 1) {
        return false;
      }
    }
    return true;
  }
  
  static void setOddCycles(ArrayList<ArrayList<Integer>> cycles, int[] squareRoot) {
    for (ArrayList<Integer> cycle : cycles) {
      int k = cycle.size() / 2;
      int prev = 0;
      for (int i = 0; i < k; ++i) {
        if (prev != 0) {
          squareRoot[prev] = cycle.get(i);
        }
        prev = cycle.get(i + k + 1);
        squareRoot[cycle.get(i)] = prev;
      }
      squareRoot[prev] = cycle.get(k);
      squareRoot[cycle.get(k)] = cycle.get(0);
    }
  }
  
  static void setEvenCycles(ArrayList<ArrayList<Integer>> cycles, int[] squareRoot) {
    for (int i = 0; i < cycles.size() - 1; i += 2) {
      ArrayList<Integer> cycleA = cycles.get(i);
      ArrayList<Integer> cycleB = cycles.get(i + 1);
      int last = 0;
      for (int j = 0; j < cycleA.size(); ++j) {
        if (last != 0) {
          squareRoot[last] = cycleA.get(j);
        }
        last = cycleB.get(j);
        squareRoot[cycleA.get(j)] = last;
      }
      squareRoot[last] = cycleA.get(0);
    }
  }

  static int[] getSquareRoot(int[] numbers) {
    HashMap<Integer, ArrayList<ArrayList<Integer>>> cyclesBySize = getCyclesBySize(numbers);
    if (!doesSquareRootExist(cyclesBySize)) {
      return null;
    }
    int[] squareRoot = new int[numbers.length];
    for (Map.Entry<Integer, ArrayList<ArrayList<Integer>>> entry : cyclesBySize.entrySet()) {
      if (entry.getKey() % 2 == 1) {
        setOddCycles(entry.getValue(), squareRoot);
      } else {
        setEvenCycles(entry.getValue(), squareRoot);
      }
    }
    return squareRoot;
  }

  public static void main(String[] args) {
    MyScanner sc = new MyScanner();
    int n = sc.nextInt();

    int[] numbers = new int[n + 1];
    for (int i = 1; i <= n; ++i) {
      numbers[i] = sc.nextInt();
    }

    out = new PrintWriter(new BufferedOutputStream(System.out));
    
    int[] squareRoot = getSquareRoot(numbers);
    if (squareRoot == null) {
      out.print(-1);
    } else {
      for (int i = 1; i < squareRoot.length - 1; ++i) {
        out.print(squareRoot[i] + " ");
      }
      out.println(squareRoot[squareRoot.length - 1]);
    }

    out.close();
  }

  public static PrintWriter out;

  public static class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}