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 MOD = 1000000007;
const double EXP = 2.7182818284590452;
const double Pi = 3.14159265;
const double EPS = 1e-13;
const int INF = 1000 * 1000 * 1001;
const long long INFL = (long long)INF * (long long)INF;
map<pair<long long, long long>, long long> hashgcd;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (hashgcd.find(std::make_pair(a, b)) != hashgcd.end())
    return hashgcd[std::make_pair(a, b)];
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  hashgcd[std::make_pair(a, b)] = a;
  return a;
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long extgcd(long long a, long long b, long long& x, long long& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x11, y11;
  long long d = extgcd(b % a, a, x11, y11);
  x = y11 - (b / a) * x11;
  y = x11;
  return d;
}
long long poww(long long v, long long p, long long mod) {
  if (p == 0) return 1;
  if (p & 1) {
    return (poww(v, p - 1, mod) * v) % mod;
  } else {
    long long t = poww(v, p / 2, mod);
    return (t * t) % mod;
  }
}
const unsigned long long L31018 = 3000000000000000000L;
int arr[1000006], res[1000006], t[1000006 + 2], a;
vector<int> c[1000006];
int was[1000006];
int n;
int circle(int cur) {
  int num = 0;
  while (!was[cur]) {
    ++num;
    was[cur] = 1;
    cur = arr[cur];
  }
  return num;
}
void evenHandler(int f, int s) {
  int cur = f;
  res[f] = arr[s];
  while (!was[cur]) {
    was[cur] = true;
    res[res[cur]] = arr[cur];
    cur = res[cur];
  }
}
void oddHandler(int size, int cur) {
  int num = 0;
  while (!was[cur]) {
    was[cur] = 1;
    t[num] = cur;
    ++num;
    cur = arr[cur];
  }
  int d = num / 2;
  for (int i = (0); i < (d + 1); ++i) t[i + num] = t[i];
  for (int i = (0); i < (num); ++i) {
    res[t[i]] = arr[t[i + d]];
  }
}
void accept() {
  cin >> n;
  for (int i = (1); i < (n + 1); ++i) scanf("%d", arr + i);
  int id = 1;
  for (int i = (1); i < (n + 1); ++i) {
    if (was[i] == 0) {
      a = circle(i);
      c[a].push_back(i);
    }
  }
  id = 0;
  for (int i = (1); i < (n + 1); ++i) {
    was[i] = 0;
  }
  id = c[1].size();
  for (int i = (0); i < (id); ++i) {
    res[c[1][i]] = c[1][i];
  }
  for (int i = (2); i < (n + 1); ++i) {
    if (c[i].size() == 0) continue;
    if (i & 1) {
      id = c[i].size();
      for (int j = (0); j < (id); ++j) {
        oddHandler(i, c[i][j]);
      }
    } else {
      id = c[i].size();
      if (id & 1) {
        cout << -1;
        return;
      }
      for (int j = 1; j < id; j += 2) {
        evenHandler(c[i][j], c[i][j - 1]);
      }
    }
  }
  for (int i = (1); i < (n + 1); ++i) {
    printf("%d ", res[i]);
  }
}
int main(void) {
  accept();
  return 0;
}
