#include <bits/stdc++.h>
using namespace std;
void read(long long &x) { scanf("%lld", &x); }
void read(long long &x, long long &y) { scanf("%lld%lld", &x, &y); }
void read(long long &x, long long &y, long long &z) {
  scanf("%lld%lld%lld", &x, &y, &z);
}
void print(long long x) { printf("%lld ", x); }
void println(long long x) { printf("%lld\n", x); }
const long long N = 1000010;
long long n, a[N], len, len2, cnt[N], b[N], c[N], res[N], w[N];
void dfs(long long x, long long st) {
  w[x] = 1;
  b[++len] = x;
  if (a[x] != st) dfs(a[x], st);
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) read(a[i]);
  for (long long i = 1; i <= n; i++)
    if (!w[i]) {
      len = 0;
      dfs(i, i);
      if (len % 2 == 1) {
        for (long long j = 1; j <= len; j++) c[j] = b[j];
        rotate(c + 1, c + len / 2 + 1, c + len + 1);
        for (long long j = 1; j <= len; j++) res[b[j]] = a[c[j]];
        continue;
      }
      if (cnt[len] == 0) {
        cnt[len] = i;
        continue;
      }
      len2 = len;
      dfs(cnt[len], cnt[len]);
      for (long long j = 1; j <= len; j++) c[j] = b[j];
      rotate(c + 1, c + len2 + 1, c + len + 1);
      rotate(c + 1, c + len2, c + len2 + 1);
      for (long long j = 1; j <= len; j++) res[b[j]] = a[c[j]];
      cnt[len2] = 0;
    }
  for (long long i = 2; i <= n; i += 2)
    if (cnt[i]) {
      cout << -1;
      return 0;
    }
  for (long long i = 1; i <= n; i++) print(res[i]);
}
