
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int[] A = new int[N];
        int max = 0;
        int second = 0;

        for (int i = 0 ; i < N ; i++) {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        }

        for (int i = 0 ; i < N ; i++) {
            if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int max = 0;
        int second = 0;

        for (int i = 0 ; i < N ; i++) {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        }

        for (int i = 0 ; i < N ; i++) {
            if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int max = 0;
        int second = 0;

        for (int i = 0 ; i < N ; i++) {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        }

        for (int i = 0 ; i < N ; i++) {
            if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            }
        }
    } main {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int max = 0;
        int second = 0;

        for (int i = 0 ; i < N ; i++) {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        }

        for (int i = 0 ; i < N ; i++) {
            if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            }
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] A = new int[N]; A new int[N] N int max = 0; max 0 int second = 0; second 0 for (int i = 0 ; i < N ; i++) {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        } int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        } {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        } A[i] = scanner.nextInt() A[i] A i scanner.nextInt() scanner.nextInt scanner if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            } A[i] >= max A[i] A i max {
                second = max;
                max = A[i];
            } second = max second max max = A[i] max A[i] A i if (A[i] >= second) {
                second = A[i];
            } A[i] >= second A[i] A i second {
                second = A[i];
            } second = A[i] second A[i] A i for (int i = 0 ; i < N ; i++) {
            if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            }
        } int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
            if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            }
        } {
            if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            }
        } if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            } A[i] == max A[i] A i max {
                System.out.println(second);
            } System.out.println(second) System.out.println System.out System System.out second {
                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 scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int max = 0;
        int second = 0;

        for (int i = 0 ; i < N ; i++) {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        }

        for (int i = 0 ; i < N ; i++) {
            if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int max = 0;
        int second = 0;

        for (int i = 0 ; i < N ; i++) {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        }

        for (int i = 0 ; i < N ; i++) {
            if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            }
        }
    }
} Main

import java.util.Scanner;

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

        int N = scanner.nextInt();
        int[] A = new int[N];
        int max = 0;
        int second = 0;

        for (int i = 0 ; i < N ; i++) {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        }

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