import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

        final int N = sc.nextInt();

        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int max1 = IntStream.of(A).max().getAsInt();
        int max2 = IntStream.of(A).sorted().limit(A.length-1).max().getAsInt();
        for (int i = 0; i < N; i++) {
            System.out.println(A[i] == max1 ? max2 : max1);
        }
    }
} import java.util.Scanner; Scanner java.util import java.util.stream.IntStream; IntStream java.util.stream public class Main {

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

        final int N = sc.nextInt();

        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int max1 = IntStream.of(A).max().getAsInt();
        int max2 = IntStream.of(A).sorted().limit(A.length-1).max().getAsInt();
        for (int i = 0; i < N; i++) {
            System.out.println(A[i] == max1 ? max2 : max1);
        }
    }
} Main public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int max1 = IntStream.of(A).max().getAsInt();
        int max2 = IntStream.of(A).sorted().limit(A.length-1).max().getAsInt();
        for (int i = 0; i < N; i++) {
            System.out.println(A[i] == max1 ? max2 : max1);
        }
    } main {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int max1 = IntStream.of(A).max().getAsInt();
        int max2 = IntStream.of(A).sorted().limit(A.length-1).max().getAsInt();
        for (int i = 0; i < N; i++) {
            System.out.println(A[i] == max1 ? max2 : max1);
        }
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc final int[] A = new int[N]; A new int[N] N for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = sc.nextInt();
        } {
            A[i] = sc.nextInt();
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int max1 = IntStream.of(A).max().getAsInt(); max1 IntStream.of(A).max().getAsInt() IntStream.of(A).max().getAsInt IntStream.of(A).max() IntStream.of(A).max IntStream.of(A) IntStream.of IntStream A int max2 = IntStream.of(A).sorted().limit(A.length-1).max().getAsInt(); max2 IntStream.of(A).sorted().limit(A.length-1).max().getAsInt() IntStream.of(A).sorted().limit(A.length-1).max().getAsInt IntStream.of(A).sorted().limit(A.length-1).max() IntStream.of(A).sorted().limit(A.length-1).max IntStream.of(A).sorted().limit(A.length-1) IntStream.of(A).sorted().limit IntStream.of(A).sorted() IntStream.of(A).sorted IntStream.of(A) IntStream.of IntStream A A.length-1 A.length A A.length 1 for (int i = 0; i < N; i++) {
            System.out.println(A[i] == max1 ? max2 : max1);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            System.out.println(A[i] == max1 ? max2 : max1);
        } {
            System.out.println(A[i] == max1 ? max2 : max1);
        } System.out.println(A[i] == max1 ? max2 : max1) System.out.println System.out System System.out A[i] == max1 ? max2 : max1 A[i] == max1 A[i] A i max1 max2 max1 String[] args args public class Main {

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

        final int N = sc.nextInt();

        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int max1 = IntStream.of(A).max().getAsInt();
        int max2 = IntStream.of(A).sorted().limit(A.length-1).max().getAsInt();
        for (int i = 0; i < N; i++) {
            System.out.println(A[i] == max1 ? max2 : max1);
        }
    }
} public class Main {

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

        final int N = sc.nextInt();

        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int max1 = IntStream.of(A).max().getAsInt();
        int max2 = IntStream.of(A).sorted().limit(A.length-1).max().getAsInt();
        for (int i = 0; i < N; i++) {
            System.out.println(A[i] == max1 ? max2 : max1);
        }
    }
} Main
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

        final int N = sc.nextInt();

        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int max1 = IntStream.of(A).max().getAsInt();
        int max2 = IntStream.of(A).sorted().limit(A.length-1).max().getAsInt();
        for (int i = 0; i < N; i++) {
            System.out.println(A[i] == max1 ? max2 : max1);
        }
    }
}
