import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] l = new int[N];
        int max = -1;
        int second_max = -1;
        for(int i = 0; i< N; i++){
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        }
        for(int elem :l){
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        }
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] l = new int[N];
        int max = -1;
        int second_max = -1;
        for(int i = 0; i< N; i++){
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        }
        for(int elem :l){
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] l = new int[N];
        int max = -1;
        int second_max = -1;
        for(int i = 0; i< N; i++){
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        }
        for(int elem :l){
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] l = new int[N];
        int max = -1;
        int second_max = -1;
        for(int i = 0; i< N; i++){
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        }
        for(int elem :l){
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] l = new int[N]; l new int[N] N int max = -1; max -1 1 int second_max = -1; second_max -1 1 for(int i = 0; i< N; i++){
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        } int i = 0; int i = 0; i 0 i< N i N i++ i++ i {
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        } {
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        } int num = Integer.parseInt(sc.next()); num Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            } num > max num max {
                second_max = max;
                max = num;
            } second_max = max second_max max max = num max num {
                if(num > second_max){
                    second_max = num;
                }
            } if(num > second_max){
                    second_max = num;
                } num > second_max num second_max {
                    second_max = num;
                } second_max = num second_max num l[i] = num l[i] l i num for(int elem :l){
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        } int elem l {
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        } {
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        } if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            } max != elem max elem {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max {
                System.out.println(second_max);
            } System.out.println(second_max) System.out.println System.out System System.out second_max String[] args args public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] l = new int[N];
        int max = -1;
        int second_max = -1;
        for(int i = 0; i< N; i++){
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        }
        for(int elem :l){
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        }
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] l = new int[N];
        int max = -1;
        int second_max = -1;
        for(int i = 0; i< N; i++){
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        }
        for(int elem :l){
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        }
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] l = new int[N];
        int max = -1;
        int second_max = -1;
        for(int i = 0; i< N; i++){
            int num = Integer.parseInt(sc.next());
            if(num > max){
                second_max = max;
                max = num;
            }else{
                if(num > second_max){
                    second_max = num;
                }
            }
            l[i] = num;
        }
        for(int elem :l){
            if(max != elem){
                System.out.println(max);
            }else{
                System.out.println(second_max);
            }
        }
    }
}