#include #include using namespace std; int N, P, Q, A[200200], p, q; bool C[200200]; int main() { scanf ("%d %d %d", &N, &P, &Q); for (int i = 0; i < N; i++) scanf ("%d", &A[i]); for (int k = 0; next_permutation(A, A + N); k++){ for (int i = 0; i < N; i++){ if (A[i] == P) p = i; if (A[i] == Q) q = i; } if (p < q){ for (int i = 0; i < N; i++) printf ("%d ", A[i]); return 0; } if (k){ for (int i = 0; i < q; i++) printf ("%d ", A[i]); for (int i = q + 1; i < p; i++) 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 = 0, w = Q; for (int i = q + 1; i < N; i++) u = max(u, A[i]); 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; i <= N; i++) if (C[i]) A[++q] = i; reverse(A + q + 1, A + N); } } puts("-1"); return 0; }