import java.util.*;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        List<Integer> A = new ArrayList<>();
        for (int i = 0; i < N; i++) A.add(sc.nextInt());

        List<Integer> ASorted = new ArrayList<>(A);
        ASorted.sort(Comparator.reverseOrder());
        int max = ASorted.get(0);
        int secondLargest = ASorted.get(1);

        for (int i = 0; i < N; i++) {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            else
                System.out.println(max);
        }



    }
} import java.util.*; util.* java import java.util.stream.IntStream; IntStream java.util.stream public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        List<Integer> A = new ArrayList<>();
        for (int i = 0; i < N; i++) A.add(sc.nextInt());

        List<Integer> ASorted = new ArrayList<>(A);
        ASorted.sort(Comparator.reverseOrder());
        int max = ASorted.get(0);
        int secondLargest = ASorted.get(1);

        for (int i = 0; i < N; i++) {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            else
                System.out.println(max);
        }



    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        List<Integer> A = new ArrayList<>();
        for (int i = 0; i < N; i++) A.add(sc.nextInt());

        List<Integer> ASorted = new ArrayList<>(A);
        ASorted.sort(Comparator.reverseOrder());
        int max = ASorted.get(0);
        int secondLargest = ASorted.get(1);

        for (int i = 0; i < N; i++) {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            else
                System.out.println(max);
        }



    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        List<Integer> A = new ArrayList<>();
        for (int i = 0; i < N; i++) A.add(sc.nextInt());

        List<Integer> ASorted = new ArrayList<>(A);
        ASorted.sort(Comparator.reverseOrder());
        int max = ASorted.get(0);
        int secondLargest = ASorted.get(1);

        for (int i = 0; i < N; i++) {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            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> A = new ArrayList<>(); A new ArrayList<>() for (int i = 0; i < N; i++) A.add(sc.nextInt()); int i = 0; int i = 0; i 0 i < N i N i++ i++ i A.add(sc.nextInt()); A.add(sc.nextInt()) A.add A sc.nextInt() sc.nextInt sc List<Integer> ASorted = new ArrayList<>(A); ASorted new ArrayList<>(A) ASorted.sort(Comparator.reverseOrder()) ASorted.sort ASorted Comparator.reverseOrder() Comparator.reverseOrder Comparator int max = ASorted.get(0); max ASorted.get(0) ASorted.get ASorted 0 int secondLargest = ASorted.get(1); secondLargest ASorted.get(1) ASorted.get ASorted 1 for (int i = 0; i < N; i++) {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            else
                System.out.println(max);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            else
                System.out.println(max);
        } {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            else
                System.out.println(max);
        } if (A.get(i) == max)
                System.out.println(secondLargest);
            else
                System.out.println(max); A.get(i) == max A.get(i) A.get A i max System.out.println(secondLargest) System.out.println System.out System System.out secondLargest 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> A = new ArrayList<>();
        for (int i = 0; i < N; i++) A.add(sc.nextInt());

        List<Integer> ASorted = new ArrayList<>(A);
        ASorted.sort(Comparator.reverseOrder());
        int max = ASorted.get(0);
        int secondLargest = ASorted.get(1);

        for (int i = 0; i < N; i++) {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            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> A = new ArrayList<>();
        for (int i = 0; i < N; i++) A.add(sc.nextInt());

        List<Integer> ASorted = new ArrayList<>(A);
        ASorted.sort(Comparator.reverseOrder());
        int max = ASorted.get(0);
        int secondLargest = ASorted.get(1);

        for (int i = 0; i < N; i++) {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            else
                System.out.println(max);
        }



    }
} Main
import java.util.*;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        List<Integer> A = new ArrayList<>();
        for (int i = 0; i < N; i++) A.add(sc.nextInt());

        List<Integer> ASorted = new ArrayList<>(A);
        ASorted.sort(Comparator.reverseOrder());
        int max = ASorted.get(0);
        int secondLargest = ASorted.get(1);

        for (int i = 0; i < N; i++) {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            else
                System.out.println(max);
        }



    }
}
