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.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.LinkedList;

import javax.swing.plaf.synth.SynthSeparatorUI;

import java.util.*;

public class Main {
	
	static HashMap<Integer, Integer> map = new HashMap<>();
    public static void main(String[] args) {
        FasterScanner s = new FasterScanner();
        PrintWriter out=new PrintWriter(System.out);
        int n=s.nextInt();
        int[] a = new int[n];
        boolean[] done = new boolean[n];
        for(int i=0;i<n;i++)
        	a[i]=s.nextInt()-1;
        int cycle [] = new int[n+1];
        int count=0;
        Arrays.fill(cycle, -1);
        int[] b = new int[n];
        for(int i=0;i<n;i++){
        	if(done[i])
        		continue;
        	int len=1;
        	int now=a[i];
        	while(now!=i){
        		done[now]=true;
        		now=a[now];
        		len++;
        	}
        	if(len%2==0 && cycle[len]==-1){
//        		System.out.println("in first if"+" "+ len+" "+i);
        		cycle[len]=i;
        		count++;
        	}
        	else if(len%2==0){
//        		System.out.println("in second if"+" "+ len+" "+i);
        		int start1=cycle[len];
        		cycle[len]=-1;
        		count--;
        		int start2=i;
        		int now1=start1;
        		int now2=start2;
        		do{
        			b[now1]=now2;
        			now1=a[now1];
        			b[now2]=now1;
        			now2=a[now2];
        		}while(now1!=start1 && now2!=start2);	
        	}
        	else{
//        		System.out.println("in third if"+" "+ len);
        		int x=len+1;
        		x>>=1;
//        		System.out.println(x);
        		int p1=i,p2=i;
        		for(int k=0;k<x;k++)
        			p2=a[p2];
        		for(int k=0;k<len;k++){
        			b[p1]=p2;
        			p1=a[p1];
        			p2=a[p2];
        		}
        	}
        }
        if(count!=0){
        	System.out.println(-1);
        	return;
        }
        for(int i=0;i<n;i++)
        	out.print((b[i]+1)+" ");
        out.close();
    }

    
    
    
    
    
    
    
    static class Node
    {
    	int id=0;
    	char ch;
    	boolean done=false;
    	Node l,r;
    	int parent=0;
    	Node(char ch){ this.ch=ch;}
		
    }
    static int gcd (long m, long n){
        long x;
        long y;
        while(m%n != 0){
            x = n;
            y = m%n;
            m = x;
            n = y;
        }
        return (int) n;
    }

    
    
    
    public static class st {
    	
	    int n;
	    int[] t;
	   
	    void build(int n2) {  // build the tree
	       t=new int[2*n2];
	       n=n2;
	       
	    }
	    void modify(int p, int value) {
	      for (t[p += n] += value; p > 1; p >>= 1) t[p>>1] = t[p] + t[p^1];
	    }
	    int query(int l, int r) {  // sum on interval [l, r)
	      int res=0;
	      for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
	            if ((l&1)!=0) res+=t[l++];
	            if ((r&1)!=0) res+=t[--r];
	          }
	      return res;
	    }
	}
    
  
   
   
   
   
   
   
   
   
   
   
    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
          
        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
      
        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
}