#include <bits/stdc++.h>
using namespace std;
int n, x[100005 * 10];
bool v[100005 * 10];
vector<pair<int, vector<int> > > y;
void go(int a) {
  if (v[a]) return;
  v[a] = 1;
  y.back().second.push_back(a);
  go(x[a]);
}
int main() {
  scanf("%d", &n);
  for (int a = 1; a <= n; a++) scanf("%d", &x[a]);
  for (int a = 1; a <= n; a++)
    if (!v[a]) {
      y.push_back(make_pair(0, vector<int>()));
      go(a);
    }
  for (int a = 0; a < y.size(); a++) {
    y[a].first = y[a].second.size();
    y[a].second.push_back(y[a].second[0]);
  }
  sort(y.begin(), y.end());
  x[0] = y.size();
  y.push_back(make_pair(0, vector<int>()));
  for (int a = 0; a < x[0]; a++) {
    if (y[a].first & 1) {
      for (int b = 0; b < y[a].first; b++) {
        x[y[a].second[b]] = y[a].second[(b + y[a].first / 2 + 1) % y[a].first];
      }
    } else {
      if (y[a].first == y[a + 1].first) {
        for (int b = 0; b < y[a].first; b++) {
          x[y[a].second[b]] = y[a + 1].second[b];
          x[y[a + 1].second[b]] = y[a].second[b + 1];
        }
        a++;
      } else {
        printf("-1\n");
        return 0;
      }
    }
  }
  for (int a = 1; a <= n; a++) printf("%d%c", x[a], a == n ? '\n' : ' ');
  return 0;
}
