#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #pragma warning(disable:4996) typedef long long ll; typedef unsigned long long ull; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; bool solve0(int n, int p, int q, vector& a) { next_permutation(a.begin(), a.end()); int flag=0, idp = -1, idq = -1; int i; for (i = 0; i < n; i++) { if (a[i] != i) flag = 1; if (a[i] == p) idp = i; if (a[i] == q) idq = i; } if (flag == 0) { return false; } if (idp < idq) { return true; } set z; for (i = idq+1; i < n; i++) { z.insert(a[i]); } int curr = idq; while (1) { if (curr < 0) { return false; } auto it = z.rbegin(); if (*it > idq) { break; } z.insert(a[curr]); curr--; } for (i = curr + 1; i < n; i++) { auto it=z.rbegin(); a[i] = *it; z.erase(*it); } bool ok = solve0(n, p, q, a); return ok; } void solve() { int n, p, q; scanf("%d%d%d", &n, &p, &q); p--; q--; vector a(n); int i; for (i = 0; i < n; i++) { scanf("%d", &a[i]); a[i]--; } bool ok = solve0(n, p, q, a); if (!ok) { printf("-1\n"); return; } for (i = 0; i < n; i++) { printf("%d", a[i]+1); if (i < n - 1) printf(" "); else printf("\n"); } return; } int main(int argc, char* argv[]) { #if 1 solve(); #else int T; scanf("%d", &T); int t; for(t=0; t