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)));
        }
    }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz