#include <bits/stdc++.h>
using namespace std;
int p[1000001], visited[1000001], q[1000001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int e, n, i, x, y, j, ws, o, k;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> o;
    if (o != i) {
      p[i] = o;
      visited[i] = 0;
    } else {
      q[i] = i;
      visited[i] = 1;
    }
  }
  map<int, vector<vector<int> > > m;
  for (i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      x = i;
      vector<int> v;
      v.push_back(x);
      visited[x] = 1;
      while (p[x] != i) {
        x = p[x];
        visited[x] = 1;
        v.push_back(x);
      }
      y = v.size();
      if (y % 2) {
        int a, b;
        a = 0;
        b = y / 2 + 1;
        while (a != y) {
          q[v[a]] = v[b];
          a = (a + 1);
          b = (b + 1) % y;
        }
      } else {
        vector<vector<int> > w = m[y];
        ws = w.size();
        if (ws == 0) {
          (m[y]).push_back(v);
        } else {
          vector<int> d;
          for (e = 0; e < y; e++) {
            d.push_back(w[ws - 1][e]);
            d.push_back(v[e]);
          }
          (m[y]).pop_back();
          for (j = 1; j < 2 * y; j++) {
            q[d[j - 1]] = d[j];
          }
          q[d[2 * y - 1]] = d[0];
        }
      }
    }
  }
  int flag = 0;
  map<int, vector<vector<int> > >::iterator mi;
  for (mi = m.begin(); mi != m.end(); mi++) {
    if (((mi)->second).size() != 0) {
      flag = 1;
      break;
    }
  }
  if (flag)
    printf("-1\n");
  else {
    for (i = 0; i < n; i++) printf("%d ", q[i + 1]);
    printf("\n");
  }
}
