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
#include <bits/stdc++.h>
using namespace std;
const int N = 1000050;
namespace io {
const int L = (1 << 19) + 1;
char ibuf[L], *iS, *iT, obuf[L], *oS = obuf, *oT = obuf + L - 1, c, st[55];
int f, tp;
inline char gc() {
  if (iS == iT) {
    iT = (iS = ibuf) + fread(ibuf, 1, L, stdin);
    return iS == iT ? EOF : *iS++;
  }
  return *iS++;
}
inline void cbuf() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) cbuf();
}
inline void gi(int &x) {
  for (f = 1, c = gc(); c < '0' || c > '9'; c = gc())
    if (c == '-') f = -1;
  for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15);
  x *= f;
}
inline void print(int x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) st[++tp] = x % 10 + '0', x /= 10;
  while (tp) putc(st[tp--]);
  putc(' ');
}
};  // namespace io
using io::gi;
using io::print;
int a[N], vis[N], n, m, ans[N];
vector<int> zh[N], id[N];
int main() {
  int i, j, g;
  for (gi(n), i = 1; i <= n; i++) gi(a[i]);
  for (i = 1; i <= n; i++) {
    if (!vis[i]) {
      m++, j = i;
      while (!vis[j]) {
        zh[m].push_back(j);
        vis[j] = 1, j = a[j];
      }
      id[zh[m].size()].push_back(m);
    }
  }
  for (i = 1; i <= n; i++) {
    if (i & 1) {
      for (g = 0; g < id[i].size(); g++)
        for (j = 0; j < i; j++)
          ans[zh[id[i][g]][j]] = zh[id[i][g]][(j + (i + 1 >> 1)) % i];
    } else {
      if (id[i].size() & 1) {
        puts("-1");
        return 0;
      }
      for (g = 0; g < id[i].size(); g += 2) {
        for (j = 0; j < i; j++) {
          ans[zh[id[i][g]][j]] = zh[id[i][g + 1]][j];
          ans[zh[id[i][g + 1]][j]] = zh[id[i][g]][(j + 1) % i];
        }
      }
    }
  }
  for (i = 1; i <= n; i++) print(ans[i]);
  io::cbuf();
  return 0;
}
