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 long long N = 2e6 + 6;
const long long inf = 1e18;
const long long M = 1e9 + 7;
long long A[N];
bool vis[N];
long long ans[N];
long long n;
void solve() {
  cin >> n;
  for (long long i = 1; i < n + 1; i++) vis[i] = 0;
  for (long long i = 1; i < n + 1; i++) cin >> A[i];
  vector<vector<pair<long long, long long> > > odd, even;
  for (long long i = 1; i < n + 1; i++) {
    if (vis[i]) continue;
    long long k = i;
    vector<pair<long long, long long> > vec;
    while (!vis[k]) {
      pair<long long, long long> p = {k, A[k]};
      vec.push_back(p);
      vis[k] = 1;
      k = A[k];
    }
    if (vec.size() & 1)
      odd.push_back(vec);
    else
      even.push_back(vec);
  }
  if (even.size() & 1) {
    cout << -1;
    return;
  }
  map<long long, long long> m;
  for (auto &x : even) m[x.size()]++;
  for (auto &x : m) {
    if (x.second & 1) {
      cout << -1;
      return;
    }
  }
  sort(even.begin(), even.end(),
       [&](vector<pair<long long, long long> > a,
           vector<pair<long long, long long> > b) {
         return a.size() < b.size();
       });
  for (long long i = 0; i < even.size(); i += 2) {
    long long x = even[i].size();
    vector<pair<long long, long long> > res(2 * x);
    long long f1 = i, f2 = i + 1;
    for (long long j = 0, k = 0; j < 2 * x; j += 2, k++) {
      res[j].first = even[f1][k].first;
      res[j + 1].first = even[f2][k].first;
    }
    for (long long j = 0; j < 2 * x - 1; j++) {
      res[j].second = res[j + 1].first;
    }
    res[2 * x - 1].second = res[0].first;
    for (long long k = 0; k < 2 * x; k++) {
      ans[res[k].first] = res[k].second;
    }
  }
  for (long long i = 0; i < odd.size(); i++) {
    if (odd[i].size() == 1) {
      ans[odd[i][0].first] = odd[i][0].first;
      continue;
    }
    long long x = odd[i].size();
    vector<pair<long long, long long> > res(x);
    for (long long j = 0; j < x; j += 2) {
      if (j == 0) {
        res[j].first = odd[i][0].first;
        res[j + 1].second = odd[i][0].second;
      } else {
        res[j].first = res[j - 1].second;
        if (j + 1 < x) res[j + 1].second = A[res[j].first];
      }
    }
    res[0].second = A[res[x - 1].first];
    for (long long j = 1; j < x; j += 2) {
      res[j].first = res[j - 1].second;
      res[j + 1].second = A[res[j].first];
    }
    for (auto &x : res) ans[x.first] = x.second;
  }
  for (long long i = 1; i < n + 1; i++) cout << ans[i] << " ";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) solve();
}
