#include #include using namespace std; int N, P, Q, A[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++){ int p, q; 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 r = N - 1; while (A[q] > A[r]) r--; sort(A + min(q, r) + 1, A + N); reverse(A + min(q, r) + 1, A + N); } } puts("-1"); return 0; }