import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } if (arr[0] > arr[n - 1]) { System.out.println("No"); return; } ArrayList list = new ArrayList<>(); for (int i = 1; i < n - 1; i++) { if (arr[i] > arr[0]) { list.add(arr[i]); arr[i] = Integer.MAX_VALUE; } } for (int i = n - 2; i > 0; i--) { if (arr[i] < arr[n - 1]) { list.add(arr[i]); } } list.add(arr[0]); StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.size(); i++) { if (i > 0) { sb.append(" "); } sb.append(list.get(i)); } System.out.println(sb); } }