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

        int[] left = new int[n];
        left[0] = a[0];
        for(int i=1; i<n; i++){
            if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            }
        }

        int[] right = new int[n];
        right[n-1] = a[n-1];
        for(int i=n-2; i>=0; i--){
            if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            }
        }

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

        int[] left = new int[n];
        left[0] = a[0];
        for(int i=1; i<n; i++){
            if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            }
        }

        int[] right = new int[n];
        right[n-1] = a[n-1];
        for(int i=n-2; i>=0; i--){
            if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            }
        }

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

        int[] left = new int[n];
        left[0] = a[0];
        for(int i=1; i<n; i++){
            if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            }
        }

        int[] right = new int[n];
        right[n-1] = a[n-1];
        for(int i=n-2; i>=0; i--){
            if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            }
        }

        for(int i=0; i<n; i++){
            if(i == 0){
                System.out.println(right[1]);
            }else if(i == n-1){
                System.out.println(left[n-2]);
            }else{
                if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                }
            }
        }
    } main {
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = stdIn.nextInt();
        }

        int[] left = new int[n];
        left[0] = a[0];
        for(int i=1; i<n; i++){
            if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            }
        }

        int[] right = new int[n];
        right[n-1] = a[n-1];
        for(int i=n-2; i>=0; i--){
            if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            }
        }

        for(int i=0; i<n; i++){
            if(i == 0){
                System.out.println(right[1]);
            }else if(i == n-1){
                System.out.println(left[n-2]);
            }else{
                if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                }
            }
        }
    } 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[] left = new int[n]; left new int[n] n left[0] = a[0] left[0] left 0 a[0] a 0 for(int i=1; i<n; i++){
            if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            }
        } int i=1; int i=1; i 1 i<n i n i++ i++ i {
            if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            }
        } {
            if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            }
        } if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            } left[i-1] < a[i] left[i-1] left i-1 i 1 a[i] a i {
                left[i] = a[i];
            } left[i] = a[i] left[i] left i a[i] a i {
                left[i] = left[i-1];
            } left[i] = left[i-1] left[i] left i left[i-1] left i-1 i 1 int[] right = new int[n]; right new int[n] n right[n-1] = a[n-1] right[n-1] right n-1 n 1 a[n-1] a n-1 n 1 for(int i=n-2; i>=0; i--){
            if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            }
        } int i=n-2; int i=n-2; i n-2 n 2 i>=0 i 0 i-- i-- i {
            if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            }
        } {
            if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            }
        } if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            } right[i+1] < a[i] right[i+1] right i+1 i 1 a[i] a i {
                right[i] = a[i];
            } right[i] = a[i] right[i] right i a[i] a i {
                right[i] = right[i+1];
            } right[i] = right[i+1] right[i] right i right[i+1] right i+1 i 1 for(int i=0; i<n; i++){
            if(i == 0){
                System.out.println(right[1]);
            }else if(i == n-1){
                System.out.println(left[n-2]);
            }else{
                if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                }
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(i == 0){
                System.out.println(right[1]);
            }else if(i == n-1){
                System.out.println(left[n-2]);
            }else{
                if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                }
            }
        } {
            if(i == 0){
                System.out.println(right[1]);
            }else if(i == n-1){
                System.out.println(left[n-2]);
            }else{
                if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                }
            }
        } if(i == 0){
                System.out.println(right[1]);
            }else if(i == n-1){
                System.out.println(left[n-2]);
            }else{
                if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                }
            } i == 0 i 0 {
                System.out.println(right[1]);
            } System.out.println(right[1]) System.out.println System.out System System.out right[1] right 1 if(i == n-1){
                System.out.println(left[n-2]);
            }else{
                if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                }
            } i == n-1 i n-1 n 1 {
                System.out.println(left[n-2]);
            } System.out.println(left[n-2]) System.out.println System.out System System.out left[n-2] left n-2 n 2 {
                if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                }
            } if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                } left[i-1] < right[i+1] left[i-1] left i-1 i 1 right[i+1] right i+1 i 1 {
                    System.out.println(right[i+1]);
                } System.out.println(right[i+1]) System.out.println System.out System System.out right[i+1] right i+1 i 1 {
                    System.out.println(left[i-1]);
                } System.out.println(left[i-1]) System.out.println System.out System System.out left[i-1] left i-1 i 1 String[] args args public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = stdIn.nextInt();
        }

        int[] left = new int[n];
        left[0] = a[0];
        for(int i=1; i<n; i++){
            if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            }
        }

        int[] right = new int[n];
        right[n-1] = a[n-1];
        for(int i=n-2; i>=0; i--){
            if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            }
        }

        for(int i=0; i<n; i++){
            if(i == 0){
                System.out.println(right[1]);
            }else if(i == n-1){
                System.out.println(left[n-2]);
            }else{
                if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                }
            }
        }
    }
} public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = stdIn.nextInt();
        }

        int[] left = new int[n];
        left[0] = a[0];
        for(int i=1; i<n; i++){
            if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            }
        }

        int[] right = new int[n];
        right[n-1] = a[n-1];
        for(int i=n-2; i>=0; i--){
            if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            }
        }

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

        int[] left = new int[n];
        left[0] = a[0];
        for(int i=1; i<n; i++){
            if(left[i-1] < a[i]){
                left[i] = a[i];
            }else{
                left[i] = left[i-1];
            }
        }

        int[] right = new int[n];
        right[n-1] = a[n-1];
        for(int i=n-2; i>=0; i--){
            if(right[i+1] < a[i]){
                right[i] = a[i];
            }else{
                right[i] = right[i+1];
            }
        }

        for(int i=0; i<n; i++){
            if(i == 0){
                System.out.println(right[1]);
            }else if(i == n-1){
                System.out.println(left[n-2]);
            }else{
                if(left[i-1] < right[i+1]){
                    System.out.println(right[i+1]);
                }else{
                    System.out.println(left[i-1]);
                }
            }
        }
    }
}
