#include <bits/stdc++.h>
using namespace std;
const int mxk = 1e6 + 7;
long long n, a[mxk], p[mxk];
int siz[mxk], col[mxk], head[mxk], cnt = 0;
bool vis[mxk];
int tot[mxk], dt[mxk], nxt[mxk];
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  col[u] = cnt;
  ++siz[cnt];
  head[cnt] = u;
  dfs(a[u]);
}
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) ++cnt, dfs(i);
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= cnt; ++i) {
    if (siz[i] & 1) {
      int tmp = head[i];
      for (int k = 1; k <= (siz[i] + 1) / 2; tmp = a[tmp], ++k)
        ;
      for (int u = head[i]; !vis[u]; u = a[u], tmp = a[tmp])
        p[u] = tmp, vis[u] = 1;
      siz[i] = 0;
      head[i] = -1;
    }
  }
  for (int i = 1; i <= n; ++i)
    ++tot[siz[i]], nxt[i] = dt[siz[i]], dt[siz[i]] = i;
  for (int i = 1; i <= n; ++i) {
    if (tot[i] > 0) {
      if (tot[i] & 1) {
        printf("-1\n");
        return 0;
      }
      int cur = dt[i], tmp = nxt[cur];
      do {
        for (int u = head[cur], v = head[tmp]; (!vis[u]) && (!vis[v]);
             u = a[u], v = a[v]) {
          p[u] = v, p[v] = a[u];
          vis[u] = vis[v] = 1;
        }
        cur = nxt[tmp], tmp = nxt[cur];
      } while (cur != 0);
    }
  }
  for (int i = 1; i <= n; ++i) printf("%lld ", p[i]);
  printf("\n");
  return 0;
}
