#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]); int p, q, k = 0; while (next_permutation(A, A + N)){ for (int i = 0; i < N; i++) printf ("%d ", A[i]); puts(""); continue; 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 (is_sorted(A + q, A + N)){ 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]); puts(""); } sort(A + q + 1, A + N); reverse(A + q + 1, A + N); } puts("-1"); return 0; }