#include #include using namespace std; int N, P, Q, A[200200], p, q; bool C[200200]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N >> P >> Q; for (int i = 0; i < N; i++) cin >> A[i]; for (int k = 0; next_permutation(A, A + N); k++){ p = find(A, A + N, P) - A; q = find(A, A + N, Q) - A; if (p < q){ for (int i = 0; i < N; i++) printf ("%d ", A[i]); return 0; } if (k){ for (int i = 0; i < p; i++) if (i != q) printf ("%d ", A[i]); printf ("%d %d ", P, Q); for (int i = p + 1; i < N; i++) printf ("%d ", A[i]); return 0; } else{ int u = *max_element(A + q + 1, A + N), w = Q; if (Q > u){ for (q--; q >= 0; q--){ if (w < A[q]) w = A[q]; else if (u < A[q] && A[q] < Q) u = A[q]; else break; } } for (int i = q + 1; i < N; i++) C[A[i]] = 1; for (int i = 1, j = q; i <= N; i++) if (C[i]) A[++j] = i; reverse(A + q + 1, A + N); } } puts("-1"); return 0; }