

import java.io.*;
import java.util.StringTokenizer;

public class Main {
    // https://atcoder.jp/contests/abc134/tasks/abc134_c
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int[] right = new int[n];
            int[] left = new int[n];
            right[n-1] = 0;
            left[0] = 0;
            for (int i = n-2; i >= 0; i--) {
                right[i] = Math.max(arr[i+1], right[i+1]);
            }
            for (int i = 1; i < n; i++) {
                left[i] = Math.max(arr[i-1], left[i-1]);
            }
            for (int i = 0; i < n; i++) {
                out.println(Math.max(right[i], left[i]));
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
} import java.io.*; io.* java import java.util.StringTokenizer; StringTokenizer java.util public class Main {
    // https://atcoder.jp/contests/abc134/tasks/abc134_c
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int[] right = new int[n];
            int[] left = new int[n];
            right[n-1] = 0;
            left[0] = 0;
            for (int i = n-2; i >= 0; i--) {
                right[i] = Math.max(arr[i+1], right[i+1]);
            }
            for (int i = 1; i < n; i++) {
                left[i] = Math.max(arr[i-1], left[i-1]);
            }
            for (int i = 0; i < n; i++) {
                out.println(Math.max(right[i], left[i]));
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
} Main // https://atcoder.jp/contests/abc134/tasks/abc134_c
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) Task solver = new Task(); solver new Task() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int[] right = new int[n];
            int[] left = new int[n];
            right[n-1] = 0;
            left[0] = 0;
            for (int i = n-2; i >= 0; i--) {
                right[i] = Math.max(arr[i+1], right[i+1]);
            }
            for (int i = 1; i < n; i++) {
                left[i] = Math.max(arr[i-1], left[i-1]);
            }
            for (int i = 0; i < n; i++) {
                out.println(Math.max(right[i], left[i]));
            }
        }
    } Task public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int[] right = new int[n];
            int[] left = new int[n];
            right[n-1] = 0;
            left[0] = 0;
            for (int i = n-2; i >= 0; i--) {
                right[i] = Math.max(arr[i+1], right[i+1]);
            }
            for (int i = 1; i < n; i++) {
                left[i] = Math.max(arr[i-1], left[i-1]);
            }
            for (int i = 0; i < n; i++) {
                out.println(Math.max(right[i], left[i]));
            }
        } solve {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int[] right = new int[n];
            int[] left = new int[n];
            right[n-1] = 0;
            left[0] = 0;
            for (int i = n-2; i >= 0; i--) {
                right[i] = Math.max(arr[i+1], right[i+1]);
            }
            for (int i = 1; i < n; i++) {
                left[i] = Math.max(arr[i-1], left[i-1]);
            }
            for (int i = 0; i < n; i++) {
                out.println(Math.max(right[i], left[i]));
            }
        } int n = in.nextInt(); n in.nextInt() in.nextInt in int[] arr = new int[n]; arr new int[n] n for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                arr[i] = in.nextInt();
            } {
                arr[i] = in.nextInt();
            } arr[i] = in.nextInt() arr[i] arr i in.nextInt() in.nextInt in int[] right = new int[n]; right new int[n] n int[] left = new int[n]; left new int[n] n right[n-1] = 0 right[n-1] right n-1 n 1 0 left[0] = 0 left[0] left 0 0 for (int i = n-2; i >= 0; i--) {
                right[i] = Math.max(arr[i+1], right[i+1]);
            } int i = n-2; int i = n-2; i n-2 n 2 i >= 0 i 0 i-- i-- i {
                right[i] = Math.max(arr[i+1], right[i+1]);
            } {
                right[i] = Math.max(arr[i+1], right[i+1]);
            } right[i] = Math.max(arr[i+1], right[i+1]) right[i] right i Math.max(arr[i+1], right[i+1]) Math.max Math arr[i+1] arr i+1 i 1 right[i+1] right i+1 i 1 for (int i = 1; i < n; i++) {
                left[i] = Math.max(arr[i-1], left[i-1]);
            } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
                left[i] = Math.max(arr[i-1], left[i-1]);
            } {
                left[i] = Math.max(arr[i-1], left[i-1]);
            } left[i] = Math.max(arr[i-1], left[i-1]) left[i] left i Math.max(arr[i-1], left[i-1]) Math.max Math arr[i-1] arr i-1 i 1 left[i-1] left i-1 i 1 for (int i = 0; i < n; i++) {
                out.println(Math.max(right[i], left[i]));
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                out.println(Math.max(right[i], left[i]));
            } {
                out.println(Math.max(right[i], left[i]));
            } out.println(Math.max(right[i], left[i])) out.println out Math.max(right[i], left[i]) Math.max Math right[i] right i left[i] left i int testNumber testNumber InputReader in in PrintWriter out out static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    } InputReader public BufferedReader reader; reader public StringTokenizer tokenizer; tokenizer public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        } InputReader {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        } reader = new BufferedReader(new InputStreamReader(stream), 32768) reader new BufferedReader(new InputStreamReader(stream), 32768) tokenizer = null tokenizer null InputStream stream stream public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } next {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } IOException e {
                    throw new RuntimeException(e);
                } throw new RuntimeException(e); new RuntimeException(e) {
                    tokenizer = new StringTokenizer(reader.readLine());
                } tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public long nextLong() {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public double nextDouble() {
            return Double.parseDouble(next());
        } nextDouble {
            return Double.parseDouble(next());
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public char nextChar() {
            return next().charAt(0);
        } nextChar {
            return next().charAt(0);
        } return next().charAt(0); next().charAt(0) next().charAt next() next 0 public String nextLine() throws IOException {
            return reader.readLine().trim();
        } nextLine {
            return reader.readLine().trim();
        } return reader.readLine().trim(); reader.readLine().trim() reader.readLine().trim reader.readLine() reader.readLine reader public class Main {
    // https://atcoder.jp/contests/abc134/tasks/abc134_c
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int[] right = new int[n];
            int[] left = new int[n];
            right[n-1] = 0;
            left[0] = 0;
            for (int i = n-2; i >= 0; i--) {
                right[i] = Math.max(arr[i+1], right[i+1]);
            }
            for (int i = 1; i < n; i++) {
                left[i] = Math.max(arr[i-1], left[i-1]);
            }
            for (int i = 0; i < n; i++) {
                out.println(Math.max(right[i], left[i]));
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
} public class Main {
    // https://atcoder.jp/contests/abc134/tasks/abc134_c
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int[] right = new int[n];
            int[] left = new int[n];
            right[n-1] = 0;
            left[0] = 0;
            for (int i = n-2; i >= 0; i--) {
                right[i] = Math.max(arr[i+1], right[i+1]);
            }
            for (int i = 1; i < n; i++) {
                left[i] = Math.max(arr[i-1], left[i-1]);
            }
            for (int i = 0; i < n; i++) {
                out.println(Math.max(right[i], left[i]));
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
} Main


import java.io.*;
import java.util.StringTokenizer;

public class Main {
    // https://atcoder.jp/contests/abc134/tasks/abc134_c
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int[] right = new int[n];
            int[] left = new int[n];
            right[n-1] = 0;
            left[0] = 0;
            for (int i = n-2; i >= 0; i--) {
                right[i] = Math.max(arr[i+1], right[i+1]);
            }
            for (int i = 1; i < n; i++) {
                left[i] = Math.max(arr[i-1], left[i-1]);
            }
            for (int i = 0; i < n; i++) {
                out.println(Math.max(right[i], left[i]));
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}
