import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            int max1 = 0, max2 = 0;

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            }

            System.out.println(sb.toString());
        }
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            int max1 = 0, max2 = 0;

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            }

            System.out.println(sb.toString());
        }
    }

} Main public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            int max1 = 0, max2 = 0;

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            }

            System.out.println(sb.toString());
        }
    } main {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            int max1 = 0, max2 = 0;

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            }

            System.out.println(sb.toString());
        }
    } try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            int max1 = 0, max2 = 0;

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            }

            System.out.println(sb.toString());
        } {
            int N = Integer.parseInt(reader.readLine());

            int max1 = 0, max2 = 0;

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            }

            System.out.println(sb.toString());
        } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(reader.readLine()); N Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader int max1 = 0 max1 0 max2 = 0; max2 0 int[] A = new int[N]; A new int[N] N for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            } {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            } A[i] = Integer.parseInt(reader.readLine()) A[i] A i Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader if (A[i] > max2) {
                    max2 = A[i];
                } A[i] > max2 A[i] A i max2 {
                    max2 = A[i];
                } max2 = A[i] max2 A[i] A i if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                } A[i] > max1 A[i] A i max1 {
                    max2 = max1;
                    max1 = A[i];
                } max2 = max1 max2 max1 max1 = A[i] max1 A[i] A i StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < N; i++) {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            } {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            } if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                } A[i] != max1 A[i] A i max1 {
                    sb.append(max1);
                } sb.append(max1) sb.append sb max1 {
                    sb.append(max2);
                } sb.append(max2) sb.append sb max2 sb.append("\n") sb.append sb "\n" System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb String[] args args public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            int max1 = 0, max2 = 0;

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            }

            System.out.println(sb.toString());
        }
    }

} public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            int max1 = 0, max2 = 0;

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            }

            System.out.println(sb.toString());
        }
    }

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            int max1 = 0, max2 = 0;

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());

                if (A[i] > max2) {
                    max2 = A[i];
                }
                if (A[i] > max1) {
                    max2 = max1;
                    max1 = A[i];
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (A[i] != max1) {
                    sb.append(max1);
                } else {
                    sb.append(max2);
                }
                sb.append("\n");
            }

            System.out.println(sb.toString());
        }
    }

}
