#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int p[n + 1];
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  int visited[n + 1];
  memset(visited, 0, sizeof(visited));
  vector<vector<int> > cycles;
  vector<pair<int, int> > sortedCycles;
  for (int i = 1; i <= n; ++i) {
    int x = p[i];
    if (visited[x]) continue;
    vector<int> v;
    while (!visited[x]) {
      v.push_back(x);
      visited[x] = 1;
      x = p[x];
    }
    cycles.push_back(v);
    sortedCycles.emplace_back(v.size(), cycles.size() - 1);
  }
  sort(sortedCycles.begin(), sortedCycles.end());
  int q[n + 1];
  memset(q, 0, sizeof(q));
  for (int i = 0; i < sortedCycles.size(); ++i) {
    if (sortedCycles[i].first % 2 == 1) {
      vector<int> v = cycles[sortedCycles[i].second];
      int sz = v.size();
      int add = sz / 2 + 1;
      for (int j = 0; j < sz; ++j) {
        v.push_back(v[j]);
        q[v[j]] = v[j + add];
      }
    } else {
      if (i == sortedCycles.size() - 1 ||
          sortedCycles[i].first != sortedCycles[i + 1].first) {
        return cout << -1 << endl, 0;
      }
      vector<int> v1 = cycles[sortedCycles[i].second];
      i++;
      vector<int> v2 = cycles[sortedCycles[i].second];
      for (int j = 0; j < v1.size(); ++j) {
        q[v1[j]] = v2[j];
        q[v2[j]] = p[v1[j]];
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << q[i] << " ";
  }
}
