#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
vector<int> loops[N];
int a[N];
bool vis[N];
int ans[N];
int rak[N];
bool cmp(int x, int y) { return loops[x].size() < loops[y].size(); }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    cnt++;
    int x = i;
    while (true) {
      loops[cnt].push_back(x);
      vis[x] = true;
      x = a[x];
      if (x == i) break;
    }
  }
  for (int i = 1; i <= cnt; i++) rak[i] = i;
  sort(rak + 1, rak + cnt + 1, cmp);
  for (int i = 1; i <= n; i++)
    if (loops[rak[i]].size() & 1) {
      vector<int> vv;
      vv.resize(loops[rak[i]].size());
      for (int j = 0; j < loops[rak[i]].size(); j++) {
        vv[2 * j % loops[rak[i]].size()] = loops[rak[i]][j];
      }
      for (int j = 0; j < vv.size(); j++) ans[vv[j]] = vv[(j + 1) % vv.size()];
    } else {
      if (i == n) {
        printf("-1\n");
        return 0;
      }
      if (loops[rak[i + 1]].size() != loops[rak[i]].size()) {
        printf("-1\n");
        return 0;
      }
      for (int j = 0; j < loops[rak[i]].size() * 2; j++) {
        if (j & 1) {
          int x = loops[rak[i + 1]][j / 2],
              y = loops[rak[i]][(j + 1) / 2 % loops[rak[i]].size()];
          ans[x] = y;
        } else {
          int x = loops[rak[i]][j / 2], y = loops[rak[i + 1]][j / 2];
          ans[x] = y;
        }
      }
      i++;
    }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
