import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        // 元配列は出力で使いたいのでとっておく
        Integer[] copied = new Integer[n];
        for (int i = 0; i < n; i++) {
            copied[i] = a[i];
        }
        Arrays.sort(copied, Comparator.reverseOrder());

        int max = copied[0];
        int nxt = copied[1];

        // 規約通りにシミュレーション
        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(nxt);
            } else {
                System.out.println(max);
            }
        }
    }
}
 import java.util.Arrays; Arrays java.util import java.util.Comparator; Comparator java.util 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();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        // 元配列は出力で使いたいのでとっておく
        Integer[] copied = new Integer[n];
        for (int i = 0; i < n; i++) {
            copied[i] = a[i];
        }
        Arrays.sort(copied, Comparator.reverseOrder());

        int max = copied[0];
        int nxt = copied[1];

        // 規約通りにシミュレーション
        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(nxt);
            } else {
                System.out.println(max);
            }
        }
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        // 元配列は出力で使いたいのでとっておく
        Integer[] copied = new Integer[n];
        for (int i = 0; i < n; i++) {
            copied[i] = a[i];
        }
        Arrays.sort(copied, Comparator.reverseOrder());

        int max = copied[0];
        int nxt = copied[1];

        // 規約通りにシミュレーション
        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(nxt);
            } else {
                System.out.println(max);
            }
        }
    } main {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        // 元配列は出力で使いたいのでとっておく
        Integer[] copied = new Integer[n];
        for (int i = 0; i < n; i++) {
            copied[i] = a[i];
        }
        Arrays.sort(copied, Comparator.reverseOrder());

        int max = copied[0];
        int nxt = copied[1];

        // 規約通りにシミュレーション
        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(nxt);
            } else {
                System.out.println(max);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc 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 Integer[] copied = new Integer[n]; copied new Integer[n] n for (int i = 0; i < n; i++) {
            copied[i] = a[i];
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            copied[i] = a[i];
        } {
            copied[i] = a[i];
        } copied[i] = a[i] copied[i] copied i a[i] a i Arrays.sort(copied, Comparator.reverseOrder()) Arrays.sort Arrays copied Comparator.reverseOrder() Comparator.reverseOrder Comparator int max = copied[0]; max copied[0] copied 0 int nxt = copied[1]; nxt copied[1] copied 1 for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(nxt);
            } 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(nxt);
            } else {
                System.out.println(max);
            }
        } {
            if (a[i] == max) {
                System.out.println(nxt);
            } else {
                System.out.println(max);
            }
        } if (a[i] == max) {
                System.out.println(nxt);
            } else {
                System.out.println(max);
            } a[i] == max a[i] a i max {
                System.out.println(nxt);
            } System.out.println(nxt) System.out.println System.out System System.out nxt {
                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 sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        // 元配列は出力で使いたいのでとっておく
        Integer[] copied = new Integer[n];
        for (int i = 0; i < n; i++) {
            copied[i] = a[i];
        }
        Arrays.sort(copied, Comparator.reverseOrder());

        int max = copied[0];
        int nxt = copied[1];

        // 規約通りにシミュレーション
        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(nxt);
            } else {
                System.out.println(max);
            }
        }
    }
} public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        // 元配列は出力で使いたいのでとっておく
        Integer[] copied = new Integer[n];
        for (int i = 0; i < n; i++) {
            copied[i] = a[i];
        }
        Arrays.sort(copied, Comparator.reverseOrder());

        int max = copied[0];
        int nxt = copied[1];

        // 規約通りにシミュレーション
        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(nxt);
            } else {
                System.out.println(max);
            }
        }
    }
} Main
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        // 元配列は出力で使いたいのでとっておく
        Integer[] copied = new Integer[n];
        for (int i = 0; i < n; i++) {
            copied[i] = a[i];
        }
        Arrays.sort(copied, Comparator.reverseOrder());

        int max = copied[0];
        int nxt = copied[1];

        // 規約通りにシミュレーション
        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(nxt);
            } else {
                System.out.println(max);
            }
        }
    }
}

