import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];
        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
            queue.add(value);
        }

        for (int i = 0; i < n; i++) {
            if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            }
        }
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];
        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
            queue.add(value);
        }

        for (int i = 0; i < n; i++) {
            if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            }
        }
    }
} Main public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];
        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
            queue.add(value);
        }

        for (int i = 0; i < n; i++) {
            if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            }
        }
    } main {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];
        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
            queue.add(value);
        }

        for (int i = 0; i < n; i++) {
            if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] list = new int[n]; list new int[n] n PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder()); queue new PriorityQueue<>(Comparator.reverseOrder()) for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
            queue.add(value);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int value = sc.nextInt();
            list[i] = value;
            queue.add(value);
        } {
            int value = sc.nextInt();
            list[i] = value;
            queue.add(value);
        } int value = sc.nextInt(); value sc.nextInt() sc.nextInt sc list[i] = value list[i] list i value queue.add(value) queue.add queue value for (int i = 0; i < n; i++) {
            if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            }
        } {
            if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            }
        } if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            } queue.peek() != list[i] queue.peek() queue.peek queue list[i] list i {
                System.out.println(queue.peek());
            } System.out.println(queue.peek()) System.out.println System.out System System.out queue.peek() queue.peek queue {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            } int max = queue.peek(); max queue.peek() queue.peek queue queue.poll() queue.poll queue System.out.println(queue.peek()) System.out.println System.out System System.out queue.peek() queue.peek queue queue.add(max) queue.add queue max String[] args args public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];
        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
            queue.add(value);
        }

        for (int i = 0; i < n; i++) {
            if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            }
        }
    }
} public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];
        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
            queue.add(value);
        }

        for (int i = 0; i < n; i++) {
            if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            }
        }
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];
        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
            queue.add(value);
        }

        for (int i = 0; i < n; i++) {
            if (queue.peek() != list[i]) {
                System.out.println(queue.peek());
            } else {
                int max = queue.peek();
                queue.poll();
                System.out.println(queue.peek());
                queue.add(max);
            }
        }
    }
}