import java.util.Arrays;
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];
        int max = 0;
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        }

        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            b[i] = a[i];
        }

        Arrays.sort(b);

        int maxNum = b[b.length - 1];
        int secondNum = b[b.length - 2];
        for (int i = 0 ; i < n ; i++) {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        }

    }

} import java.util.Arrays; Arrays 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];
        int max = 0;
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        }

        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            b[i] = a[i];
        }

        Arrays.sort(b);

        int maxNum = b[b.length - 1];
        int secondNum = b[b.length - 2];
        for (int i = 0 ; i < n ; i++) {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        }

    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int max = 0;
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        }

        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            b[i] = a[i];
        }

        Arrays.sort(b);

        int maxNum = b[b.length - 1];
        int secondNum = b[b.length - 2];
        for (int i = 0 ; i < n ; i++) {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        }

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

        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            b[i] = a[i];
        }

        Arrays.sort(b);

        int maxNum = b[b.length - 1];
        int secondNum = b[b.length - 2];
        for (int i = 0 ; i < n ; i++) {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        }

    } 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 int max = 0; max 0 for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        } {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc max = Math.max(max, a[i]) max Math.max(max, a[i]) Math.max Math max a[i] a i int[] b = new int[n]; b new int[n] n for (int i = 0 ; i < n ; i++) {
            b[i] = a[i];
        } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
            b[i] = a[i];
        } {
            b[i] = a[i];
        } b[i] = a[i] b[i] b i a[i] a i Arrays.sort(b) Arrays.sort Arrays b int maxNum = b[b.length - 1]; maxNum b[b.length - 1] b b.length - 1 b.length b b.length 1 int secondNum = b[b.length - 2]; secondNum b[b.length - 2] b b.length - 2 b.length b b.length 2 for (int i = 0 ; i < n ; i++) {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        } {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        } if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            } a[i] == maxNum a[i] a i maxNum {
                System.out.println(secondNum);
            } System.out.println(secondNum) System.out.println System.out System System.out secondNum {
                System.out.println(maxNum);
            } System.out.println(maxNum) System.out.println System.out System System.out maxNum 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];
        int max = 0;
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        }

        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            b[i] = a[i];
        }

        Arrays.sort(b);

        int maxNum = b[b.length - 1];
        int secondNum = b[b.length - 2];
        for (int i = 0 ; i < n ; i++) {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        }

    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int max = 0;
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        }

        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            b[i] = a[i];
        }

        Arrays.sort(b);

        int maxNum = b[b.length - 1];
        int secondNum = b[b.length - 2];
        for (int i = 0 ; i < n ; i++) {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        }

    }

} Main
import java.util.Arrays;
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];
        int max = 0;
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        }

        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            b[i] = a[i];
        }

        Arrays.sort(b);

        int maxNum = b[b.length - 1];
        int secondNum = b[b.length - 2];
        for (int i = 0 ; i < n ; i++) {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        }

    }

}
