import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) list.add(sc.nextInt());
        ArrayList<Integer> list1 = (ArrayList<Integer>)list.clone();
        list1.stream().distinct();
        Collections.sort(list1);
        Integer a = list1.get(list1.size() - 1);
        Integer b = list1.get(list1.size() - 2);
        for(int i = 0; i < n; i++){
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        }
    }
} 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();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) list.add(sc.nextInt());
        ArrayList<Integer> list1 = (ArrayList<Integer>)list.clone();
        list1.stream().distinct();
        Collections.sort(list1);
        Integer a = list1.get(list1.size() - 1);
        Integer b = list1.get(list1.size() - 2);
        for(int i = 0; i < n; i++){
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) list.add(sc.nextInt());
        ArrayList<Integer> list1 = (ArrayList<Integer>)list.clone();
        list1.stream().distinct();
        Collections.sort(list1);
        Integer a = list1.get(list1.size() - 1);
        Integer b = list1.get(list1.size() - 2);
        for(int i = 0; i < n; i++){
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) list.add(sc.nextInt());
        ArrayList<Integer> list1 = (ArrayList<Integer>)list.clone();
        list1.stream().distinct();
        Collections.sort(list1);
        Integer a = list1.get(list1.size() - 1);
        Integer b = list1.get(list1.size() - 2);
        for(int i = 0; i < n; i++){
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc ArrayList<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 list sc.nextInt() sc.nextInt sc ArrayList<Integer> list1 = (ArrayList<Integer>)list.clone(); list1 (ArrayList<Integer>)list.clone() list.clone list list1.stream().distinct() list1.stream().distinct list1.stream() list1.stream list1 Collections.sort(list1) Collections.sort Collections list1 Integer a = list1.get(list1.size() - 1); a list1.get(list1.size() - 1) list1.get list1 list1.size() - 1 list1.size() list1.size list1 1 Integer b = list1.get(list1.size() - 2); b list1.get(list1.size() - 2) list1.get list1 list1.size() - 2 list1.size() list1.size list1 2 for(int i = 0; i < n; i++){
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        } {
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        } if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a); list.get(i) == a list.get(i) list.get list i a System.out.println(b) System.out.println System.out System System.out b if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a); list.get(i) == b list.get(i) list.get list i b System.out.println(a) System.out.println System.out System System.out a System.out.println(a) System.out.println System.out System System.out a String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) list.add(sc.nextInt());
        ArrayList<Integer> list1 = (ArrayList<Integer>)list.clone();
        list1.stream().distinct();
        Collections.sort(list1);
        Integer a = list1.get(list1.size() - 1);
        Integer b = list1.get(list1.size() - 2);
        for(int i = 0; i < n; i++){
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) list.add(sc.nextInt());
        ArrayList<Integer> list1 = (ArrayList<Integer>)list.clone();
        list1.stream().distinct();
        Collections.sort(list1);
        Integer a = list1.get(list1.size() - 1);
        Integer b = list1.get(list1.size() - 2);
        for(int i = 0; i < n; i++){
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        }
    }
} 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();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) list.add(sc.nextInt());
        ArrayList<Integer> list1 = (ArrayList<Integer>)list.clone();
        list1.stream().distinct();
        Collections.sort(list1);
        Integer a = list1.get(list1.size() - 1);
        Integer b = list1.get(list1.size() - 2);
        for(int i = 0; i < n; i++){
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        }
    }
}