#include <bits/stdc++.h>
using namespace std;
int n, a[1000005], v[1000005], fix[1000005], raod;
int ans[1000005];
vector<int> g, ne;
vector<int> hav[1000005];
void go(int x) {
  raod++;
  g.push_back(x);
  fix[x] = 1;
  if (!fix[v[x]]) go(v[x]);
}
int main() {
  ios::sync_with_stdio(false);
  srand(time(NULL));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    v[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (!fix[i]) {
      raod = 0;
      g.clear();
      go(i);
      if (raod % 2 == 1) {
        if (raod == 1) {
          ans[g[0]] = g[0];
          continue;
        }
        int first = raod / 2;
        for (int i = 0; i < (int)g.size(); i++)
          ans[g[i]] = g[(i + first) % (int)g.size()];
      } else {
        if (hav[raod].size() == 0) {
          hav[raod] = g;
          continue;
        }
        ne.clear();
        for (int i = 0; i < 2 * raod; i++) {
          if (i & 1)
            ne.push_back(g[i / 2]);
          else
            ne.push_back(hav[raod][i / 2]);
        }
        for (int i = 1; i < (int)ne.size(); i++) ans[ne[i]] = ne[i - 1];
        ans[ne[0]] = ne[2 * raod - 1];
        hav[raod].clear();
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (hav[i].size() > 0) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
