def Next_Permutation(perm,inplace=False): N=len(perm) b=N-1 while b and perm[b-1]>perm[b]: b-=1 if b==0: return None i=max(i for i in range(b,N) if perm[i]>perm[b-1]) if inplace: queue=perm[i:i+1]+perm[:i:-1]+perm[b-1:b]+perm[i-1:b-1:-1] while b-1perm[b-1]) return perm[:b-1]+perm[i:i+1]+perm[:i:-1]+perm[b-1:b]+perm[i-1:b-1:-1] N,P,Q=map(int,input().split()) A=list(map(int,input().split())) if A==sorted(A,reverse=True): print(-1) exit() A=Next_Permutation(A) if A.index(P)A[i+1] for i in range(A.index(Q))): print(-1) exit() inf=1<<30 dp=A[:] dp[A.index(Q)]=-inf for i in range(N-2,-1,-1): dp[i]=max(dp[i],dp[i+1]) idx=[i for i in range(A.index(Q)) if dp[i]>A[i]] if not idx: print(-1) exit() i=max(idx) B=A[:i] BB=A[i:] BB.sort() b=min(b for b in BB if b>A[i] and b!=Q) B.append(b) for bb in BB: if b==bb: continue B.append(bb) print(*B)