#include using namespace std; using ll = long long; constexpr char newl = '\n'; bool judge(const vector& a, int p, int q) { for (int x : a) { if (x == q) return false; if (x == p) return true; } assert(false); } bool judge2(const vector& a, int q, int& hoge) { int n = a.size(); hoge = n + 1; bool res = true; for (int i = n - 1; i >= 0; i--) { if (a[i] == q) return res; if (a[i] > q) { res = false; hoge = min(hoge, a[i]); } } assert(false); } void func1(vector& a, int q, int hoge) { int n = a.size(); int idx = -1; for (int i = n - 1; i >= 0; --i) { if (a[i] == q) { a[i] = hoge; idx = i; } else if (a[i] == hoge) a[i] = q; } sort(a.begin() + idx + 1, a.end()); } void func2(vector& a, int p, int q) { int n = a.size(); for (int i = 0; i < n; i++) { if (a[i] == q) { assert(i + 1 < n); swap(a[i], a[i + 1]); if (a[i] == p) return; } } } int func3(const vector& a, int q) { int n = a.size(); int idx = -1; for (int i = 0; i < n; ++i) { if (a[i] == q) return idx; if (a[i] < q) idx = i; } return idx; } void print(const vector& a) { int n = a.size(); for (int i = 0; i < n; i++) { cout << a[i] << " \n"[i + 1 == n]; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, p, q; cin >> n >> p >> q; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector aa = a; sort(aa.begin(), aa.end(), greater<>()); if (a == aa) { cout << -1 << newl; return 0; } next_permutation(a.begin(), a.end()); if (judge(a, p, q)) { print(a); return 0; } int hoge; if (!judge2(a, q, hoge)) { func1(a, q, hoge); if (judge(a, p, q)) { print(a); return 0; } func2(a, p, q); if (judge(a, p, q)) { print(a); return 0; } else { cout << -1 << newl; return 0; } } else { int idx = func3(a, q); if (idx == -1) { cout << -1 << newl; return 0; } if (!judge2(a, a[idx], hoge)) { func1(a, a[idx], hoge); if (judge(a, p, q)) { print(a); return 0; } else { cout << -1 << newl; return 0; } } else { cout << -1 << newl; return 0; } } return 0; }