import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int first = Integer.MIN_VALUE;
        int second = Integer.MIN_VALUE;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            list.add(a);
            if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            }
        }

        for (int a : list) {
            if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            }
        }
    }

} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int first = Integer.MIN_VALUE;
        int second = Integer.MIN_VALUE;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            list.add(a);
            if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            }
        }

        for (int a : list) {
            if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            }
        }
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int first = Integer.MIN_VALUE;
        int second = Integer.MIN_VALUE;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            list.add(a);
            if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            }
        }

        for (int a : list) {
            if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int first = Integer.MIN_VALUE;
        int second = Integer.MIN_VALUE;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            list.add(a);
            if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            }
        }

        for (int a : list) {
            if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int first = Integer.MIN_VALUE; first Integer.MIN_VALUE Integer Integer.MIN_VALUE int second = Integer.MIN_VALUE; second Integer.MIN_VALUE Integer Integer.MIN_VALUE List<Integer> list = new ArrayList<>(); list new ArrayList<>() for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            list.add(a);
            if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int a = sc.nextInt();
            list.add(a);
            if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            }
        } {
            int a = sc.nextInt();
            list.add(a);
            if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            }
        } int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc list.add(a) list.add list a if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            } a > first a first {
                second = first;
                first = a;
            } second = first second first first = a first a if (a > second){
                second = a;
            } a > second a second {
                second = a;
            } second = a second a for (int a : list) {
            if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            }
        } int a list {
            if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            }
        } {
            if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            }
        } if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            } a < first a first {
                System.out.println(first);
            } System.out.println(first) System.out.println System.out System System.out first {
                System.out.println(second);
            } System.out.println(second) System.out.println System.out System System.out second String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int first = Integer.MIN_VALUE;
        int second = Integer.MIN_VALUE;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            list.add(a);
            if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            }
        }

        for (int a : list) {
            if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            }
        }
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int first = Integer.MIN_VALUE;
        int second = Integer.MIN_VALUE;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            list.add(a);
            if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            }
        }

        for (int a : list) {
            if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            }
        }
    }

} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int first = Integer.MIN_VALUE;
        int second = Integer.MIN_VALUE;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            list.add(a);
            if (a > first) {
                second = first;
                first = a;
            } else if (a > second){
                second = a;
            }
        }

        for (int a : list) {
            if (a < first) {
                System.out.println(first);
            } else {
                System.out.println(second);
            }
        }
    }

}