#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define inf 0x3f3f3f3f #define INF INT_MAX/3 #define PB push_back #define MP make_pair #define ALL(a) (a).begin(),(a).end() #define SET(a,c) memset(a,c,sizeof a) #define CLR(a) memset(a,0,sizeof a) #define pii pair #define pcc pair #define pic pair #define pci pair #define VS vector #define VI vector #define DEBUG(x) cout<<#x<<": "<b?b:a) #define MAX(a,b) (a>b?a:b) #define pi 2*acos(0.0) #define INFILE() freopen("in0.txt","r",stdin) #define OUTFILE()freopen("out0.txt","w",stdout) #define in scanf #define out printf #define ll long long #define ull unsigned long long #define eps 1e-14 #define FST first #define SEC second class MaxFlow { struct Edge { int to, cap, rev; Edge(int t, int c, int r) :to(t), cap(c), rev(r){} }; public: vector > G; vector used; MaxFlow(int MAX_V) :G(MAX_V), used(MAX_V) {} void add_edge(int from, int to, int cap) { G[from].push_back(Edge(to,cap,G[to].size())); G[to].push_back(Edge(from, 0, G[from].size() - 1)); } int dfs(int v,int t,int f) { if (v == t) return f; used[v] = true; for (int i = 0; i < G[v].size(); ++i) { Edge &e = G[v][i]; if (!used[e.to] and e.cap>0) { int 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; } int max_flow(int s, int t) { int flow = 0; while (true) { fill(ALL(used), false); int f = dfs(s, t, 0x3f3f3f3f); if(f == 0) return flow; flow += f; } } }; int main() { int N; cin >> N; vector A(N); for (auto &a : A) cin >> a; MaxFlow flow(2 * N + 3); REP(i, N) { flow.add_edge(0, i + 1, 1); for (int j = 0; j < N; ++j) if(A[i] != j) flow.add_edge(i + 1, N + j + 1, 1); flow.add_edge(N + i + 1, 2 * N+2 , 1); } int cnt = flow.max_flow(0, 2 * N + 2); if (cnt < N) { cout << -1 << endl; return 0; } REP(i, N) { int res = -1; for (auto e: flow.G[i + 1]) { if (e.to >= N + 1 and e.to < 2 * N + 1 and e.cap == 0) { cout << e.to - N - 1 << endl; break; } } } return 0; }