import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:11-

            int n = sc.nextInt();
            int[] vs = new int[n];
            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int[] ml = new int[n];
            ml[0] = vs[0];
            for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            }

            int[] mr = new int[n];
            mr[n - 1] = vs[n - 1];
            for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            }

            for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            }

        }
    }
} import java.io.BufferedInputStream; BufferedInputStream java.io import java.io.BufferedOutputStream; BufferedOutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:11-

            int n = sc.nextInt();
            int[] vs = new int[n];
            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int[] ml = new int[n];
            ml[0] = vs[0];
            for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            }

            int[] mr = new int[n];
            mr[n - 1] = vs[n - 1];
            for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            }

            for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            }

        }
    }
} Main public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:11-

            int n = sc.nextInt();
            int[] vs = new int[n];
            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int[] ml = new int[n];
            ml[0] = vs[0];
            for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            }

            int[] mr = new int[n];
            mr[n - 1] = vs[n - 1];
            for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            }

            for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            }

        }
    } main {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:11-

            int n = sc.nextInt();
            int[] vs = new int[n];
            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int[] ml = new int[n];
            ml[0] = vs[0];
            for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            }

            int[] mr = new int[n];
            mr[n - 1] = vs[n - 1];
            for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            }

            for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            }

        }
    } try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:11-

            int n = sc.nextInt();
            int[] vs = new int[n];
            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int[] ml = new int[n];
            ml[0] = vs[0];
            for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            }

            int[] mr = new int[n];
            mr[n - 1] = vs[n - 1];
            for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            }

            for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            }

        } {

            Scanner sc = new Scanner(in);

            // 12:11-

            int n = sc.nextInt();
            int[] vs = new int[n];
            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int[] ml = new int[n];
            ml[0] = vs[0];
            for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            }

            int[] mr = new int[n];
            mr[n - 1] = vs[n - 1];
            for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            }

            for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            }

        } BufferedInputStream in = new BufferedInputStream(System.in) BufferedInputStream in = new BufferedInputStream(System.in) new BufferedInputStream(System.in) PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)) PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)) new PrintWriter(new BufferedOutputStream(System.out)) Scanner sc = new Scanner(in); sc new Scanner(in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] vs = new int[n]; vs new int[n] n for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < vs.length i vs.length vs vs.length i++ i++ i vs[i] = sc.nextInt(); vs[i] = sc.nextInt() vs[i] vs i sc.nextInt() sc.nextInt sc int[] ml = new int[n]; ml new int[n] n ml[0] = vs[0] ml[0] ml 0 vs[0] vs 0 for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            } int i = 1; int i = 1; i 1 i < ml.length i ml.length ml ml.length i++ i++ i {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            } {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            } ml[i] = Math.max(ml[i - 1], vs[i]) ml[i] ml i Math.max(ml[i - 1], vs[i]) Math.max Math ml[i - 1] ml i - 1 i 1 vs[i] vs i int[] mr = new int[n]; mr new int[n] n mr[n - 1] = vs[n - 1] mr[n - 1] mr n - 1 n 1 vs[n - 1] vs n - 1 n 1 for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            } int i = mr.length - 2; int i = mr.length - 2; i mr.length - 2 mr.length mr mr.length 2 i >= 0 i 0 i-- i-- i {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            } {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            } mr[i] = Math.max(mr[i + 1], vs[i]) mr[i] mr i Math.max(mr[i + 1], vs[i]) Math.max Math mr[i + 1] mr i + 1 i 1 vs[i] vs i for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            } int i = 0; int i = 0; i 0 i < vs.length i vs.length vs vs.length i++ i++ i {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            } {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            } if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                } i == 0 i 0 {
                    out.println(mr[i + 1]);
                } out.println(mr[i + 1]) out.println out mr[i + 1] mr i + 1 i 1 if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                } i == n - 1 i n - 1 n 1 {
                    out.println(ml[i - 1]);
                } out.println(ml[i - 1]) out.println out ml[i - 1] ml i - 1 i 1 {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                } out.println(Math.max(ml[i - 1], mr[i + 1])) out.println out Math.max(ml[i - 1], mr[i + 1]) Math.max Math ml[i - 1] ml i - 1 i 1 mr[i + 1] mr i + 1 i 1 String[] args args public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:11-

            int n = sc.nextInt();
            int[] vs = new int[n];
            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int[] ml = new int[n];
            ml[0] = vs[0];
            for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            }

            int[] mr = new int[n];
            mr[n - 1] = vs[n - 1];
            for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            }

            for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            }

        }
    }
} public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:11-

            int n = sc.nextInt();
            int[] vs = new int[n];
            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int[] ml = new int[n];
            ml[0] = vs[0];
            for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            }

            int[] mr = new int[n];
            mr[n - 1] = vs[n - 1];
            for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            }

            for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            }

        }
    }
} Main
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:11-

            int n = sc.nextInt();
            int[] vs = new int[n];
            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int[] ml = new int[n];
            ml[0] = vs[0];
            for (int i = 1; i < ml.length; i++) {
                ml[i] = Math.max(ml[i - 1], vs[i]);
            }

            int[] mr = new int[n];
            mr[n - 1] = vs[n - 1];
            for (int i = mr.length - 2; i >= 0; i--) {
                mr[i] = Math.max(mr[i + 1], vs[i]);
            }

            for (int i = 0; i < vs.length; i++) {
                if (i == 0) {
                    out.println(mr[i + 1]);
                } else if (i == n - 1) {
                    out.println(ml[i - 1]);
                } else {
                    out.println(Math.max(ml[i - 1], mr[i + 1]));
                }
            }

        }
    }
}
