#include <bits/stdc++.h>
using namespace std;
const char *sp = "";
int n;
int p[1000005];
int q[1000005];
int vis[1000005];
map<int, vector<int> > c;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      int k = i;
      vector<int> cur;
      while (!vis[k]) {
        vis[k] = 1;
        cur.push_back(k);
        k = p[k];
      }
      int sz = cur.size();
      if (cur.size() % 2 == 1) {
        for (int j = 0; j < sz; j++) {
          q[cur[j]] = cur[(j + sz / 2 + 1) % sz];
        }
      } else {
        if (c.find(sz) != c.end()) {
          vector<int> nex = c[sz];
          c.erase(sz);
          for (int j = 0; j < sz; j++) {
            q[cur[j]] = nex[j];
            q[nex[j]] = cur[(j + 1) % sz];
          }
        } else {
          c[sz] = cur;
        }
      }
    }
  }
  if (c.size() > 0) {
    printf("-1\n");
  } else {
    for (int i = 1; i <= n; i++) {
      printf("%s%d", sp, q[i]);
      sp = " ";
    }
    printf("\n");
  }
  return 0;
}
