#include using namespace std; //#include //using multiInt = boost::multiprecision::cpp_int; using ll = long long int; using ld = long double; using pii = pair; using pll = pair; template using smaller_queue = priority_queue, greater>; const int MOD_TYPE = 1; const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); const int INF = (int)1e9; const ll LINF = (ll)4e18; const ld PI = acos(-1.0); const ld EPS = 1e-11; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl #define possible(n) cout << ((n) ? "possible" : "impossible") << endl #define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << endl; vector Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0}; vector Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0}; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); int n, p, q; cin >> n >> p >> q; vector a(n); rep(i, n) cin >> a[i]; int Max1[100010], Max2[100010]; Max1[n] = -1, Max2[n] = -2; for (int i = n; i > 0; i--) { int t = a[i - 1]; if (t > Max1[i]) { Max1[i - 1] = t; Max2[i - 1] = Max1[i]; } else if (t > Max2[i]) { Max1[i - 1] = Max1[i]; Max2[i - 1] = t; } else { Max1[i - 1] = Max1[i]; Max2[i - 1] = Max2[i]; } } //条件を満たす順列Bで、先頭i文字が一致し、a[i]!=b[i]となるものがあるか int match = -1; bool used_p = false; rep(i, n) { if (used_p) { if (Max1[i] > a[i]) match = i; } else { if ((Max1[i] > a[i] && Max1[i] != q) || Max2[i] > a[i]) match = i; } if (a[i] == p) used_p = true; else if (a[i] == q && !used_p) break; } dbg(match); if (match == -1) { cout << -1 << endl; return 0; } vector b(n); rep(i, n) b[i] = a[i]; used_p = false; rep(i, match) { if (a[i] == p) { used_p = true; break; } } if (used_p) { cerr << 1 << endl; rep(i, n) b[i] = a[i]; int m = INF, mi; REP(i, match + 1, n) { if (a[match] < a[i] && a[i] < m) { m = min(m, a[i]); mi = i; } } swap(b[match], b[mi]); sort(b.begin() + match + 1, b.end()); } else { cerr << 2 << endl; int m = INF, mi; REP(i, match + 1, n) { if (a[match] < a[i] && a[i] != q && a[i] < m) { m = min(m, a[i]); mi = i; } } swap(b[match], b[mi]); sort(b.begin() + match + 1, b.end()); if (p > q && m != p) { cerr << "2+" << endl; int p_pos, q_pos; REP(i, match + 1, n) { if (b[i] == p) p_pos = i; else if (b[i] == q) q_pos = i; } assert(q_pos < p_pos); rotate(b.begin() + q_pos, b.begin() + q_pos + 1, b.begin() + p_pos + 1); } } rep(i, n) cout << b[i] << (i == n - 1 ? "\n" : " "); //----------debug---------- assert(a < b); int p_pos, q_pos; rep(i, n) { if (b[i] == p) p_pos = i; else if (b[i] == q) q_pos = i; } assert(p_pos < q_pos); prev_permutation(all(b)); rep(i, n) { if (b[i] == p) p_pos = i; else if (b[i] == q) q_pos = i; } assert(p_pos > q_pos || a == b); return 0; }