import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] a = new Integer[n];
        int[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] a = new Integer[n];
        int[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            }
        }
    }
} Main public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] a = new Integer[n];
        int[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            }
        }
    } main {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] a = new Integer[n];
        int[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc Integer[] a = new Integer[n]; a new Integer[n] n int[] max = new int[2]; max new int[2] 2 for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = sc.nextInt();
            if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            }
        } {
            a[i] = sc.nextInt();
            if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            }
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            } a[i] >= max[1] a[i] a i max[1] max 1 {
                max[0] = i;
                max[1] = a[i];
            } max[0] = i max[0] max 0 i max[1] = a[i] max[1] max 1 a[i] a i for (int i = 0; i < n; i++) {
            if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            }
        } {
            if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            }
        } if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            } i == max[0] i max[0] max 0 {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } int result = 0; result 0 for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                } {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                } if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    } a[j] >= result && max[0] != j a[j] >= result a[j] a j result max[0] != j max[0] max 0 j {
                        result = a[j];
                    } result = a[j] result a[j] a j System.out.println(result) System.out.println System.out System System.out result {
                System.out.println(max[1]);
            } System.out.println(max[1]) System.out.println System.out System System.out max[1] max 1 String args[] args public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] a = new Integer[n];
        int[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            }
        }
    }
} public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] a = new Integer[n];
        int[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] a = new Integer[n];
        int[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] >= max[1]) {
                max[0] = i;
                max[1] = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == max[0]) {
                int result = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] >= result && max[0] != j) {
                        result = a[j];
                    }
                }
                System.out.println(result);
            } else {
                System.out.println(max[1]);
            }
        }
    }
}
