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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

    static class _612E {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();

            int[] p = new int[n + 1];

            for (int i = 1; i <= n; i++) {
                p[i] = in.nextInt();
            }

            boolean[] vis = new boolean[n + 1];

            Map<Integer, List<List<Integer>>> csm = new HashMap<>();
            List<List<Integer>> oc = new ArrayList<>();

            int[] ans = new int[n + 1];

            for (int i = 1; i <= n; i++) {
                if (p[i] == i) {
                    ans[i] = i;
                    vis[i] = true;
                    continue;
                }

                if (!vis[i]) {
                    List<Integer> nc = new ArrayList<>();
                    dfs(i, p, vis, nc);

                    if (nc.size() % 2 == 0) {
                        if (!csm.containsKey(nc.size())) {
                            csm.put(nc.size(), new ArrayList<>());
                        }
                        csm.get(nc.size()).add(nc);
                    } else {
                        oc.add(nc);
                    }
                }

            }

            for (Integer size : csm.keySet()) {
                if (csm.get(size).size() % 2 == 1) {
                    out.println("-1");
                    return;
                }
            }

            for (int i = 0; i < oc.size(); i++) {
                List<Integer> cl = oc.get(i);

                for (int j = 0, k = cl.size() / 2 + 1; j < cl.size() / 2; j++, k++) {
                    ans[cl.get(j)] = cl.get(k);
                    ans[cl.get(k)] = cl.get(j + 1);
                }
                ans[cl.get(cl.size() / 2)] = cl.get(0);
            }

            for (Integer size : csm.keySet()) {
                List<List<Integer>> cll = csm.get(size);

                for (int i = 0; i < cll.size() - 1; i += 2) {
                    List<Integer> cl1 = cll.get(i);
                    List<Integer> cl2 = cll.get(i + 1);

                    for (int j = 0; j < size - 1; j++) {
                        ans[cl1.get(j)] = cl2.get(j);
                        ans[cl2.get(j)] = cl1.get(j + 1);
                    }
                    ans[cl1.get(size - 1)] = cl2.get(size - 1);
                    ans[cl2.get(size - 1)] = cl1.get(0);
                }
            }

            for (int i = 1; i <= n; i++) {
                out.print(ans[i] + " ");
            }
        }

        void dfs(int u, int[] p, boolean[] vis, List<Integer> nc) {
            vis[u] = true;
            nc.add(u);

            if (!vis[p[u]])
                dfs(p[u], p, vis, nc);

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}

