#include <bits/stdc++.h>
using namespace std;
int n;
bool f[1000005];
int a[1000005];
int ans[1000005] = {};
vector<int> v[1000005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    vector<int> q;
    if (f[i]) continue;
    int now = i;
    while (!f[now]) {
      f[now] = 1;
      q.push_back(now);
      now = a[now];
    }
    if ((q.size() & 1)) {
      int mid = (q.size()) >> 1;
      for (int i = 0; i < q.size(); i++)
        ans[q[i]] = q[(i + mid + 1) % q.size()];
      continue;
    }
    q.push_back(now);
    int len = q.size();
    if (v[len].empty())
      v[len] = q;
    else {
      vector<int> nownow;
      int x = 0, y = 0;
      for (int i = 0; i <= (len - 1) * 2; i++) {
        if ((x + y) & 1)
          nownow.push_back(q[y++]);
        else
          nownow.push_back(v[len][x++]);
      }
      for (int i = 0; i + 1 < nownow.size(); i++)
        ans[nownow[i]] = nownow[i + 1];
      v[len].clear();
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!ans[i]) {
      printf("-1");
      goto Thank_You;
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
Thank_You:;
  return 0;
}
