#include #include #include #include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x) using namespace std; int main() { int n; cin >> n; vector a(n); repeat (i,n) cin >> a[i]; if (whole(count, a, a[0]) == n) { cout << -1 << endl; // all a_i is the same } else { vector b(n); whole(iota, b, 0); set c; repeat (i,n) if (a[i] == b[i]) c.insert(i); default_random_engine gen((random_device())()); uniform_int_distribution dist(0, n-1); while (not c.empty()) { int i = *c.begin(); int j = i; while (j == i) j = dist(gen); swap(b[i], b[j]); c.erase(i); c.erase(j); if (a[i] == b[i]) c.insert(i); if (a[j] == b[j]) c.insert(j); } for (int it : b) cout << it << endl; } return 0; }