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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.StringTokenizer;

public class CFPROBE {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[] array = new int[n + 1];
		boolean[] bool = new boolean[n + 1];
		for (int a = 0; a < n; a++) {
			array[a + 1] = input.nextInt();
			bool[a+1] = true;
		}
		int startIndex = 1;
		int currentIndex = 1;
		int count = 1;
		int[] storage = new int[n + 1];
		int[] permutationStartsForLength = new int[n+1];
		ArrayList<Pair> output = new ArrayList<Pair>();
		while (true) {
			if(startIndex > n){
				break;
			}
			if (bool[startIndex] || bool[currentIndex]) {
				bool[currentIndex] = false;
				currentIndex = array[currentIndex];
				if (currentIndex == startIndex) {
					if(permutationStartsForLength[count] == 0){
						permutationStartsForLength[count] = startIndex;
					}
					else{
						//System.out.println(count + "adding " + permutationStartsForLength[count] + " " + startIndex);
						output.add(new Pair(permutationStartsForLength[count], startIndex));
						permutationStartsForLength[count] = 0;
					}
					storage[count]++;
					startIndex++;
					count = 0;
					currentIndex = startIndex;
				}
				count++;
			}
			else{
				startIndex++;
				currentIndex = startIndex;
			}
		}
		boolean OK = true;
		for(int a = 2; a <= n; a=a+2){
			OK = OK && (storage[a]%2==0);
		}
		if(OK){
			int[] outputPermutation = new int[n+1];
			for(Pair a: output){
				//System.out.println(a.c + " " + a.d);
				ArrayList<Integer> permutation1 = getPermutation(a.c, array);
				ArrayList<Integer> permutation2 = getPermutation(a.d, array);
				//System.out.println(permutation1 + " " + permutation2);
				for(int b = 0; b < permutation1.size(); b++){
					outputPermutation[permutation1.get(b)] = permutation2.get(b);
					outputPermutation[permutation2.get(b)] = permutation1.get((b+1)%permutation1.size());
				}
			}
			for(int a = 0; a <= n; a++){
				if(permutationStartsForLength[a] != 0){
					ArrayList<Integer> perm1 = getPermutation(permutationStartsForLength[a], array);
					ArrayList<Integer> finalPerm = invertOdd(perm1, array);
					for(int b = 0; b < perm1.size(); b++){
						outputPermutation[perm1.get(b)] = finalPerm.get(b);
					}
				}
			}
			StringBuilder outputString = new StringBuilder();
			for(int a = 1; a <= n; a++){
				outputString.append(outputPermutation[a] + " ");
			}		
			System.out.println(outputString);
		}
		else{
			System.out.println(-1);
		}
	}
	private static ArrayList<Integer> invertOdd(ArrayList<Integer> perm1, int[] array) {
		int start = perm1.get(0);
		int startResult = permute(start, perm1.size()/2 + 1, array);
		ArrayList<Integer> output = new ArrayList<Integer>();
		output.add(startResult);
		for(int a = 1; a < perm1.size(); a++){
			startResult = array[startResult];
			output.add(startResult);
		}
		//System.out.println(output);
		return output;
	}
	private static int permute(int start, int number, int[] array){
		for(int a = 0; a < number; a++){
			start = array[start];
		}
		return start;
	}
	public static class Pair{
		int c;
		int d;
		public Pair(int a, int b){
			c = a;
			d = b;
		}
	}
	public static ArrayList<Integer> getPermutation(int start, int[] permutation){
		ArrayList<Integer> startIndex = new ArrayList<Integer>();
		int current = start;
		do{
			startIndex.add(current);
			current = permutation[current];
			
		}while(current != start);
		
		return startIndex;
	}
}