import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CExceptionHandling solver = new CExceptionHandling();
        solver.solve(1, in, out);
        out.close();
    }

    static class CExceptionHandling {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            SegmentTree st = new SegmentTree(0, n - 1);
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            }

            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            }
        }

        class SegmentTree {
            int start;
            int end;
            SegmentTree leftTree;
            SegmentTree rightTree;
            int maxValue;

            public SegmentTree(int start, int end) {

                this.start = start;

                this.end = end;

                this.maxValue = Integer.MIN_VALUE;

                if (start == end) { // es una hoja

                    leftTree = rightTree = null;

                    return;

                }

                int mid = (start + end) / 2;

                leftTree = new SegmentTree(start, mid);
                rightTree = new SegmentTree(mid + 1, end);

            }

            public void set(int pos, int value) {
                // es una hoja, CASO BASE

                if (start == end) {

                    maxValue = value;

                    return;

                }

                int mid = (start + end) / 2;

                if (pos <= mid)

                    leftTree.set(pos, value);

                else

                    rightTree.set(pos, value);

                maxValue = Math.max(leftTree.maxValue, rightTree.maxValue);
            }

            public int getMax(int low, int high) {
                // [low,high] = [start,end]

                if (start == low && end == high)

                    return maxValue;

                int mid = (start + end) / 2;

                // [low,high] totalmente incluido en [start,mid]

                if (high <= mid)

                    return leftTree.getMax(low, high);

                // [low,high] totalmente incluido en [mid+1,end]

                if (low > mid)

                    return rightTree.getMax(low, high);

                // debemos dividir el intervalo en [low,mid] y [mid+1,high]

                int leftMin = leftTree.getMax(low, mid);

                int rightMin = rightTree.getMax(mid + 1, high);

                return Math.max(leftMin, rightMin);
            }

        }

    }

    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 int nextInt() {
            return Integer.parseInt(next());
        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.StringTokenizer; StringTokenizer java.util import java.io.IOException; IOException java.io import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.InputStream; InputStream java.io public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CExceptionHandling solver = new CExceptionHandling();
        solver.solve(1, in, out);
        out.close();
    }

    static class CExceptionHandling {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            SegmentTree st = new SegmentTree(0, n - 1);
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            }

            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            }
        }

        class SegmentTree {
            int start;
            int end;
            SegmentTree leftTree;
            SegmentTree rightTree;
            int maxValue;

            public SegmentTree(int start, int end) {

                this.start = start;

                this.end = end;

                this.maxValue = Integer.MIN_VALUE;

                if (start == end) { // es una hoja

                    leftTree = rightTree = null;

                    return;

                }

                int mid = (start + end) / 2;

                leftTree = new SegmentTree(start, mid);
                rightTree = new SegmentTree(mid + 1, end);

            }

            public void set(int pos, int value) {
                // es una hoja, CASO BASE

                if (start == end) {

                    maxValue = value;

                    return;

                }

                int mid = (start + end) / 2;

                if (pos <= mid)

                    leftTree.set(pos, value);

                else

                    rightTree.set(pos, value);

                maxValue = Math.max(leftTree.maxValue, rightTree.maxValue);
            }

            public int getMax(int low, int high) {
                // [low,high] = [start,end]

                if (start == low && end == high)

                    return maxValue;

                int mid = (start + end) / 2;

                // [low,high] totalmente incluido en [start,mid]

                if (high <= mid)

                    return leftTree.getMax(low, high);

                // [low,high] totalmente incluido en [mid+1,end]

                if (low > mid)

                    return rightTree.getMax(low, high);

                // debemos dividir el intervalo en [low,mid] y [mid+1,high]

                int leftMin = leftTree.getMax(low, mid);

                int rightMin = rightTree.getMax(mid + 1, high);

                return Math.max(leftMin, rightMin);
            }

        }

    }

    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 int nextInt() {
            return Integer.parseInt(next());
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CExceptionHandling solver = new CExceptionHandling();
        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);
        CExceptionHandling solver = new CExceptionHandling();
        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) CExceptionHandling solver = new CExceptionHandling(); solver new CExceptionHandling() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class CExceptionHandling {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            SegmentTree st = new SegmentTree(0, n - 1);
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            }

            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            }
        }

        class SegmentTree {
            int start;
            int end;
            SegmentTree leftTree;
            SegmentTree rightTree;
            int maxValue;

            public SegmentTree(int start, int end) {

                this.start = start;

                this.end = end;

                this.maxValue = Integer.MIN_VALUE;

                if (start == end) { // es una hoja

                    leftTree = rightTree = null;

                    return;

                }

                int mid = (start + end) / 2;

                leftTree = new SegmentTree(start, mid);
                rightTree = new SegmentTree(mid + 1, end);

            }

            public void set(int pos, int value) {
                // es una hoja, CASO BASE

                if (start == end) {

                    maxValue = value;

                    return;

                }

                int mid = (start + end) / 2;

                if (pos <= mid)

                    leftTree.set(pos, value);

                else

                    rightTree.set(pos, value);

                maxValue = Math.max(leftTree.maxValue, rightTree.maxValue);
            }

            public int getMax(int low, int high) {
                // [low,high] = [start,end]

                if (start == low && end == high)

                    return maxValue;

                int mid = (start + end) / 2;

                // [low,high] totalmente incluido en [start,mid]

                if (high <= mid)

                    return leftTree.getMax(low, high);

                // [low,high] totalmente incluido en [mid+1,end]

                if (low > mid)

                    return rightTree.getMax(low, high);

                // debemos dividir el intervalo en [low,mid] y [mid+1,high]

                int leftMin = leftTree.getMax(low, mid);

                int rightMin = rightTree.getMax(mid + 1, high);

                return Math.max(leftMin, rightMin);
            }

        }

    } CExceptionHandling public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            SegmentTree st = new SegmentTree(0, n - 1);
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            }

            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            }
        } solve {
            int n = in.nextInt();
            int[] a = new int[n];
            SegmentTree st = new SegmentTree(0, n - 1);
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            }

            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            }
        } int n = in.nextInt(); n in.nextInt() in.nextInt in int[] a = new int[n]; a new int[n] n SegmentTree st = new SegmentTree(0, n - 1); st new SegmentTree(0, n - 1) for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            } {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            } a[i] = in.nextInt() a[i] a i in.nextInt() in.nextInt in st.set(i, a[i]) st.set st i a[i] a i for (int i = 0; i < n; i++) {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            } {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            } if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                } i == 0 i 0 {
                    out.println(st.getMax(1, n - 1));
                } out.println(st.getMax(1, n - 1)) out.println out st.getMax(1, n - 1) st.getMax st 1 n - 1 n 1 if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                } i == n - 1 i n - 1 n 1 {
                    out.println(st.getMax(0, n - 2));
                } out.println(st.getMax(0, n - 2)) out.println out st.getMax(0, n - 2) st.getMax st 0 n - 2 n 2 {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                } out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1))) out.println out Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)) Math.max Math st.getMax(0, i - 1) st.getMax st 0 i - 1 i 1 st.getMax(i + 1, n - 1) st.getMax st i + 1 i 1 n - 1 n 1 int testNumber testNumber InputReader in in PrintWriter out out class SegmentTree {
            int start;
            int end;
            SegmentTree leftTree;
            SegmentTree rightTree;
            int maxValue;

            public SegmentTree(int start, int end) {

                this.start = start;

                this.end = end;

                this.maxValue = Integer.MIN_VALUE;

                if (start == end) { // es una hoja

                    leftTree = rightTree = null;

                    return;

                }

                int mid = (start + end) / 2;

                leftTree = new SegmentTree(start, mid);
                rightTree = new SegmentTree(mid + 1, end);

            }

            public void set(int pos, int value) {
                // es una hoja, CASO BASE

                if (start == end) {

                    maxValue = value;

                    return;

                }

                int mid = (start + end) / 2;

                if (pos <= mid)

                    leftTree.set(pos, value);

                else

                    rightTree.set(pos, value);

                maxValue = Math.max(leftTree.maxValue, rightTree.maxValue);
            }

            public int getMax(int low, int high) {
                // [low,high] = [start,end]

                if (start == low && end == high)

                    return maxValue;

                int mid = (start + end) / 2;

                // [low,high] totalmente incluido en [start,mid]

                if (high <= mid)

                    return leftTree.getMax(low, high);

                // [low,high] totalmente incluido en [mid+1,end]

                if (low > mid)

                    return rightTree.getMax(low, high);

                // debemos dividir el intervalo en [low,mid] y [mid+1,high]

                int leftMin = leftTree.getMax(low, mid);

                int rightMin = rightTree.getMax(mid + 1, high);

                return Math.max(leftMin, rightMin);
            }

        } SegmentTree int start; start int end; end SegmentTree leftTree; leftTree SegmentTree rightTree; rightTree int maxValue; maxValue public SegmentTree(int start, int end) {

                this.start = start;

                this.end = end;

                this.maxValue = Integer.MIN_VALUE;

                if (start == end) { // es una hoja

                    leftTree = rightTree = null;

                    return;

                }

                int mid = (start + end) / 2;

                leftTree = new SegmentTree(start, mid);
                rightTree = new SegmentTree(mid + 1, end);

            } SegmentTree {

                this.start = start;

                this.end = end;

                this.maxValue = Integer.MIN_VALUE;

                if (start == end) { // es una hoja

                    leftTree = rightTree = null;

                    return;

                }

                int mid = (start + end) / 2;

                leftTree = new SegmentTree(start, mid);
                rightTree = new SegmentTree(mid + 1, end);

            } this.start = start this.start this this.start start this.end = end this.end this this.end end this.maxValue = Integer.MIN_VALUE this.maxValue this this.maxValue Integer.MIN_VALUE Integer Integer.MIN_VALUE if (start == end) { // es una hoja

                    leftTree = rightTree = null;

                    return;

                } start == end start end { // es una hoja

                    leftTree = rightTree = null;

                    return;

                } leftTree = rightTree = null leftTree rightTree = null rightTree null return; int mid = (start + end) / 2; mid (start + end) / 2 (start + end) start end 2 leftTree = new SegmentTree(start, mid) leftTree new SegmentTree(start, mid) rightTree = new SegmentTree(mid + 1, end) rightTree new SegmentTree(mid + 1, end) int start start int end end public void set(int pos, int value) {
                // es una hoja, CASO BASE

                if (start == end) {

                    maxValue = value;

                    return;

                }

                int mid = (start + end) / 2;

                if (pos <= mid)

                    leftTree.set(pos, value);

                else

                    rightTree.set(pos, value);

                maxValue = Math.max(leftTree.maxValue, rightTree.maxValue);
            } set {
                // es una hoja, CASO BASE

                if (start == end) {

                    maxValue = value;

                    return;

                }

                int mid = (start + end) / 2;

                if (pos <= mid)

                    leftTree.set(pos, value);

                else

                    rightTree.set(pos, value);

                maxValue = Math.max(leftTree.maxValue, rightTree.maxValue);
            } if (start == end) {

                    maxValue = value;

                    return;

                } start == end start end {

                    maxValue = value;

                    return;

                } maxValue = value maxValue value return; int mid = (start + end) / 2; mid (start + end) / 2 (start + end) start end 2 if (pos <= mid)

                    leftTree.set(pos, value);

                else

                    rightTree.set(pos, value); pos <= mid pos mid leftTree.set(pos, value) leftTree.set leftTree pos value rightTree.set(pos, value) rightTree.set rightTree pos value maxValue = Math.max(leftTree.maxValue, rightTree.maxValue) maxValue Math.max(leftTree.maxValue, rightTree.maxValue) Math.max Math leftTree.maxValue leftTree leftTree.maxValue rightTree.maxValue rightTree rightTree.maxValue int pos pos int value value public int getMax(int low, int high) {
                // [low,high] = [start,end]

                if (start == low && end == high)

                    return maxValue;

                int mid = (start + end) / 2;

                // [low,high] totalmente incluido en [start,mid]

                if (high <= mid)

                    return leftTree.getMax(low, high);

                // [low,high] totalmente incluido en [mid+1,end]

                if (low > mid)

                    return rightTree.getMax(low, high);

                // debemos dividir el intervalo en [low,mid] y [mid+1,high]

                int leftMin = leftTree.getMax(low, mid);

                int rightMin = rightTree.getMax(mid + 1, high);

                return Math.max(leftMin, rightMin);
            } getMax {
                // [low,high] = [start,end]

                if (start == low && end == high)

                    return maxValue;

                int mid = (start + end) / 2;

                // [low,high] totalmente incluido en [start,mid]

                if (high <= mid)

                    return leftTree.getMax(low, high);

                // [low,high] totalmente incluido en [mid+1,end]

                if (low > mid)

                    return rightTree.getMax(low, high);

                // debemos dividir el intervalo en [low,mid] y [mid+1,high]

                int leftMin = leftTree.getMax(low, mid);

                int rightMin = rightTree.getMax(mid + 1, high);

                return Math.max(leftMin, rightMin);
            } if (start == low && end == high)

                    return maxValue; start == low && end == high start == low start low end == high end high return maxValue; maxValue int mid = (start + end) / 2; mid (start + end) / 2 (start + end) start end 2 if (high <= mid)

                    return leftTree.getMax(low, high); high <= mid high mid return leftTree.getMax(low, high); leftTree.getMax(low, high) leftTree.getMax leftTree low high if (low > mid)

                    return rightTree.getMax(low, high); low > mid low mid return rightTree.getMax(low, high); rightTree.getMax(low, high) rightTree.getMax rightTree low high int leftMin = leftTree.getMax(low, mid); leftMin leftTree.getMax(low, mid) leftTree.getMax leftTree low mid int rightMin = rightTree.getMax(mid + 1, high); rightMin rightTree.getMax(mid + 1, high) rightTree.getMax rightTree mid + 1 mid 1 high return Math.max(leftMin, rightMin); Math.max(leftMin, rightMin) Math.max Math leftMin rightMin int low low int high high 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 int nextInt() {
            return Integer.parseInt(next());
        }

    } 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 int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CExceptionHandling solver = new CExceptionHandling();
        solver.solve(1, in, out);
        out.close();
    }

    static class CExceptionHandling {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            SegmentTree st = new SegmentTree(0, n - 1);
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            }

            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            }
        }

        class SegmentTree {
            int start;
            int end;
            SegmentTree leftTree;
            SegmentTree rightTree;
            int maxValue;

            public SegmentTree(int start, int end) {

                this.start = start;

                this.end = end;

                this.maxValue = Integer.MIN_VALUE;

                if (start == end) { // es una hoja

                    leftTree = rightTree = null;

                    return;

                }

                int mid = (start + end) / 2;

                leftTree = new SegmentTree(start, mid);
                rightTree = new SegmentTree(mid + 1, end);

            }

            public void set(int pos, int value) {
                // es una hoja, CASO BASE

                if (start == end) {

                    maxValue = value;

                    return;

                }

                int mid = (start + end) / 2;

                if (pos <= mid)

                    leftTree.set(pos, value);

                else

                    rightTree.set(pos, value);

                maxValue = Math.max(leftTree.maxValue, rightTree.maxValue);
            }

            public int getMax(int low, int high) {
                // [low,high] = [start,end]

                if (start == low && end == high)

                    return maxValue;

                int mid = (start + end) / 2;

                // [low,high] totalmente incluido en [start,mid]

                if (high <= mid)

                    return leftTree.getMax(low, high);

                // [low,high] totalmente incluido en [mid+1,end]

                if (low > mid)

                    return rightTree.getMax(low, high);

                // debemos dividir el intervalo en [low,mid] y [mid+1,high]

                int leftMin = leftTree.getMax(low, mid);

                int rightMin = rightTree.getMax(mid + 1, high);

                return Math.max(leftMin, rightMin);
            }

        }

    }

    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 int nextInt() {
            return Integer.parseInt(next());
        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CExceptionHandling solver = new CExceptionHandling();
        solver.solve(1, in, out);
        out.close();
    }

    static class CExceptionHandling {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            SegmentTree st = new SegmentTree(0, n - 1);
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            }

            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            }
        }

        class SegmentTree {
            int start;
            int end;
            SegmentTree leftTree;
            SegmentTree rightTree;
            int maxValue;

            public SegmentTree(int start, int end) {

                this.start = start;

                this.end = end;

                this.maxValue = Integer.MIN_VALUE;

                if (start == end) { // es una hoja

                    leftTree = rightTree = null;

                    return;

                }

                int mid = (start + end) / 2;

                leftTree = new SegmentTree(start, mid);
                rightTree = new SegmentTree(mid + 1, end);

            }

            public void set(int pos, int value) {
                // es una hoja, CASO BASE

                if (start == end) {

                    maxValue = value;

                    return;

                }

                int mid = (start + end) / 2;

                if (pos <= mid)

                    leftTree.set(pos, value);

                else

                    rightTree.set(pos, value);

                maxValue = Math.max(leftTree.maxValue, rightTree.maxValue);
            }

            public int getMax(int low, int high) {
                // [low,high] = [start,end]

                if (start == low && end == high)

                    return maxValue;

                int mid = (start + end) / 2;

                // [low,high] totalmente incluido en [start,mid]

                if (high <= mid)

                    return leftTree.getMax(low, high);

                // [low,high] totalmente incluido en [mid+1,end]

                if (low > mid)

                    return rightTree.getMax(low, high);

                // debemos dividir el intervalo en [low,mid] y [mid+1,high]

                int leftMin = leftTree.getMax(low, mid);

                int rightMin = rightTree.getMax(mid + 1, high);

                return Math.max(leftMin, rightMin);
            }

        }

    }

    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 int nextInt() {
            return Integer.parseInt(next());
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CExceptionHandling solver = new CExceptionHandling();
        solver.solve(1, in, out);
        out.close();
    }

    static class CExceptionHandling {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            SegmentTree st = new SegmentTree(0, n - 1);
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                st.set(i, a[i]);
            }

            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    out.println(st.getMax(1, n - 1));
                } else if (i == n - 1) {
                    out.println(st.getMax(0, n - 2));
                } else {
                    out.println(Math.max(st.getMax(0, i - 1), st.getMax(i + 1, n - 1)));
                }
            }
        }

        class SegmentTree {
            int start;
            int end;
            SegmentTree leftTree;
            SegmentTree rightTree;
            int maxValue;

            public SegmentTree(int start, int end) {

                this.start = start;

                this.end = end;

                this.maxValue = Integer.MIN_VALUE;

                if (start == end) { // es una hoja

                    leftTree = rightTree = null;

                    return;

                }

                int mid = (start + end) / 2;

                leftTree = new SegmentTree(start, mid);
                rightTree = new SegmentTree(mid + 1, end);

            }

            public void set(int pos, int value) {
                // es una hoja, CASO BASE

                if (start == end) {

                    maxValue = value;

                    return;

                }

                int mid = (start + end) / 2;

                if (pos <= mid)

                    leftTree.set(pos, value);

                else

                    rightTree.set(pos, value);

                maxValue = Math.max(leftTree.maxValue, rightTree.maxValue);
            }

            public int getMax(int low, int high) {
                // [low,high] = [start,end]

                if (start == low && end == high)

                    return maxValue;

                int mid = (start + end) / 2;

                // [low,high] totalmente incluido en [start,mid]

                if (high <= mid)

                    return leftTree.getMax(low, high);

                // [low,high] totalmente incluido en [mid+1,end]

                if (low > mid)

                    return rightTree.getMax(low, high);

                // debemos dividir el intervalo en [low,mid] y [mid+1,high]

                int leftMin = leftTree.getMax(low, mid);

                int rightMin = rightTree.getMax(mid + 1, high);

                return Math.max(leftMin, rightMin);
            }

        }

    }

    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 int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

