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 = Integer.parseInt(sc.next());
        Integer[] ary = new Integer[N];
        for (int i = 0; i < N; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        }
        Integer[] sortAry = ary.clone();
        Arrays.sort(sortAry, Comparator.reverseOrder());
        int maxNum = sortAry[0];
        int secondNum = sortAry[1];
        for (int i = 0; i < N; i++) {
            if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            }
        }
    }
} 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 = Integer.parseInt(sc.next());
        Integer[] ary = new Integer[N];
        for (int i = 0; i < N; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        }
        Integer[] sortAry = ary.clone();
        Arrays.sort(sortAry, Comparator.reverseOrder());
        int maxNum = sortAry[0];
        int secondNum = sortAry[1];
        for (int i = 0; i < N; i++) {
            if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        Integer[] ary = new Integer[N];
        for (int i = 0; i < N; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        }
        Integer[] sortAry = ary.clone();
        Arrays.sort(sortAry, Comparator.reverseOrder());
        int maxNum = sortAry[0];
        int secondNum = sortAry[1];
        for (int i = 0; i < N; i++) {
            if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        Integer[] ary = new Integer[N];
        for (int i = 0; i < N; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        }
        Integer[] sortAry = ary.clone();
        Arrays.sort(sortAry, Comparator.reverseOrder());
        int maxNum = sortAry[0];
        int secondNum = sortAry[1];
        for (int i = 0; i < N; i++) {
            if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc Integer[] ary = new Integer[N]; ary new Integer[N] N for (int i = 0; i < N; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        } {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        } int a = Integer.parseInt(sc.next()); a Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc ary[i] = a ary[i] ary i a Integer[] sortAry = ary.clone(); sortAry ary.clone() ary.clone ary Arrays.sort(sortAry, Comparator.reverseOrder()) Arrays.sort Arrays sortAry Comparator.reverseOrder() Comparator.reverseOrder Comparator int maxNum = sortAry[0]; maxNum sortAry[0] sortAry 0 int secondNum = sortAry[1]; secondNum sortAry[1] sortAry 1 for (int i = 0; i < N; i++) {
            if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            }
        } {
            if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            }
        } if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            } maxNum > ary[i] maxNum ary[i] ary i {
                System.out.println(maxNum);
            } System.out.println(maxNum) System.out.println System.out System System.out maxNum {
                System.out.println(secondNum);
            } System.out.println(secondNum) System.out.println System.out System System.out secondNum String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        Integer[] ary = new Integer[N];
        for (int i = 0; i < N; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        }
        Integer[] sortAry = ary.clone();
        Arrays.sort(sortAry, Comparator.reverseOrder());
        int maxNum = sortAry[0];
        int secondNum = sortAry[1];
        for (int i = 0; i < N; i++) {
            if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            }
        }
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        Integer[] ary = new Integer[N];
        for (int i = 0; i < N; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        }
        Integer[] sortAry = ary.clone();
        Arrays.sort(sortAry, Comparator.reverseOrder());
        int maxNum = sortAry[0];
        int secondNum = sortAry[1];
        for (int i = 0; i < N; i++) {
            if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            }
        }
    }
} 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 = Integer.parseInt(sc.next());
        Integer[] ary = new Integer[N];
        for (int i = 0; i < N; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
        }
        Integer[] sortAry = ary.clone();
        Arrays.sort(sortAry, Comparator.reverseOrder());
        int maxNum = sortAry[0];
        int secondNum = sortAry[1];
        for (int i = 0; i < N; i++) {
            if (maxNum > ary[i]) {
                System.out.println(maxNum);
            } else {
                System.out.println(secondNum);
            }
        }
    }
}