#include #include #include using namespace std; template class MaxFlowGraph{ private: struct Edge{ int to; T cap; int rev; }; using graph = vector>; //graph G; vector used; public: graph G; MaxFlowGraph(int n){ G = graph(n); used = vector(n, false); } void add_edge(int from, int to, T cap){ G[from].push_back({to, cap, (int)G[to].size()}); G[to].push_back({from, 0, (int)G[from].size()-1}); } T dfs(int v, int t, T f){ if(v == t) return f; used[v] = true; for(int i = 0; i < G[v].size(); i++){ auto &e = G[v][i]; if(used[e.to] || e.cap == 0) continue; T d = dfs(e.to, t, min(f, e.cap)); if(d > 0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } return 0; } T flow(int s, int t){ T maxflow = 0; while(true){ fill(used.begin(), used.end(), false); T INF = 1001001001; T f = dfs(s, t, INF); if(f == 0) return maxflow; else maxflow += f; } } }; int main(){ int n; cin >> n; vector a(n); for(auto &p: a) cin >> p; MaxFlowGraph G(n*2+2); const int s = n*2; const int t = n*2+1; for(int i = 0; i < n; i++) G.add_edge(n+i, t, 1); for(int i = 0; i < n; i++){ G.add_edge(s, i, 1); for(int j = 0; j < n; j++){ if(a[i] != j) G.add_edge(i, n+j, 1); } } if(G.flow(s, t) != n){ cout << -1 << endl; }else{ for(int i = 0; i < n; i++){ for(auto &p: G.G[i]){ if(p.cap == 0){ cout << p.to-n << endl; break; } } } } return 0; }