#include <bits/stdc++.h>
using namespace std;
int P[1000006];
bool visited[1000006];
vector<vector<int> > cycles[1000006];
vector<int> temp;
int main() {
  int n, u;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &P[i]);
    cycles[i].clear();
  }
  for (int i = 1; i <= n; i++) {
    if (visited[i]) continue;
    temp.clear();
    u = i;
    while (!visited[u]) {
      temp.push_back(u);
      visited[u] = true;
      u = P[u];
    }
    cycles[temp.size()].push_back(temp);
  }
  for (int i = 2; i <= n; i += 2)
    if (cycles[i].size() % 2) {
      cout << "-1\n";
      return 0;
    }
  for (int i = 1; i <= n; i++) {
    if (i % 2) {
      for (int j = 0; j < cycles[i].size(); j++)
        for (int k = 0; k < i; k++)
          P[cycles[i][j][k]] = cycles[i][j][(k + (i / 2) + 1) % i];
    } else {
      for (int j = 0; j < cycles[i].size(); j += 2)
        for (int k = 0; k < i; k++) {
          P[cycles[i][j][k]] = cycles[i][j + 1][k];
          P[cycles[i][j + 1][k]] = cycles[i][j][(k + 1) % i];
        }
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", P[i]);
  cout << endl;
  return 0;
}
