#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-10;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
template <class T>
inline T sq(T a) {
  return a * a;
}
const int MAX_N = 1000010;
int n;
int a[MAX_N];
bool used[MAX_N];
bool pooling[MAX_N];
vector<int> ss[MAX_N];
int ans[MAX_N];
vector<int> split(int x) {
  vector<int> res = {x};
  int cur = a[x];
  while (cur != x) {
    res.emplace_back(cur);
    cur = a[cur];
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (long long int i = (0); i < (long long int)(n); i++)
    scanf("%d", &a[i]), a[i]--;
  for (long long int i = (0); i < (long long int)(n); i++)
    if (!used[i]) {
      vector<int> res = split(i);
      for (auto &w : res) used[w] = true;
      int m = ((long long int)(res).size());
      if (m % 2 == 1) {
        for (long long int i = (0); i < (long long int)(m / 2); i++) {
          ans[res[i]] = res[i + m / 2 + 1];
          ans[res[i + m / 2 + 1]] = res[i + 1];
        }
        ans[res[m / 2]] = res[0];
      } else {
        if (!pooling[m]) {
          pooling[m] = true;
          ss[m] = res;
        } else {
          for (long long int i = (0); i < (long long int)(m); i++)
            ans[res[i]] = ss[m][i], ans[ss[m][i]] = res[(i + 1) % m];
          pooling[m] = false;
        }
      }
    }
  for (long long int i = (0); i < (long long int)(MAX_N); i++)
    if (pooling[i]) {
      puts("-1");
      return 0;
    }
  for (long long int i = (0); i < (long long int)(n); i++)
    printf("%d%c", ans[i] + 1, i == n - 1 ? '\n' : ' ');
  return 0;
}
