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 oo = 0x3f3f3f3f;
const long long OO = 0x3f3f3f3f3f3f3f3fLL;
const int M7 = 1000000007;
const int M9 = 1000000009;
const long long M7L = 1000000007L;
template <typename T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <typename T, typename... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <typename T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
template <typename T>
void _W(const vector<T> &x) {
  for (auto i = x.cbegin(); i != x.cend(); i++) {
    if (i != x.cbegin()) putchar(' ');
    _W(*i);
  }
}
void W() {}
template <typename T, typename... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}
int n;
int p[1000005], q[1000005];
bool vis[1000005];
map<int, vector<int> > cnt;
int count(int u) {
  int ret = 1;
  vis[u] = true;
  for (int nxt = p[u]; nxt != u; nxt = p[nxt]) {
    vis[nxt] = true;
    ++ret;
  }
  return ret;
}
void walkodd(int u) {
  vector<int> tmp;
  int pos[1000005];
  int ucur = u, len;
  do {
    ;
    tmp.push_back(p[ucur]);
    ucur = p[ucur];
  } while (ucur != u);
  ;
  len = tmp.size();
  for (int i = 0; i <= int(len / 2); i++) {
    pos[i * 2] = tmp[i];
  }
  for (int i = len / 2 + 1; i <= int(len - 1); i++) {
    pos[2 * (i - (len + 1) / 2) + 1] = tmp[i];
  }
  for (int i = 0; i <= int(len - 1); i++) {
    q[pos[i]] = pos[(i + 1) % len];
  }
}
void walkeven(int u, int v) {
  int ucur = u, vcur = v;
  int unxt = p[u], vnxt = p[v];
  do {
    q[ucur] = vcur;
    q[vcur] = unxt;
    ucur = unxt, vcur = vnxt;
    unxt = p[ucur], vnxt = p[vcur];
  } while (ucur != u);
}
bool check() {
  for (auto u : cnt) {
    if (u.first & 1) {
      for (auto v : u.second) {
        walkodd(v);
      }
    } else {
      if (u.second.size() & 1) {
        return false;
      } else {
        for (int i = 0; i < u.second.size(); i += 2) {
          walkeven(u.second[i], u.second[i + 1]);
        }
      }
    }
  }
  return true;
}
bool checkans() {
  for (int i = 1; i <= int(n); i++) {
    if (p[i] != q[q[i]]) {
      ;
      return false;
    }
  }
  return true;
}
int main(int argc, char *argv[]) {
  int cc;
  bool space;
  R(n);
  for (int i = 1; i <= int(n); i++) {
    R(p[i]);
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= int(n); i++) {
    if (vis[i]) {
      continue;
    }
    cc = count(i);
    cnt[cc].push_back(i);
  };
  if (!check()) {
    W(-1);
  } else {
    ;
    space = false;
    for (int i = 1; i <= int(n); i++) {
      if (space)
        putchar(' ');
      else
        space = true;
      printf("%d", q[i]);
    }
    putchar('\n');
  }
  return 0;
}
