import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.TreeSet; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int p = Integer.parseInt(sa[1]); int q = Integer.parseInt(sa[2]); sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } br.close(); a = next(a); if (a == null) { System.out.println(-1); return; } int pi = 0; int qi = 0; for (int i = 0; i < n; i++) { if (a[i] == p) { pi = i; } if (a[i] == q) { qi = i; } } if (pi > qi) { if (q == n) { qi--; } if (qi == -1) { System.out.println(-1); return; } TreeSet set = new TreeSet<>(); set.add(a[n - 1]); for (int i = a.length - 2; i >= qi; i--) { set.add(a[i]); } while (set.higher(a[qi]) == null || set.higher(a[qi]) == q) { qi--; if (qi < 0) { System.out.println(-1); return; } set.add(a[qi]); } int[] b = new int[n]; for (int i = 0; i < qi; i++) { b[i] = a[i]; } b[qi] = set.higher(a[qi]); set.remove(b[qi]); set.add(a[qi]); boolean flg = b[qi] == p; while (!set.isEmpty()) { qi++; int o = set.pollFirst(); if (!flg && o == q) { int o2 = set.pollFirst(); b[qi] = o2; set.add(o); if (o2 == p) { flg = true; } } else { b[qi] = o; if (o == p) { flg = true; } } } a = b; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(a[i]).append(' '); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb.toString()); } static int[] next(int[] a) { TreeSet set = new TreeSet<>(); set.add(a[a.length - 1]); for (int i = a.length - 2; i >= 0; i--) { if (a[i] > a[i + 1] || set.higher(a[i]) == null) { set.add(a[i]); } else { int[] b = new int[a.length]; for (int j = 0; j < i; j++) { b[j] = a[j]; } b[i] = set.higher(a[i]); set.remove(b[i]); set.add(a[i]); Integer[] arr = set.toArray(new Integer[0]); for (int j = 0; j < arr.length; j++) { b[i + 1 + j] = arr[j]; } return b; } } return null; } }