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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Artem Gilmudinov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Reader in = new Reader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, Reader in, PrintWriter out) {
            int n = in.ni();
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = in.ni() - 1;
            }
            ArrayList<ArrayList<Cycle>> cycles = new ArrayList<>();
            for (int i = 0; i <= n; i++) {
                cycles.add(new ArrayList<>());
            }
            boolean[] used = new boolean[n];
            for (int i = 0; i < n; i++) {
                if (!used[i]) {
                    int cur = i;
                    ArrayList<Integer> cycle = new ArrayList<>();
                    while (!used[cur]) {
                        used[cur] = true;
                        cycle.add(cur);
                        cur = p[cur];
                    }
                    cycles.get(cycle.size()).add(new Cycle(cycle));
                }
            }
            int[] q = new int[n];
            Arrays.fill(used, false);
            for (int i = 1; i <= n; i++) {
                ArrayList<Cycle> list = cycles.get(i);
                if (i % 2 == 0) {
                    if (list.size() % 2 != 0) {
                        out.println(-1);
                        return;
                    }
                    for (int j = 0; j < list.size(); j += 2) {
                        Cycle cycle1 = list.get(j);
                        Cycle cycle2 = list.get(j + 1);
                        int prev, next, size;
                        size = cycle1.vertexes.size();
                        prev = 0;
                        next = 0;
                        while (!used[cycle1.vertexes.get(prev)]) {
                            used[cycle1.vertexes.get(prev)] = true;
                            q[cycle1.vertexes.get(prev)] = cycle2.vertexes.get(next);
                            q[cycle2.vertexes.get(next)] = cycle1.vertexes.get((prev + 1) % size);
                            prev = (prev + 1) % size;
                            next = (next + 1) % size;
                        }
                    }
                } else {
                    for (Cycle cycle : list) {
                        if (cycle.vertexes.size() == 1) {
                            q[cycle.vertexes.get(0)] = cycle.vertexes.get(0);
                            continue;
                        }
                        int size = cycle.vertexes.size();
                        int prev = 0;
                        int next = size / 2 + 1;
                        int temp;
                        while (!used[cycle.vertexes.get(prev)]) {
                            used[cycle.vertexes.get(prev)] = true;
                            q[cycle.vertexes.get(prev)] = cycle.vertexes.get(next);
                            temp = next;
                            next = (prev + 1) % size;
                            prev = temp;
                        }
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                out.print(q[i] + 1 + " ");
            }
        }

        class Cycle {
            public ArrayList<Integer> vertexes;

            public Cycle(ArrayList<Integer> cycle) {
                this.vertexes = cycle;
            }


            public String toString() {
                return this.vertexes.toString();
            }

        }

    }

    static class Reader {
        private BufferedReader in;
        private StringTokenizer st = new StringTokenizer("");
        private String delim = " ";

        public Reader(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            if (!st.hasMoreTokens()) {
                st = new StringTokenizer(rl());
            }
            return st.nextToken(delim);
        }

        public String rl() {
            try {
                return in.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public int ni() {
            return Integer.parseInt(next());
        }

    }
}

