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[] A = new int[N];
        
        int max1 = 0;
        int max2 = 0;
        
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        }
        
        for(int i = 0; i < N; i++){
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        }
        
    }
} 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[] A = new int[N];
        
        int max1 = 0;
        int max2 = 0;
        
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        }
        
        for(int i = 0; i < N; i++){
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        }
        
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        
        int max1 = 0;
        int max2 = 0;
        
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        }
        
        for(int i = 0; i < N; i++){
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        }
        
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        
        int max1 = 0;
        int max2 = 0;
        
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        }
        
        for(int i = 0; i < N; i++){
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        }
        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A = new int[N]; A new int[N] N int max1 = 0; max1 0 int max2 = 0; max2 0 for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        } {
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            } max1 < A[i] max1 A[i] A i {
                max1 = A[i];
            } max1 = A[i] max1 A[i] A i if ( max2 < A[i] ) {
                max2 = A[i];
            } max2 < A[i] max2 A[i] A i {
                max2 = A[i];
            } max2 = A[i] max2 A[i] A i for(int i = 0; i < N; i++){
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        } {
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        } if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            } A[i] != max1 A[i] A i max1 {
                System.out.println(max1);
            } System.out.println(max1) System.out.println System.out System System.out max1 {
                System.out.println(max2);
            } System.out.println(max2) System.out.println System.out System System.out max2 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[] A = new int[N];
        
        int max1 = 0;
        int max2 = 0;
        
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        }
        
        for(int i = 0; i < N; i++){
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        }
        
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        
        int max1 = 0;
        int max2 = 0;
        
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        }
        
        for(int i = 0; i < N; i++){
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        }
        
    }
} 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[] A = new int[N];
        
        int max1 = 0;
        int max2 = 0;
        
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        }
        
        for(int i = 0; i < N; i++){
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        }
        
    }
}
