 
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

  class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int arr[] = new int[x];
        int arr2[] = new int[x];
        for(int i = 0 ; i<x ; i++){
            arr[i]=scan.nextInt();
            arr2[i]=arr[i];
        }
        Arrays.sort(arr2);
        int max1 = arr2[x-1];
        int max2 = arr2[x-2];
        for(int i = 0 ; i<x ; i++){
            if(arr[i]==max1){
                System.out.println(max2);
            }else{
                System.out.println(max1);
            }
        }
        
         
        
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int arr[] = new int[x];
        int arr2[] = new int[x];
        for(int i = 0 ; i<x ; i++){
            arr[i]=scan.nextInt();
            arr2[i]=arr[i];
        }
        Arrays.sort(arr2);
        int max1 = arr2[x-1];
        int max2 = arr2[x-2];
        for(int i = 0 ; i<x ; i++){
            if(arr[i]==max1){
                System.out.println(max2);
            }else{
                System.out.println(max1);
            }
        }
        
         
        
    }
} Main public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int arr[] = new int[x];
        int arr2[] = new int[x];
        for(int i = 0 ; i<x ; i++){
            arr[i]=scan.nextInt();
            arr2[i]=arr[i];
        }
        Arrays.sort(arr2);
        int max1 = arr2[x-1];
        int max2 = arr2[x-2];
        for(int i = 0 ; i<x ; i++){
            if(arr[i]==max1){
                System.out.println(max2);
            }else{
                System.out.println(max1);
            }
        }
        
         
        
    } main {
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int arr[] = new int[x];
        int arr2[] = new int[x];
        for(int i = 0 ; i<x ; i++){
            arr[i]=scan.nextInt();
            arr2[i]=arr[i];
        }
        Arrays.sort(arr2);
        int max1 = arr2[x-1];
        int max2 = arr2[x-2];
        for(int i = 0 ; i<x ; i++){
            if(arr[i]==max1){
                System.out.println(max2);
            }else{
                System.out.println(max1);
            }
        }
        
         
        
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan int arr[] = new int[x]; arr new int[x] x int arr2[] = new int[x]; arr2 new int[x] x for(int i = 0 ; i<x ; i++){
            arr[i]=scan.nextInt();
            arr2[i]=arr[i];
        } int i = 0 ; int i = 0 ; i 0 i<x i x i++ i++ i {
            arr[i]=scan.nextInt();
            arr2[i]=arr[i];
        } {
            arr[i]=scan.nextInt();
            arr2[i]=arr[i];
        } arr[i]=scan.nextInt() arr[i] arr i scan.nextInt() scan.nextInt scan arr2[i]=arr[i] arr2[i] arr2 i arr[i] arr i Arrays.sort(arr2) Arrays.sort Arrays arr2 int max1 = arr2[x-1]; max1 arr2[x-1] arr2 x-1 x 1 int max2 = arr2[x-2]; max2 arr2[x-2] arr2 x-2 x 2 for(int i = 0 ; i<x ; i++){
            if(arr[i]==max1){
                System.out.println(max2);
            }else{
                System.out.println(max1);
            }
        } int i = 0 ; int i = 0 ; i 0 i<x i x i++ i++ i {
            if(arr[i]==max1){
                System.out.println(max2);
            }else{
                System.out.println(max1);
            }
        } {
            if(arr[i]==max1){
                System.out.println(max2);
            }else{
                System.out.println(max1);
            }
        } if(arr[i]==max1){
                System.out.println(max2);
            }else{
                System.out.println(max1);
            } arr[i]==max1 arr[i] arr i max1 {
                System.out.println(max2);
            } System.out.println(max2) System.out.println System.out System System.out max2 {
                System.out.println(max1);
            } System.out.println(max1) System.out.println System.out System System.out max1 String[]args args
 
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

  class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int arr[] = new int[x];
        int arr2[] = new int[x];
        for(int i = 0 ; i<x ; i++){
            arr[i]=scan.nextInt();
            arr2[i]=arr[i];
        }
        Arrays.sort(arr2);
        int max1 = arr2[x-1];
        int max2 = arr2[x-2];
        for(int i = 0 ; i<x ; i++){
            if(arr[i]==max1){
                System.out.println(max2);
            }else{
                System.out.println(max1);
            }
        }
        
         
        
    }
}
