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* = *q*<sup class="upper-index">2</sup> = [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 *q*<sup class="upper-index">2</sup> = *p*. If there are several such *q* find any of them.
The first line contains integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">6</sup>) — the number of elements in permutation *p*.

The second line contains *n* distinct integers *p*<sub class="lower-index">1</sub>, *p*<sub class="lower-index">2</sub>, ..., *p*<sub class="lower-index">*n*</sub> (1 ≤ *p*<sub class="lower-index">*i*</sub> ≤ *n*) — the elements of permutation *p*.
none
4
2 1 4 3
3 4 2 1
4
2 1 3 4
-1
5
2 3 4 5 1
4 5 1 2 3
1
1
1
1
1
1
10
8 2 10 3 4 6 1 7 9 5
-1
10
3 5 1 2 10 8 7 6 4 9
6 9 8 10 4 3 7 1 5 2
100
11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 81 52 87 83 73 44 49 23 82 85 75 86 33 47 19 58 97 37 20 40 10 92 4 6 68 77 54 71 12 62 60 100 39 41 99 72 29 57 8 70 32 66 98
-1
100
94 22 24 99 58 97 20 29 67 30 38 64 77 50 15 44 92 88 39 42 25 70 2 76 84 6 37 49 17 71 31 19 26 79 10 35 65 63 32 95 5 8 52 27 83 18 53 93 13 81 48 68 54 82 34 60 87 23 16 86 55 40 61 45 28 7 74 41 14 91 3 72 33 11 98 89 90 69 78 36 80 59 56 21 43 1 75 46 47 12 96 73 57 51 4 85 9 100 66 62
78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 32 54 84 68 43 4 21 28 73 6 16 62 31 39 65 86 98 75 33 45 19 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 72 37 12 35 99 67 94 1 87 57 8 61 25 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30
import os
from re import M
import sys 
from io import BytesIO, IOBase
 
BUFSIZE = 8192
  
class FastIO(IOBase):
    newlines = 0
  
    def __init__(self, file):
        self._fd = file.fileno() 
        self.buffer = BytesIO()  
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break  
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0 
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) 
            self.newlines = b.count(b"\n") + (not b)  
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1    
        return self.buffer.readline()
 
    def flush(self): 
        if self.writable: 
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)   
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def solve():
    n = int(input())
    P = list(map(int, input().split()))
    P = [p - 1 for p in P]
    Q = [-1] * n
    size = {}
    used = [False] * n
    for i in range(n):
        if used[i]:
            continue
        lst = []
        while not used[i]:
            used[i] = True
            lst.append(i)
            i = P[i]
        le = len(lst)
        if le & 1:
            c = (le + 1) // 2
            for i in range(le):
                Q[lst[i]] = lst[(i + c) % le]
        elif le not in size:
            size[le] = lst
        else:
            lst2 = size[le]
            del size[le]
            lst.append(lst[0])
            for i in range(le):
                Q[lst[i]] = lst2[i]
                Q[lst2[i]] = lst[i + 1]
    if -1 in Q:
        print(-1)
    else:
        Q = [q + 1 for q in Q]
        print(*Q)

        




    
for _ in range(1):
    solve()   
    