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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        List<Integer> list2 = new ArrayList<>();
        list2.addAll(list);
        Collections.sort(list2);
        Collections.reverse(list2);
        int max = list2.get(0);
        int max2 = list2.get(1);
        for(int i=0; i<n; i++) {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        }
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        List<Integer> list2 = new ArrayList<>();
        list2.addAll(list);
        Collections.sort(list2);
        Collections.reverse(list2);
        int max = list2.get(0);
        int max2 = list2.get(1);
        for(int i=0; i<n; i++) {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        List<Integer> list2 = new ArrayList<>();
        list2.addAll(list);
        Collections.sort(list2);
        Collections.reverse(list2);
        int max = list2.get(0);
        int max2 = list2.get(1);
        for(int i=0; i<n; i++) {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        List<Integer> list2 = new ArrayList<>();
        list2.addAll(list);
        Collections.sort(list2);
        Collections.reverse(list2);
        int max = list2.get(0);
        int max2 = list2.get(1);
        for(int i=0; i<n; i++) {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc List<Integer> list = new ArrayList<>(); list new ArrayList<>() for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            list.add(sc.nextInt());
        } {
            list.add(sc.nextInt());
        } list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc List<Integer> list2 = new ArrayList<>(); list2 new ArrayList<>() list2.addAll(list) list2.addAll list2 list Collections.sort(list2) Collections.sort Collections list2 Collections.reverse(list2) Collections.reverse Collections list2 int max = list2.get(0); max list2.get(0) list2.get list2 0 int max2 = list2.get(1); max2 list2.get(1) list2.get list2 1 for(int i=0; i<n; i++) {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        } {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        } if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max); list.get(i) == max list.get(i) list.get list i max System.out.println(max2) System.out.println System.out System System.out max2 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 n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        List<Integer> list2 = new ArrayList<>();
        list2.addAll(list);
        Collections.sort(list2);
        Collections.reverse(list2);
        int max = list2.get(0);
        int max2 = list2.get(1);
        for(int i=0; i<n; i++) {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        List<Integer> list2 = new ArrayList<>();
        list2.addAll(list);
        Collections.sort(list2);
        Collections.reverse(list2);
        int max = list2.get(0);
        int max2 = list2.get(1);
        for(int i=0; i<n; i++) {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        }
    }
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        List<Integer> list2 = new ArrayList<>();
        list2.addAll(list);
        Collections.sort(list2);
        Collections.reverse(list2);
        int max = list2.get(0);
        int max2 = list2.get(1);
        for(int i=0; i<n; i++) {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        }
    }
}