import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> val = new ArrayList<>();
        for(int i= 0;i<N;i++){
            int A = scanner.nextInt();
            val.add(A);
        }
        Map<Integer,Integer> maxLeft = new HashMap<>();
        Map<Integer,Integer> maxRight = new HashMap<>();
        maxLeft.put(0,0);
        maxLeft.put(1,val.get(0));
        for(int i=2; i<N; i++){
            int ml = Math.max(maxLeft.get(i-1), val.get(i-1));
            maxLeft.put(i, ml);
        }
        maxRight.put(N-1, 0);
        maxRight.put(N-2, val.get(N-1));
        for(int i=N-3; i>=0; i--){
            int mr = Math.max(maxRight.get(i+1), val.get(i+1));
            maxRight.put(i, mr);
        }
        // System.out.println(maxLeft);
        // System.out.println(maxRight);

        for(int i=0; i<N; i++){
            System.out.println(Math.max(maxLeft.get(i), maxRight.get(i)));
        }
    }
} import java.util.*; util.* java public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> val = new ArrayList<>();
        for(int i= 0;i<N;i++){
            int A = scanner.nextInt();
            val.add(A);
        }
        Map<Integer,Integer> maxLeft = new HashMap<>();
        Map<Integer,Integer> maxRight = new HashMap<>();
        maxLeft.put(0,0);
        maxLeft.put(1,val.get(0));
        for(int i=2; i<N; i++){
            int ml = Math.max(maxLeft.get(i-1), val.get(i-1));
            maxLeft.put(i, ml);
        }
        maxRight.put(N-1, 0);
        maxRight.put(N-2, val.get(N-1));
        for(int i=N-3; i>=0; i--){
            int mr = Math.max(maxRight.get(i+1), val.get(i+1));
            maxRight.put(i, mr);
        }
        // System.out.println(maxLeft);
        // System.out.println(maxRight);

        for(int i=0; i<N; i++){
            System.out.println(Math.max(maxLeft.get(i), maxRight.get(i)));
        }
    }
} Main public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> val = new ArrayList<>();
        for(int i= 0;i<N;i++){
            int A = scanner.nextInt();
            val.add(A);
        }
        Map<Integer,Integer> maxLeft = new HashMap<>();
        Map<Integer,Integer> maxRight = new HashMap<>();
        maxLeft.put(0,0);
        maxLeft.put(1,val.get(0));
        for(int i=2; i<N; i++){
            int ml = Math.max(maxLeft.get(i-1), val.get(i-1));
            maxLeft.put(i, ml);
        }
        maxRight.put(N-1, 0);
        maxRight.put(N-2, val.get(N-1));
        for(int i=N-3; i>=0; i--){
            int mr = Math.max(maxRight.get(i+1), val.get(i+1));
            maxRight.put(i, mr);
        }
        // System.out.println(maxLeft);
        // System.out.println(maxRight);

        for(int i=0; i<N; i++){
            System.out.println(Math.max(maxLeft.get(i), maxRight.get(i)));
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> val = new ArrayList<>();
        for(int i= 0;i<N;i++){
            int A = scanner.nextInt();
            val.add(A);
        }
        Map<Integer,Integer> maxLeft = new HashMap<>();
        Map<Integer,Integer> maxRight = new HashMap<>();
        maxLeft.put(0,0);
        maxLeft.put(1,val.get(0));
        for(int i=2; i<N; i++){
            int ml = Math.max(maxLeft.get(i-1), val.get(i-1));
            maxLeft.put(i, ml);
        }
        maxRight.put(N-1, 0);
        maxRight.put(N-2, val.get(N-1));
        for(int i=N-3; i>=0; i--){
            int mr = Math.max(maxRight.get(i+1), val.get(i+1));
            maxRight.put(i, mr);
        }
        // System.out.println(maxLeft);
        // System.out.println(maxRight);

        for(int i=0; i<N; i++){
            System.out.println(Math.max(maxLeft.get(i), maxRight.get(i)));
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner List<Integer> val = new ArrayList<>(); val new ArrayList<>() for(int i= 0;i<N;i++){
            int A = scanner.nextInt();
            val.add(A);
        } int i= 0; int i= 0; i 0 i<N i N i++ i++ i {
            int A = scanner.nextInt();
            val.add(A);
        } {
            int A = scanner.nextInt();
            val.add(A);
        } int A = scanner.nextInt(); A scanner.nextInt() scanner.nextInt scanner val.add(A) val.add val A Map<Integer,Integer> maxLeft = new HashMap<>(); maxLeft new HashMap<>() Map<Integer,Integer> maxRight = new HashMap<>(); maxRight new HashMap<>() maxLeft.put(0,0) maxLeft.put maxLeft 0 0 maxLeft.put(1,val.get(0)) maxLeft.put maxLeft 1 val.get(0) val.get val 0 for(int i=2; i<N; i++){
            int ml = Math.max(maxLeft.get(i-1), val.get(i-1));
            maxLeft.put(i, ml);
        } int i=2; int i=2; i 2 i<N i N i++ i++ i {
            int ml = Math.max(maxLeft.get(i-1), val.get(i-1));
            maxLeft.put(i, ml);
        } {
            int ml = Math.max(maxLeft.get(i-1), val.get(i-1));
            maxLeft.put(i, ml);
        } int ml = Math.max(maxLeft.get(i-1), val.get(i-1)); ml Math.max(maxLeft.get(i-1), val.get(i-1)) Math.max Math maxLeft.get(i-1) maxLeft.get maxLeft i-1 i 1 val.get(i-1) val.get val i-1 i 1 maxLeft.put(i, ml) maxLeft.put maxLeft i ml maxRight.put(N-1, 0) maxRight.put maxRight N-1 N 1 0 maxRight.put(N-2, val.get(N-1)) maxRight.put maxRight N-2 N 2 val.get(N-1) val.get val N-1 N 1 for(int i=N-3; i>=0; i--){
            int mr = Math.max(maxRight.get(i+1), val.get(i+1));
            maxRight.put(i, mr);
        } int i=N-3; int i=N-3; i N-3 N 3 i>=0 i 0 i-- i-- i {
            int mr = Math.max(maxRight.get(i+1), val.get(i+1));
            maxRight.put(i, mr);
        } {
            int mr = Math.max(maxRight.get(i+1), val.get(i+1));
            maxRight.put(i, mr);
        } int mr = Math.max(maxRight.get(i+1), val.get(i+1)); mr Math.max(maxRight.get(i+1), val.get(i+1)) Math.max Math maxRight.get(i+1) maxRight.get maxRight i+1 i 1 val.get(i+1) val.get val i+1 i 1 maxRight.put(i, mr) maxRight.put maxRight i mr for(int i=0; i<N; i++){
            System.out.println(Math.max(maxLeft.get(i), maxRight.get(i)));
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            System.out.println(Math.max(maxLeft.get(i), maxRight.get(i)));
        } {
            System.out.println(Math.max(maxLeft.get(i), maxRight.get(i)));
        } System.out.println(Math.max(maxLeft.get(i), maxRight.get(i))) System.out.println System.out System System.out Math.max(maxLeft.get(i), maxRight.get(i)) Math.max Math maxLeft.get(i) maxLeft.get maxLeft i maxRight.get(i) maxRight.get maxRight i String args[] args public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> val = new ArrayList<>();
        for(int i= 0;i<N;i++){
            int A = scanner.nextInt();
            val.add(A);
        }
        Map<Integer,Integer> maxLeft = new HashMap<>();
        Map<Integer,Integer> maxRight = new HashMap<>();
        maxLeft.put(0,0);
        maxLeft.put(1,val.get(0));
        for(int i=2; i<N; i++){
            int ml = Math.max(maxLeft.get(i-1), val.get(i-1));
            maxLeft.put(i, ml);
        }
        maxRight.put(N-1, 0);
        maxRight.put(N-2, val.get(N-1));
        for(int i=N-3; i>=0; i--){
            int mr = Math.max(maxRight.get(i+1), val.get(i+1));
            maxRight.put(i, mr);
        }
        // System.out.println(maxLeft);
        // System.out.println(maxRight);

        for(int i=0; i<N; i++){
            System.out.println(Math.max(maxLeft.get(i), maxRight.get(i)));
        }
    }
} public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> val = new ArrayList<>();
        for(int i= 0;i<N;i++){
            int A = scanner.nextInt();
            val.add(A);
        }
        Map<Integer,Integer> maxLeft = new HashMap<>();
        Map<Integer,Integer> maxRight = new HashMap<>();
        maxLeft.put(0,0);
        maxLeft.put(1,val.get(0));
        for(int i=2; i<N; i++){
            int ml = Math.max(maxLeft.get(i-1), val.get(i-1));
            maxLeft.put(i, ml);
        }
        maxRight.put(N-1, 0);
        maxRight.put(N-2, val.get(N-1));
        for(int i=N-3; i>=0; i--){
            int mr = Math.max(maxRight.get(i+1), val.get(i+1));
            maxRight.put(i, mr);
        }
        // System.out.println(maxLeft);
        // System.out.println(maxRight);

        for(int i=0; i<N; i++){
            System.out.println(Math.max(maxLeft.get(i), maxRight.get(i)));
        }
    }
} Main
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> val = new ArrayList<>();
        for(int i= 0;i<N;i++){
            int A = scanner.nextInt();
            val.add(A);
        }
        Map<Integer,Integer> maxLeft = new HashMap<>();
        Map<Integer,Integer> maxRight = new HashMap<>();
        maxLeft.put(0,0);
        maxLeft.put(1,val.get(0));
        for(int i=2; i<N; i++){
            int ml = Math.max(maxLeft.get(i-1), val.get(i-1));
            maxLeft.put(i, ml);
        }
        maxRight.put(N-1, 0);
        maxRight.put(N-2, val.get(N-1));
        for(int i=N-3; i>=0; i--){
            int mr = Math.max(maxRight.get(i+1), val.get(i+1));
            maxRight.put(i, mr);
        }
        // System.out.println(maxLeft);
        // System.out.println(maxRight);

        for(int i=0; i<N; i++){
            System.out.println(Math.max(maxLeft.get(i), maxRight.get(i)));
        }
    }
}