import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

import static java.util.Comparator.reverseOrder;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> aList = new ArrayList();
        for (int i = 1; i <= n; i++) {
            aList.add(sc.nextInt());
        }
        List<Integer> sortedList = aList.stream().sorted(reverseOrder()).collect(Collectors.toList());
        int max = sortedList.get(0);

        for (int i = 0; i < n; i++) {
            int tempA = aList.get(i);
            if (tempA == max) {
                System.out.println(sortedList.get(1));
            } else {
                System.out.println(max);
            }
        }
    }
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util import java.util.stream.Collectors; Collectors java.util.stream import static java.util.Comparator.reverseOrder; import static java.util.Comparator.reverseOrder; import static java.util.Comparator.reverseOrder; public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> aList = new ArrayList();
        for (int i = 1; i <= n; i++) {
            aList.add(sc.nextInt());
        }
        List<Integer> sortedList = aList.stream().sorted(reverseOrder()).collect(Collectors.toList());
        int max = sortedList.get(0);

        for (int i = 0; i < n; i++) {
            int tempA = aList.get(i);
            if (tempA == max) {
                System.out.println(sortedList.get(1));
            } else {
                System.out.println(max);
            }
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> aList = new ArrayList();
        for (int i = 1; i <= n; i++) {
            aList.add(sc.nextInt());
        }
        List<Integer> sortedList = aList.stream().sorted(reverseOrder()).collect(Collectors.toList());
        int max = sortedList.get(0);

        for (int i = 0; i < n; i++) {
            int tempA = aList.get(i);
            if (tempA == max) {
                System.out.println(sortedList.get(1));
            } else {
                System.out.println(max);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> aList = new ArrayList();
        for (int i = 1; i <= n; i++) {
            aList.add(sc.nextInt());
        }
        List<Integer> sortedList = aList.stream().sorted(reverseOrder()).collect(Collectors.toList());
        int max = sortedList.get(0);

        for (int i = 0; i < n; i++) {
            int tempA = aList.get(i);
            if (tempA == max) {
                System.out.println(sortedList.get(1));
            } 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> aList = new ArrayList(); aList new ArrayList() for (int i = 1; i <= n; i++) {
            aList.add(sc.nextInt());
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            aList.add(sc.nextInt());
        } {
            aList.add(sc.nextInt());
        } aList.add(sc.nextInt()) aList.add aList sc.nextInt() sc.nextInt sc List<Integer> sortedList = aList.stream().sorted(reverseOrder()).collect(Collectors.toList()); sortedList aList.stream().sorted(reverseOrder()).collect(Collectors.toList()) aList.stream().sorted(reverseOrder()).collect aList.stream().sorted(reverseOrder()) aList.stream().sorted aList.stream() aList.stream aList reverseOrder() reverseOrder Collectors.toList() Collectors.toList Collectors int max = sortedList.get(0); max sortedList.get(0) sortedList.get sortedList 0 for (int i = 0; i < n; i++) {
            int tempA = aList.get(i);
            if (tempA == max) {
                System.out.println(sortedList.get(1));
            } else {
                System.out.println(max);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int tempA = aList.get(i);
            if (tempA == max) {
                System.out.println(sortedList.get(1));
            } else {
                System.out.println(max);
            }
        } {
            int tempA = aList.get(i);
            if (tempA == max) {
                System.out.println(sortedList.get(1));
            } else {
                System.out.println(max);
            }
        } int tempA = aList.get(i); tempA aList.get(i) aList.get aList i if (tempA == max) {
                System.out.println(sortedList.get(1));
            } else {
                System.out.println(max);
            } tempA == max tempA max {
                System.out.println(sortedList.get(1));
            } System.out.println(sortedList.get(1)) System.out.println System.out System System.out sortedList.get(1) sortedList.get sortedList 1 {
                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 n = sc.nextInt();
        List<Integer> aList = new ArrayList();
        for (int i = 1; i <= n; i++) {
            aList.add(sc.nextInt());
        }
        List<Integer> sortedList = aList.stream().sorted(reverseOrder()).collect(Collectors.toList());
        int max = sortedList.get(0);

        for (int i = 0; i < n; i++) {
            int tempA = aList.get(i);
            if (tempA == max) {
                System.out.println(sortedList.get(1));
            } 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> aList = new ArrayList();
        for (int i = 1; i <= n; i++) {
            aList.add(sc.nextInt());
        }
        List<Integer> sortedList = aList.stream().sorted(reverseOrder()).collect(Collectors.toList());
        int max = sortedList.get(0);

        for (int i = 0; i < n; i++) {
            int tempA = aList.get(i);
            if (tempA == max) {
                System.out.println(sortedList.get(1));
            } else {
                System.out.println(max);
            }
        }
    }
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

import static java.util.Comparator.reverseOrder;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> aList = new ArrayList();
        for (int i = 1; i <= n; i++) {
            aList.add(sc.nextInt());
        }
        List<Integer> sortedList = aList.stream().sorted(reverseOrder()).collect(Collectors.toList());
        int max = sortedList.get(0);

        for (int i = 0; i < n; i++) {
            int tempA = aList.get(i);
            if (tempA == max) {
                System.out.println(sortedList.get(1));
            } else {
                System.out.println(max);
            }
        }
    }
}