A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. For example, the square of q = [4, 5, 1, 2, 3] is p = q2 = [2, 3, 4, 5, 1].

This problem is about the inverse operation: given the permutation p you task is to find such permutation q that q2 = p. If there are several such q find any of them.

Input

The first line contains integer n (1 ≤ n ≤ 106) — the number of elements in permutation p.

The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the elements of permutation p.

Output

If there is no permutation q such that q2 = p print the number "-1".

If the answer exists print it. The only line should contain n different integers qi (1 ≤ qi ≤ n) — the elements of the permutation q. If there are several solutions print any of them.

Examples

Input

4
2 1 4 3


Output

3 4 2 1


Input

4
2 1 3 4


Output

-1


Input

5
2 3 4 5 1


Output

4 5 1 2 3
#include <bits/stdc++.h>
using std::vector;
using Permutation = vector<size_t>;
using Cycle = vector<size_t>;
Permutation ReadInput();
void WriteAns(const Permutation& sqrt);
void WriteError();
Permutation Sqrt(const Permutation& p);
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  try {
    auto input = ReadInput();
    auto result = Sqrt(input);
    WriteAns(result);
  } catch (...) {
    WriteError();
  }
  return 0;
}
vector<Cycle> Divide(const Permutation& permutation);
Permutation Unit(const vector<Cycle>& cycles, size_t length);
Cycle OddSqrt(const Cycle& cycle);
Cycle EvenSqrt(const Cycle& cycle_first, const Cycle& cycle_second);
Permutation Sqrt(const Permutation& permutation) {
  const vector<Cycle> cycles = Divide(permutation);
  size_t length = permutation.size();
  vector<vector<Cycle>> cycles_by_len(length + 1);
  for (auto cycle : cycles) {
    cycles_by_len[cycle.size()].push_back(cycle);
  }
  vector<Cycle> sqrt_cycles;
  for (size_t i = 1; i <= length; ++i) {
    if (i % 2 != 0) {
      for (auto elem : cycles_by_len[i]) {
        sqrt_cycles.push_back(OddSqrt(elem));
      }
    } else {
      if (cycles_by_len[i].size() % 2 != 0) {
        throw 1;
      }
      for (size_t pos_1 = 0, pos_2 = 1; pos_2 < cycles_by_len[i].size();
           pos_1 += 2, pos_2 += 2) {
        sqrt_cycles.push_back(
            EvenSqrt(cycles_by_len[i][pos_1], cycles_by_len[i][pos_2]));
      }
    }
  }
  Permutation sqrt = Unit(sqrt_cycles, length);
  return sqrt;
}
vector<Cycle> Divide(const Permutation& permutation) {
  vector<bool> used(permutation.size(), false);
  vector<Cycle> cycles;
  size_t length = permutation.size();
  for (size_t node = 0; node < length; ++node) {
    if (!used[node]) {
      Cycle cycle;
      for (size_t cycle_node = node; !used[cycle_node];
           used[cycle_node] = true, cycle_node = permutation[cycle_node]) {
        cycle.push_back(cycle_node);
      }
      cycles.push_back(cycle);
    }
  }
  return cycles;
}
Cycle OddSqrt(const Cycle& cycle) {
  size_t length = cycle.size();
  Cycle sqrt;
  for (size_t fst = 0, snd = (length + 1) / 2; sqrt.size() < length;
       ++fst, ++snd) {
    if (fst < length) {
      sqrt.push_back(cycle[fst]);
    }
    if (snd < length) {
      sqrt.push_back(cycle[snd]);
    }
  }
  return sqrt;
}
Cycle EvenSqrt(const Cycle& cycle_first, const Cycle& cycle_second) {
  Cycle cycle;
  for (size_t i = 0; i < cycle_first.size(); ++i) {
    cycle.push_back(cycle_first[i]);
    cycle.push_back(cycle_second[i]);
  }
  return cycle;
}
Permutation Unit(const vector<Cycle>& cycles, size_t length) {
  Permutation permutation(length);
  for (auto cycle : cycles) {
    for (size_t i = 0, j = 1 % cycle.size(); i < cycle.size();
         ++i, j = (j + 1) % cycle.size()) {
      permutation[cycle[i]] = cycle[j];
    }
  }
  return permutation;
}
Permutation ReadInput() {
  size_t perm_size;
  std::cin >> perm_size;
  Permutation permutation(perm_size);
  for (auto& elem : permutation) {
    std::cin >> elem;
    --elem;
  }
  return permutation;
}
void WriteAns(const Permutation& sqrt) {
  for (auto elem : sqrt) {
    std::cout << elem + 1 << ' ';
  }
}
void WriteError() { std::cout << -1; }
