import java.util.*;
import java.io.*;

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

        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int max = -1;
        int max_index = -1;
        int second = -1;
        int second_index = -1;
        for (int i = 0; i < N; i++) {
            if (max < A[i]) {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } else if (second < A[i]) {
                second = A[i];
                second_index = i;
            }
        }

        for (int i = 0; i < N; i++) {
            if (max_index == i) {
                out.printf("%d\n", A[second_index]);
            }
            else {
                out.printf("%d\n", A[max_index]);
            }
        }
        out.flush();
    }
} import java.util.*; util.* java import java.io.*; io.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int max = -1;
        int max_index = -1;
        int second = -1;
        int second_index = -1;
        for (int i = 0; i < N; i++) {
            if (max < A[i]) {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } else if (second < A[i]) {
                second = A[i];
                second_index = i;
            }
        }

        for (int i = 0; i < N; i++) {
            if (max_index == i) {
                out.printf("%d\n", A[second_index]);
            }
            else {
                out.printf("%d\n", A[max_index]);
            }
        }
        out.flush();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int max = -1;
        int max_index = -1;
        int second = -1;
        int second_index = -1;
        for (int i = 0; i < N; i++) {
            if (max < A[i]) {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } else if (second < A[i]) {
                second = A[i];
                second_index = i;
            }
        }

        for (int i = 0; i < N; i++) {
            if (max_index == i) {
                out.printf("%d\n", A[second_index]);
            }
            else {
                out.printf("%d\n", A[max_index]);
            }
        }
        out.flush();
    } main {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int max = -1;
        int max_index = -1;
        int second = -1;
        int second_index = -1;
        for (int i = 0; i < N; i++) {
            if (max < A[i]) {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } else if (second < A[i]) {
                second = A[i];
                second_index = i;
            }
        }

        for (int i = 0; i < N; i++) {
            if (max_index == i) {
                out.printf("%d\n", A[second_index]);
            }
            else {
                out.printf("%d\n", A[max_index]);
            }
        }
        out.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] A = new int[N]; A new int[N] N for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = Integer.parseInt(sc.next());
        } {
            A[i] = Integer.parseInt(sc.next());
        } A[i] = Integer.parseInt(sc.next()) A[i] A i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int max = -1; max -1 1 int max_index = -1; max_index -1 1 int second = -1; second -1 1 int second_index = -1; second_index -1 1 for (int i = 0; i < N; i++) {
            if (max < A[i]) {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } else if (second < A[i]) {
                second = A[i];
                second_index = i;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (max < A[i]) {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } else if (second < A[i]) {
                second = A[i];
                second_index = i;
            }
        } {
            if (max < A[i]) {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } else if (second < A[i]) {
                second = A[i];
                second_index = i;
            }
        } if (max < A[i]) {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } else if (second < A[i]) {
                second = A[i];
                second_index = i;
            } max < A[i] max A[i] A i {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } second = max second max second_index = max_index second_index max_index max = A[i] max A[i] A i max_index = i max_index i if (second < A[i]) {
                second = A[i];
                second_index = i;
            } second < A[i] second A[i] A i {
                second = A[i];
                second_index = i;
            } second = A[i] second A[i] A i second_index = i second_index i for (int i = 0; i < N; i++) {
            if (max_index == i) {
                out.printf("%d\n", A[second_index]);
            }
            else {
                out.printf("%d\n", A[max_index]);
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (max_index == i) {
                out.printf("%d\n", A[second_index]);
            }
            else {
                out.printf("%d\n", A[max_index]);
            }
        } {
            if (max_index == i) {
                out.printf("%d\n", A[second_index]);
            }
            else {
                out.printf("%d\n", A[max_index]);
            }
        } if (max_index == i) {
                out.printf("%d\n", A[second_index]);
            }
            else {
                out.printf("%d\n", A[max_index]);
            } max_index == i max_index i {
                out.printf("%d\n", A[second_index]);
            } out.printf("%d\n", A[second_index]) out.printf out "%d\n" A[second_index] A second_index {
                out.printf("%d\n", A[max_index]);
            } out.printf("%d\n", A[max_index]) out.printf out "%d\n" A[max_index] A max_index out.flush() out.flush out String[] args args
import java.util.*;
import java.io.*;

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

        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int max = -1;
        int max_index = -1;
        int second = -1;
        int second_index = -1;
        for (int i = 0; i < N; i++) {
            if (max < A[i]) {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } else if (second < A[i]) {
                second = A[i];
                second_index = i;
            }
        }

        for (int i = 0; i < N; i++) {
            if (max_index == i) {
                out.printf("%d\n", A[second_index]);
            }
            else {
                out.printf("%d\n", A[max_index]);
            }
        }
        out.flush();
    }
}
