#include <cstdio>
#include <cctype>
#include <cstring>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 1000010
int readint()
{
int x = 0, c;
while (!isdigit(c = getchar()));
do
x = x * 10 + c - '0';
while (isdigit(c = getchar()));
return x;
}
int n;
int ff[MAXN], f[MAXN];
bool vis[MAXN];
vector<int> round[MAXN];
int cnt;
int temp[MAXN];
int times[MAXN];
inline void work(int st)
{
while (!vis[st])
{
vis[st] = 1;
round[cnt].push_back(st);
st = ff[st];
}
cnt++;
}
stack<char> put;
inline void printint(int x)
{
while (x)
{
put.push((x % 10) + '0');
x /= 10;
}
while (!put.empty())
{
putchar(put.top());
put.pop();
}
}
int main()
{
freopen("deepdarkfantasy.in", "r", stdin);
freopen("deepdarkfantasy.out", "w", stdout);
n = readint();
for (int i = 1; i <= n; i++)
{
int x = readint();
ff[x] = i;
}
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n; i++)
if(!vis[i])
work(i);
for (int i = 0; i < cnt; i++)
times[(int)round[i].size()]++;
for (int i = 1; i <= n; i++)
times[i] += times[i - 1];
for (int i = 0; i < n; i++)
temp[--times[(int)round[i].size()]] = i;
memset(vis, 0, sizeof(vis));
for (int i = 0; i < cnt; i++)
{
int sz = (int)round[temp[i]].size();
if (sz & 1)
{
for (int j = 0; j < sz; j++)
f[round[temp[i]][j]] = round[temp[i]][(j + (sz + 1) / 2) % sz];
}
else
{
if (vis[temp[i]])
continue;
if (i >= cnt - 1 || sz != (int)round[temp[i + 1]].size())
{
printf("-1\n");
return 0;
}
int t = temp[i + 1];
for (int j = 0; j < sz; j++)
f[round[temp[i]][j]] = round[t][j], f[round[t][j]] = round[temp[i]][(j + 1) % sz];
vis[temp[i + 1]] = true;
}
}
for (int i = 1; i <= n; i++)
{
printint(f[i]);
if (i < n)
putchar(' ');
else
putchar('\n');
}
return 0;
}