#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-10;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
template <class T>
inline T sq(T a) {
  return a * a;
}
const int MAX_N = 1000010;
int n;
int a[MAX_N];
bool used[MAX_N];
bool pooling[MAX_N];
vector<int> ss[MAX_N];
int ans[MAX_N];
vector<int> split(int x) {
  vector<int> res = {x};
  int cur = a[x];
  while (cur != x) {
    res.emplace_back(cur);
    cur = a[cur];
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (long long int i = (0); i < (long long int)(n); i++)
    scanf("%d", &a[i]), a[i]--;
  for (long long int i = (0); i < (long long int)(n); i++)
    if (!used[i]) {
      vector<int> res = split(i);
      for (auto &w : res) used[w] = true;
      int m = ((long long int)(res).size());
      if (m % 2 == 1) {
        for (long long int i = (0); i < (long long int)(m / 2); i++) {
          ans[res[i]] = res[i + m / 2 + 1];
          ans[res[i + m / 2 + 1]] = res[i + 1];
        }
        ans[res[m / 2]] = res[0];
      } else {
        if (!pooling[m]) {
          pooling[m] = true;
          ss[m] = res;
        } else {
          for (long long int i = (0); i < (long long int)(m); i++)
            ans[res[i]] = ss[m][i], ans[ss[m][i]] = res[(i + 1) % m];
          pooling[m] = false;
        }
      }
    }
  for (long long int i = (0); i < (long long int)(MAX_N); i++)
    if (pooling[i]) {
      puts("-1");
      return 0;
    }
  for (long long int i = (0); i < (long long int)(n); i++)
    printf("%d%c", ans[i] + 1, i == n - 1 ? '\n' : ' ');
  return 0;
}

### Prompt

Please formulate a Cpp solution to the following problem:

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-10;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
template <class T>
inline T sq(T a) {
  return a * a;
}
const int MAX_N = 1000010;
int n;
int a[MAX_N];
bool used[MAX_N];
bool pooling[MAX_N];
vector<int> ss[MAX_N];
int ans[MAX_N];
vector<int> split(int x) {
  vector<int> res = {x};
  int cur = a[x];
  while (cur != x) {
    res.emplace_back(cur);
    cur = a[cur];
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (long long int i = (0); i < (long long int)(n); i++)
    scanf("%d", &a[i]), a[i]--;
  for (long long int i = (0); i < (long long int)(n); i++)
    if (!used[i]) {
      vector<int> res = split(i);
      for (auto &w : res) used[w] = true;
      int m = ((long long int)(res).size());
      if (m % 2 == 1) {
        for (long long int i = (0); i < (long long int)(m / 2); i++) {
          ans[res[i]] = res[i + m / 2 + 1];
          ans[res[i + m / 2 + 1]] = res[i + 1];
        }
        ans[res[m / 2]] = res[0];
      } else {
        if (!pooling[m]) {
          pooling[m] = true;
          ss[m] = res;
        } else {
          for (long long int i = (0); i < (long long int)(m); i++)
            ans[res[i]] = ss[m][i], ans[ss[m][i]] = res[(i + 1) % m];
          pooling[m] = false;
        }
      }
    }
  for (long long int i = (0); i < (long long int)(MAX_N); i++)
    if (pooling[i]) {
      puts("-1");
      return 0;
    }
  for (long long int i = (0); i < (long long int)(n); i++)
    printf("%d%c", ans[i] + 1, i == n - 1 ? '\n' : ' ');
  return 0;
}

```