#include using namespace std; #define all(x) (x).begin(), (x).end() vector solve(vector &A, int P, int Q) { int N = A.size(); vector B = A, A_i(N + 1); for(int i = 0; i < N; i++) { A_i[A[i]] = i; } bool p = false, q = false; set S; for(int i = N - 1; i >= 0; i--) { p |= A[i] == P; q |= A[i] == Q; if (((A_i[P] < A_i[Q] && A_i[Q] < i) || ((!p) && q)) && S.lower_bound(A[i]) != S.end()) { int m = *S.lower_bound(A[i]); swap(B[i], B[A_i[m]]); sort(B.begin() + i + 1, B.end()); break; } if (p && q && S.lower_bound(A[i]) != S.end()) { int m = *S.lower_bound(A[i]); if (m == Q) { if (next(S.lower_bound(A[i]), 1) == S.end()) { S.insert(A[i]); continue; } m = *next(S.lower_bound(A[i]), 1); } swap(B[i], B[A_i[m]]); sort(B.begin() + i + 1, B.end()); if (P > Q && m != P) { auto p_it = find(all(B), P); auto q_it = find(all(B), Q); rotate(q_it, q_it + 1, p_it + 1); } break; } S.insert(A[i]); } return B; } void validate(vector &A, vector &B, int P, int Q) { int N = A.size(); assert(N >= 2 && N <= 100000); assert(P >= 1 && P <= N && Q >= 1 && Q <= N); assert(P != Q); vector A_i(N + 1, -1); for(int i = 0; i < N; i++) { assert(A_i[A[i]] == -1); A_i[A[i]] = i; } assert(A.size() == B.size() && B.size() >= 2); if (A == B) return; assert(A < B); vector B_i(N + 1, -1); for(int i = 0; i < N; i++) { assert(B_i[B[i]] == -1); B_i[B[i]] = i; } assert(B_i[P] < B_i[Q]); } int main() { int N, P, Q; cin >> N >> P >> Q; vector A(N); for(int i = 0; i < N; i++) { cin >> A[i]; } vector B = solve(A, P, Q); validate(A, B, P, Q); if (A == B) { cout << -1 << endl; } else { for(int i = 0; i < N; i++) { cout << B[i]; if (i != N - 1) cout << " "; else cout << endl; } } return 0; }