import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n ;i++){
            a[i] = stdIn.nextInt();
        }
        int max = 0;
        int max2 = 0;
        for(int i = 0 ; i < n ;i++) {
            if(a[i] > max) {
                max2 = max;
                max = a[i];
            }else if(a[i] > max2) {
                max2 = a[i];
            }
        }
        for(int i = 0;i < n;i++) {
            if(a[i] < max){
                System.out.println(max);
            }else {
                System.out.println(max2);
            }
        }

    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n ;i++){
            a[i] = stdIn.nextInt();
        }
        int max = 0;
        int max2 = 0;
        for(int i = 0 ; i < n ;i++) {
            if(a[i] > max) {
                max2 = max;
                max = a[i];
            }else if(a[i] > max2) {
                max2 = a[i];
            }
        }
        for(int i = 0;i < n;i++) {
            if(a[i] < max){
                System.out.println(max);
            }else {
                System.out.println(max2);
            }
        }

    }
} Main public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n ;i++){
            a[i] = stdIn.nextInt();
        }
        int max = 0;
        int max2 = 0;
        for(int i = 0 ; i < n ;i++) {
            if(a[i] > max) {
                max2 = max;
                max = a[i];
            }else if(a[i] > max2) {
                max2 = a[i];
            }
        }
        for(int i = 0;i < n;i++) {
            if(a[i] < max){
                System.out.println(max);
            }else {
                System.out.println(max2);
            }
        }

    } main {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n ;i++){
            a[i] = stdIn.nextInt();
        }
        int max = 0;
        int max2 = 0;
        for(int i = 0 ; i < n ;i++) {
            if(a[i] > max) {
                max2 = max;
                max = a[i];
            }else if(a[i] > max2) {
                max2 = a[i];
            }
        }
        for(int i = 0;i < n;i++) {
            if(a[i] < max){
                System.out.println(max);
            }else {
                System.out.println(max2);
            }
        }

    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] a = new int[n]; a new int[n] n for(int i = 0; i < n ;i++){
            a[i] = stdIn.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = stdIn.nextInt();
        } {
            a[i] = stdIn.nextInt();
        } a[i] = stdIn.nextInt() a[i] a i stdIn.nextInt() stdIn.nextInt stdIn int max = 0; max 0 int max2 = 0; max2 0 for(int i = 0 ; i < n ;i++) {
            if(a[i] > max) {
                max2 = max;
                max = a[i];
            }else if(a[i] > max2) {
                max2 = a[i];
            }
        } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
            if(a[i] > max) {
                max2 = max;
                max = a[i];
            }else if(a[i] > max2) {
                max2 = a[i];
            }
        } {
            if(a[i] > max) {
                max2 = max;
                max = a[i];
            }else if(a[i] > max2) {
                max2 = a[i];
            }
        } if(a[i] > max) {
                max2 = max;
                max = a[i];
            }else if(a[i] > max2) {
                max2 = a[i];
            } a[i] > max a[i] a i max {
                max2 = max;
                max = a[i];
            } max2 = max max2 max max = a[i] max a[i] a i if(a[i] > max2) {
                max2 = a[i];
            } a[i] > max2 a[i] a i max2 {
                max2 = a[i];
            } max2 = a[i] max2 a[i] a i for(int i = 0;i < n;i++) {
            if(a[i] < max){
                System.out.println(max);
            }else {
                System.out.println(max2);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(a[i] < max){
                System.out.println(max);
            }else {
                System.out.println(max2);
            }
        } {
            if(a[i] < max){
                System.out.println(max);
            }else {
                System.out.println(max2);
            }
        } if(a[i] < max){
                System.out.println(max);
            }else {
                System.out.println(max2);
            } a[i] < max a[i] a i max {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max {
                System.out.println(max2);
            } System.out.println(max2) System.out.println System.out System System.out max2 String[] args args
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n ;i++){
            a[i] = stdIn.nextInt();
        }
        int max = 0;
        int max2 = 0;
        for(int i = 0 ; i < n ;i++) {
            if(a[i] > max) {
                max2 = max;
                max = a[i];
            }else if(a[i] > max2) {
                max2 = a[i];
            }
        }
        for(int i = 0;i < n;i++) {
            if(a[i] < max){
                System.out.println(max);
            }else {
                System.out.println(max2);
            }
        }

    }
}