#include <bits/stdc++.h>
using std::pair;
using std::vector;
using Permutation = std::vector<size_t>;
using Cycle = std::vector<size_t>;
Permutation ReadInput(std::istream& in_stream = std::cin);
void WriteError(std::ostream& out_stream = std::cout);
void WriteAnswer(const Permutation& permutation,
                 std::ostream& out_stream = std::cout);
Permutation Sqrt(const Permutation& permutation);
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  try {
    auto input = ReadInput();
    auto result = Sqrt(input);
    WriteAnswer(result);
  } catch (...) {
    WriteError();
  }
  return 0;
}
Cycle CycleByNode(size_t node, vector<bool>* looked,
                  const Permutation& permutation);
Permutation Sqrt(const Permutation& permutation) {
  vector<bool> looked(permutation.size(), false);
  std::multimap<size_t, Cycle> cycle_by_len;
  for (size_t node = 0; node < permutation.size(); ++node) {
    if (!looked[node]) {
      Cycle cycle = CycleByNode(node, &looked, permutation);
      cycle_by_len.insert({cycle.size(), cycle});
    }
  }
  for (size_t cycle_size = 0; cycle_size <= permutation.size();
       cycle_size += 2) {
    if (cycle_by_len.count(cycle_size) % 2 == 1) {
      throw std::exception();
    }
  }
  std::vector<Cycle> cycles;
  for (size_t cycle_size = 1; cycle_size <= permutation.size();
       cycle_size += 2) {
    auto range = cycle_by_len.equal_range(cycle_size);
    for (auto it = range.first; it != range.second; ++it) {
      Cycle cycle;
      for (size_t i = 0; i != 0 || cycle.empty();
           i = (i + (cycle_size + 1) / 2) % cycle_size) {
        cycle.push_back(it->second[i]);
      }
      cycles.push_back(cycle);
    }
  }
  for (size_t cycle_size = 0; cycle_size <= permutation.size();
       cycle_size += 2) {
    auto range = cycle_by_len.equal_range(cycle_size);
    if (range.first != range.second) {
      for (auto fst = range.first, snd = ++range.first;
           fst != range.second && snd != range.second;
           ++fst, ((fst != range.second) ? ++fst : fst), ++snd,
                ((snd != range.second) ? ++snd : snd)) {
        cycles.push_back({});
        bool flag = true;
        auto cmp = [&flag](size_t a, size_t b) {
          flag = !flag;
          return flag;
        };
        std::merge(fst->second.begin(), fst->second.end(), snd->second.begin(),
                   snd->second.end(), std::back_inserter(cycles.back()), cmp);
      }
    }
  }
  Permutation sqrt(permutation.size());
  for (auto cycle : cycles) {
    for (auto it = cycle.begin(), next = cycle.begin() + 1;
         it != cycle.end() && next != cycle.end(); ++it, ++next) {
      sqrt[*it] = *next;
    }
    sqrt[cycle.back()] = cycle.front();
  }
  return sqrt;
}
Cycle CycleByNode(size_t node, vector<bool>* looked,
                  const Permutation& permutation) {
  Cycle cycle;
  for (; !looked->at(node); looked->at(node) = true, node = permutation[node]) {
    cycle.push_back(node);
  }
  return cycle;
}
void WriteError(std::ostream& out_stream) { out_stream << -1; }
void WriteAnswer(const Permutation& permutation, std::ostream& out_stream) {
  for (auto elem : permutation) {
    out_stream << elem + 1 << ' ';
  }
}
Permutation ReadInput(std::istream& in_stream) {
  size_t perm_size;
  in_stream >> perm_size;
  Permutation permutation(perm_size);
  for (auto& elem : permutation) {
    in_stream >> elem;
    --elem;
  }
  return permutation;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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

### Response

```cpp
#include <bits/stdc++.h>
using std::pair;
using std::vector;
using Permutation = std::vector<size_t>;
using Cycle = std::vector<size_t>;
Permutation ReadInput(std::istream& in_stream = std::cin);
void WriteError(std::ostream& out_stream = std::cout);
void WriteAnswer(const Permutation& permutation,
                 std::ostream& out_stream = std::cout);
Permutation Sqrt(const Permutation& permutation);
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  try {
    auto input = ReadInput();
    auto result = Sqrt(input);
    WriteAnswer(result);
  } catch (...) {
    WriteError();
  }
  return 0;
}
Cycle CycleByNode(size_t node, vector<bool>* looked,
                  const Permutation& permutation);
Permutation Sqrt(const Permutation& permutation) {
  vector<bool> looked(permutation.size(), false);
  std::multimap<size_t, Cycle> cycle_by_len;
  for (size_t node = 0; node < permutation.size(); ++node) {
    if (!looked[node]) {
      Cycle cycle = CycleByNode(node, &looked, permutation);
      cycle_by_len.insert({cycle.size(), cycle});
    }
  }
  for (size_t cycle_size = 0; cycle_size <= permutation.size();
       cycle_size += 2) {
    if (cycle_by_len.count(cycle_size) % 2 == 1) {
      throw std::exception();
    }
  }
  std::vector<Cycle> cycles;
  for (size_t cycle_size = 1; cycle_size <= permutation.size();
       cycle_size += 2) {
    auto range = cycle_by_len.equal_range(cycle_size);
    for (auto it = range.first; it != range.second; ++it) {
      Cycle cycle;
      for (size_t i = 0; i != 0 || cycle.empty();
           i = (i + (cycle_size + 1) / 2) % cycle_size) {
        cycle.push_back(it->second[i]);
      }
      cycles.push_back(cycle);
    }
  }
  for (size_t cycle_size = 0; cycle_size <= permutation.size();
       cycle_size += 2) {
    auto range = cycle_by_len.equal_range(cycle_size);
    if (range.first != range.second) {
      for (auto fst = range.first, snd = ++range.first;
           fst != range.second && snd != range.second;
           ++fst, ((fst != range.second) ? ++fst : fst), ++snd,
                ((snd != range.second) ? ++snd : snd)) {
        cycles.push_back({});
        bool flag = true;
        auto cmp = [&flag](size_t a, size_t b) {
          flag = !flag;
          return flag;
        };
        std::merge(fst->second.begin(), fst->second.end(), snd->second.begin(),
                   snd->second.end(), std::back_inserter(cycles.back()), cmp);
      }
    }
  }
  Permutation sqrt(permutation.size());
  for (auto cycle : cycles) {
    for (auto it = cycle.begin(), next = cycle.begin() + 1;
         it != cycle.end() && next != cycle.end(); ++it, ++next) {
      sqrt[*it] = *next;
    }
    sqrt[cycle.back()] = cycle.front();
  }
  return sqrt;
}
Cycle CycleByNode(size_t node, vector<bool>* looked,
                  const Permutation& permutation) {
  Cycle cycle;
  for (; !looked->at(node); looked->at(node) = true, node = permutation[node]) {
    cycle.push_back(node);
  }
  return cycle;
}
void WriteError(std::ostream& out_stream) { out_stream << -1; }
void WriteAnswer(const Permutation& permutation, std::ostream& out_stream) {
  for (auto elem : permutation) {
    out_stream << elem + 1 << ' ';
  }
}
Permutation ReadInput(std::istream& in_stream) {
  size_t perm_size;
  in_stream >> perm_size;
  Permutation permutation(perm_size);
  for (auto& elem : permutation) {
    in_stream >> elem;
    --elem;
  }
  return permutation;
}

```