#include using namespace std; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout< st; rep (i, n) { if (i != q) st.insert(i); } bool big = false; rep (i, n) { if (not big) { auto itr = st.end(); if (itr == st.begin()) return false; itr--; int x = *itr; if (x > a[i]) { big = true; st.erase(x); } else if (x == a[i]) { st.erase(x); } else { return false; } if (x == p) st.insert(q); } else { auto itr = st.end(); if (itr == st.begin()) return false; itr--; int x = *itr; st.erase(x); if (x == p) st.insert(q); } } if (not big) return false; return true; } vi b; bool check(int mid) { set st; rep (i, n) { if (i != q) st.insert(i); } rep (i, mid) { if (st.count(a[i]) == 0) { return false; } st.erase(a[i]); b[i] = a[i]; if (a[i] == p) st.insert(q); } bool big = false; for (int i = mid; i < n; i++) { if (not big) { auto itr = st.end(); if (itr == st.begin()) { return false; } itr--; if (*itr < a[i]) { return false; } bool flag = false; if (*itr != a[i]) { itr = st.lower_bound(a[i] + 1); flag = true; } if (flag and itr != st.end()) { int x = *itr; st.erase(itr); assert(x > a[i]); b[i] = x; if (x == p) st.insert(q); big = true; } else { int x = a[i]; st.erase(x); b[i] = x; if (x == p) st.insert(q); } } else { auto itr = st.begin(); int x = *itr; st.erase(itr); b[i] = x; if (x == p) st.insert(q); } } if (not big) return false; return true; } signed main() { scanf("%d %d %d", &n, &p, &q); p--; q--; a.resize(n); b.resize(n); rep (i, n) { scanf("%d", &a[i]); a[i]--; } if (not check1()) { cout << -1 << endl; return 0; } int ok = 0, ng = n; set st; rep (i, n) { if (i != q) st.insert(i); } rep (i, n) { auto itr = st.lower_bound(a[i] + 1); if (itr != st.end()) { ok = i; DEBUG(ok); } if (st.count(a[i]) == 0) break; st.erase(a[i]); if (a[i] == p) st.insert(q); } // while (ok + 1 < ng) { // int mid = (ok + ng) / 2; // if (not check(mid)) ng = mid; // else ok = mid; // } check(ok); rep (i, n) { cout << b[i] + 1 << " "; } cout << endl; }