import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int[] value = new int[num];
        int a = 0;
        int b = 0;
        for (int i = 0; i < num; i++){
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        }
        in.close();
        for (int i = 0; i < num; i++) {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int[] value = new int[num];
        int a = 0;
        int b = 0;
        for (int i = 0; i < num; i++){
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        }
        in.close();
        for (int i = 0; i < num; i++) {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int[] value = new int[num];
        int a = 0;
        int b = 0;
        for (int i = 0; i < num; i++){
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        }
        in.close();
        for (int i = 0; i < num; i++) {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        }
    } main {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int[] value = new int[num];
        int a = 0;
        int b = 0;
        for (int i = 0; i < num; i++){
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        }
        in.close();
        for (int i = 0; i < num; i++) {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        }
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int num = in.nextInt(); num in.nextInt() in.nextInt in int[] value = new int[num]; value new int[num] num int a = 0; a 0 int b = 0; b 0 for (int i = 0; i < num; i++){
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        } int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        } {
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        } value[i] = in.nextInt() value[i] value i in.nextInt() in.nextInt in if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            } a < value[i] a value[i] value i {
                b = a;
                a = value[i];
            } b = a b a a = value[i] a value[i] value i if (b < value[i]) {
                b = value[i];
            } b < value[i] b value[i] value i {
                b = value[i];
            } b = value[i] b value[i] value i in.close() in.close in for (int i = 0; i < num; i++) {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        } int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        } {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        } if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            } a == value[i] a value[i] value i {
                System.out.println(b);
            } System.out.println(b) System.out.println System.out System System.out b {
                System.out.println(a);
            } System.out.println(a) System.out.println System.out System System.out a String[] args args public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int[] value = new int[num];
        int a = 0;
        int b = 0;
        for (int i = 0; i < num; i++){
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        }
        in.close();
        for (int i = 0; i < num; i++) {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int[] value = new int[num];
        int a = 0;
        int b = 0;
        for (int i = 0; i < num; i++){
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        }
        in.close();
        for (int i = 0; i < num; i++) {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int[] value = new int[num];
        int a = 0;
        int b = 0;
        for (int i = 0; i < num; i++){
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        }
        in.close();
        for (int i = 0; i < num; i++) {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        }
    }
}
