import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();
        int[] leftMax = new int[n];
        int max = 0;
        for(int i = 0; i < n; i++) {
        	leftMax[i] = max;
        	max = Math.max(max, arr[i]);
        }

        int[] rightMax = new int[n];
        max = 0;
        for(int i = n-1; i >= 0; i--) {
        	rightMax[i] = max;
        	max = Math.max(max, arr[i]);
        }
        for(int i = 0; i < n; i++)
        	System.out.println(Math.max(leftMax[i], rightMax[i]));
    }
} import java.util.*; util.* java public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();
        int[] leftMax = new int[n];
        int max = 0;
        for(int i = 0; i < n; i++) {
        	leftMax[i] = max;
        	max = Math.max(max, arr[i]);
        }

        int[] rightMax = new int[n];
        max = 0;
        for(int i = n-1; i >= 0; i--) {
        	rightMax[i] = max;
        	max = Math.max(max, arr[i]);
        }
        for(int i = 0; i < n; i++)
        	System.out.println(Math.max(leftMax[i], rightMax[i]));
    }
} Main public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();
        int[] leftMax = new int[n];
        int max = 0;
        for(int i = 0; i < n; i++) {
        	leftMax[i] = max;
        	max = Math.max(max, arr[i]);
        }

        int[] rightMax = new int[n];
        max = 0;
        for(int i = n-1; i >= 0; i--) {
        	rightMax[i] = max;
        	max = Math.max(max, arr[i]);
        }
        for(int i = 0; i < n; i++)
        	System.out.println(Math.max(leftMax[i], rightMax[i]));
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();
        int[] leftMax = new int[n];
        int max = 0;
        for(int i = 0; i < n; i++) {
        	leftMax[i] = max;
        	max = Math.max(max, arr[i]);
        }

        int[] rightMax = new int[n];
        max = 0;
        for(int i = n-1; i >= 0; i--) {
        	rightMax[i] = max;
        	max = Math.max(max, arr[i]);
        }
        for(int i = 0; i < n; i++)
        	System.out.println(Math.max(leftMax[i], rightMax[i]));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i arr[i] = sc.nextInt(); arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc int[] leftMax = new int[n]; leftMax new int[n] n int max = 0; max 0 for(int i = 0; i < n; i++) {
        	leftMax[i] = max;
        	max = Math.max(max, arr[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        	leftMax[i] = max;
        	max = Math.max(max, arr[i]);
        } {
        	leftMax[i] = max;
        	max = Math.max(max, arr[i]);
        } leftMax[i] = max leftMax[i] leftMax i max max = Math.max(max, arr[i]) max Math.max(max, arr[i]) Math.max Math max arr[i] arr i int[] rightMax = new int[n]; rightMax new int[n] n max = 0 max 0 for(int i = n-1; i >= 0; i--) {
        	rightMax[i] = max;
        	max = Math.max(max, arr[i]);
        } int i = n-1; int i = n-1; i n-1 n 1 i >= 0 i 0 i-- i-- i {
        	rightMax[i] = max;
        	max = Math.max(max, arr[i]);
        } {
        	rightMax[i] = max;
        	max = Math.max(max, arr[i]);
        } rightMax[i] = max rightMax[i] rightMax i max max = Math.max(max, arr[i]) max Math.max(max, arr[i]) Math.max Math max arr[i] arr i for(int i = 0; i < n; i++)
        	System.out.println(Math.max(leftMax[i], rightMax[i])); int i = 0; int i = 0; i 0 i < n i n i++ i++ i System.out.println(Math.max(leftMax[i], rightMax[i])); System.out.println(Math.max(leftMax[i], rightMax[i])) System.out.println System.out System System.out Math.max(leftMax[i], rightMax[i]) Math.max Math leftMax[i] leftMax i rightMax[i] rightMax i String args[] args public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();
        int[] leftMax = new int[n];
        int max = 0;
        for(int i = 0; i < n; i++) {
        	leftMax[i] = max;
        	max = Math.max(max, arr[i]);
        }

        int[] rightMax = new int[n];
        max = 0;
        for(int i = n-1; i >= 0; i--) {
        	rightMax[i] = max;
        	max = Math.max(max, arr[i]);
        }
        for(int i = 0; i < n; i++)
        	System.out.println(Math.max(leftMax[i], rightMax[i]));
    }
} public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();
        int[] leftMax = new int[n];
        int max = 0;
        for(int i = 0; i < n; i++) {
        	leftMax[i] = max;
        	max = Math.max(max, arr[i]);
        }

        int[] rightMax = new int[n];
        max = 0;
        for(int i = n-1; i >= 0; i--) {
        	rightMax[i] = max;
        	max = Math.max(max, arr[i]);
        }
        for(int i = 0; i < n; i++)
        	System.out.println(Math.max(leftMax[i], rightMax[i]));
    }
} Main
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();
        int[] leftMax = new int[n];
        int max = 0;
        for(int i = 0; i < n; i++) {
        	leftMax[i] = max;
        	max = Math.max(max, arr[i]);
        }

        int[] rightMax = new int[n];
        max = 0;
        for(int i = n-1; i >= 0; i--) {
        	rightMax[i] = max;
        	max = Math.max(max, arr[i]);
        }
        for(int i = 0; i < n; i++)
        	System.out.println(Math.max(leftMax[i], rightMax[i]));
    }
}
