#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1000000007;
inline string getstr(string &s, int l, int r) {
  string ret = "";
  for (int i = l; i <= r; i++) ret.push_back(s[i]);
  return ret;
}
int modpow(int x, int y, int md = mod) {
  if (y == 0) return 1;
  int ret = modpow(x, y >> 1, md);
  ret = (long long)ret * ret % md;
  if (y & 1) ret = (long long)ret * x % md;
  return ret;
}
int n, sz = 0;
int to[1000005], ans[1000005];
bool vis[1000005];
vector<int> id[1000005];
void dfs(int x) {
  vis[x] = 1;
  sz++;
  if (!vis[to[x]]) dfs(to[x]);
}
vector<int> all;
bool used[1000005];
void get_v(int x) {
  used[x] = 1;
  all.push_back(x);
  if (!used[to[x]]) get_v(to[x]);
}
int pos[1000005], val[1000005];
void solve1(int x) {
  all.clear();
  get_v(x);
  for (int i = 0; i < all.size(); i++) {
    if (i + i < all.size()) {
      int v = i + i + 1;
      pos[v] = i;
      val[i] = v;
    } else {
      int v = i - (int)(all.size()) / 2;
      v *= 2;
      pos[v] = i;
      val[i] = v;
    }
  }
  for (int i = 0; i < all.size(); i++) {
    ans[all[i]] = all[pos[(val[i] % (int)all.size()) + 1]];
  }
}
vector<int> v1, v2;
void solve2(int x, int y) {
  all.clear();
  get_v(x);
  v1 = all;
  all.clear();
  get_v(y);
  v2 = all;
  for (int i = 0; i < v1.size(); i++) {
    ans[v1[i]] = v2[(i + 1) % (int)v2.size()];
  }
  for (int i = 0; i < v2.size(); i++) {
    ans[v2[i]] = v1[i];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &to[i]);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      sz = 0;
      dfs(i);
      id[sz].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!id[i].size()) continue;
    if (i & 1) {
      for (int j = 0; j < id[i].size(); j++) {
        solve1(id[i][j]);
      }
    } else {
      if (id[i].size() % 2) {
        puts("-1");
        return 0;
      }
      for (int j = 0; j < id[i].size(); j += 2) {
        solve2(id[i][j], id[i][j + 1]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}

### Prompt

Please provide a Cpp coded solution to the problem described below:

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 int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1000000007;
inline string getstr(string &s, int l, int r) {
  string ret = "";
  for (int i = l; i <= r; i++) ret.push_back(s[i]);
  return ret;
}
int modpow(int x, int y, int md = mod) {
  if (y == 0) return 1;
  int ret = modpow(x, y >> 1, md);
  ret = (long long)ret * ret % md;
  if (y & 1) ret = (long long)ret * x % md;
  return ret;
}
int n, sz = 0;
int to[1000005], ans[1000005];
bool vis[1000005];
vector<int> id[1000005];
void dfs(int x) {
  vis[x] = 1;
  sz++;
  if (!vis[to[x]]) dfs(to[x]);
}
vector<int> all;
bool used[1000005];
void get_v(int x) {
  used[x] = 1;
  all.push_back(x);
  if (!used[to[x]]) get_v(to[x]);
}
int pos[1000005], val[1000005];
void solve1(int x) {
  all.clear();
  get_v(x);
  for (int i = 0; i < all.size(); i++) {
    if (i + i < all.size()) {
      int v = i + i + 1;
      pos[v] = i;
      val[i] = v;
    } else {
      int v = i - (int)(all.size()) / 2;
      v *= 2;
      pos[v] = i;
      val[i] = v;
    }
  }
  for (int i = 0; i < all.size(); i++) {
    ans[all[i]] = all[pos[(val[i] % (int)all.size()) + 1]];
  }
}
vector<int> v1, v2;
void solve2(int x, int y) {
  all.clear();
  get_v(x);
  v1 = all;
  all.clear();
  get_v(y);
  v2 = all;
  for (int i = 0; i < v1.size(); i++) {
    ans[v1[i]] = v2[(i + 1) % (int)v2.size()];
  }
  for (int i = 0; i < v2.size(); i++) {
    ans[v2[i]] = v1[i];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &to[i]);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      sz = 0;
      dfs(i);
      id[sz].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!id[i].size()) continue;
    if (i & 1) {
      for (int j = 0; j < id[i].size(); j++) {
        solve1(id[i][j]);
      }
    } else {
      if (id[i].size() % 2) {
        puts("-1");
        return 0;
      }
      for (int j = 0; j < id[i].size(); j += 2) {
        solve2(id[i][j], id[i][j + 1]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}

```