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

public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        for(int i = 0; i < a; i++){
            list.add(sc.nextInt());
        }
        ArrayList<Integer> list1 = new ArrayList<Integer>(list);
        Collections.sort(list1);
        int max = list1.get(a - 1);
        int second = list1.get(a - 2);
        for(int i = 0; i < a; i++){
            if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            }
        }
    }
} import java.util.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        for(int i = 0; i < a; i++){
            list.add(sc.nextInt());
        }
        ArrayList<Integer> list1 = new ArrayList<Integer>(list);
        Collections.sort(list1);
        int max = list1.get(a - 1);
        int second = list1.get(a - 2);
        for(int i = 0; i < a; i++){
            if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            }
        }
    }
} Main public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        for(int i = 0; i < a; i++){
            list.add(sc.nextInt());
        }
        ArrayList<Integer> list1 = new ArrayList<Integer>(list);
        Collections.sort(list1);
        int max = list1.get(a - 1);
        int second = list1.get(a - 2);
        for(int i = 0; i < a; i++){
            if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            }
        }
    } main {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        for(int i = 0; i < a; i++){
            list.add(sc.nextInt());
        }
        ArrayList<Integer> list1 = new ArrayList<Integer>(list);
        Collections.sort(list1);
        int max = list1.get(a - 1);
        int second = list1.get(a - 2);
        for(int i = 0; i < a; i++){
            if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() for(int i = 0; i < a; i++){
            list.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
            list.add(sc.nextInt());
        } {
            list.add(sc.nextInt());
        } list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc ArrayList<Integer> list1 = new ArrayList<Integer>(list); list1 new ArrayList<Integer>(list) Collections.sort(list1) Collections.sort Collections list1 int max = list1.get(a - 1); max list1.get(a - 1) list1.get list1 a - 1 a 1 int second = list1.get(a - 2); second list1.get(a - 2) list1.get list1 a - 2 a 2 for(int i = 0; i < a; i++){
            if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            }
        } int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
            if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            }
        } {
            if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            }
        } if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            } list.get(i) == max list.get(i) list.get list i max {
                System.out.println(second);
            } System.out.println(second) System.out.println System.out System System.out second {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        for(int i = 0; i < a; i++){
            list.add(sc.nextInt());
        }
        ArrayList<Integer> list1 = new ArrayList<Integer>(list);
        Collections.sort(list1);
        int max = list1.get(a - 1);
        int second = list1.get(a - 2);
        for(int i = 0; i < a; i++){
            if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            }
        }
    }
} public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        for(int i = 0; i < a; i++){
            list.add(sc.nextInt());
        }
        ArrayList<Integer> list1 = new ArrayList<Integer>(list);
        Collections.sort(list1);
        int max = list1.get(a - 1);
        int second = list1.get(a - 2);
        for(int i = 0; i < a; i++){
            if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            }
        }
    }
} Main
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        for(int i = 0; i < a; i++){
            list.add(sc.nextInt());
        }
        ArrayList<Integer> list1 = new ArrayList<Integer>(list);
        Collections.sort(list1);
        int max = list1.get(a - 1);
        int second = list1.get(a - 2);
        for(int i = 0; i < a; i++){
            if(list.get(i) == max){
                System.out.println(second);
            }else{
                System.out.println(max);
            }
        }
    }
}
