#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
int n, tot, a[maxn], b[maxn], s[maxn], l[maxn], cir[maxn];
bool flag[maxn];
bool com(int a, int b) { return l[a] < l[b]; }
int main() {
  scanf("%d", &n);
  int i, j, k;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++)
    if (!flag[i]) {
      cir[++tot] = i;
      flag[i] = true;
      ++l[i];
      j = a[i];
      while (!flag[j]) {
        flag[j] = true;
        ++l[i];
        j = a[j];
      }
    }
  sort(cir + 1, cir + 1 + tot, com);
  int x = 0;
  bool f = true;
  for (i = 1; i <= tot; i++)
    if ((l[cir[i]] & 1) == 0) {
      if (x == 0)
        x = l[cir[i]];
      else if (x == l[cir[i]])
        x = 0;
      else
        f = false;
    }
  if (x != 0) f = false;
  if (f == false)
    printf("-1");
  else {
    for (i = 1; i <= tot; i++) {
      if ((l[cir[i]] & 1) == 1) {
        j = cir[i];
        k = 0;
        while (flag[j]) {
          s[k] = j;
          flag[j] = false;
          k = (k + 2) % l[cir[i]];
          j = a[j];
        }
        for (j = 0; j < l[cir[i]] - 1; j++) b[s[j]] = s[j + 1];
        b[s[l[cir[i]] - 1]] = s[0];
      } else {
        j = cir[i];
        k = cir[i + 1];
        while (flag[j]) {
          b[j] = k;
          b[k] = a[j];
          flag[j] = false;
          flag[k] = false;
          j = a[j];
          k = a[k];
        }
        ++i;
      }
    }
    for (i = 1; i <= n; i++) printf("%d ", b[i]);
  }
  return 0;
}
