import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhijeetkns
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(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, Scanner in, PrintWriter out) {
            ArrayList<Integer> list = new ArrayList<>();
            int n = in.nextInt();
            for (int i = 0; i < n; i++) list.add(in.nextInt());
            ArrayList<Integer> list1 = new ArrayList<>(list);
            int max1 = Collections.max(list);
            Collections.sort(list);
            //out.println(list);
            int max2 = list.get(n - 2);

            for (int i = 0; i < n; i++) {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            }
        }

    }
}
 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.Scanner; Scanner java.util import java.util.Collections; Collections java.util import java.util.ArrayList; ArrayList java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(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, Scanner in, PrintWriter out) {
            ArrayList<Integer> list = new ArrayList<>();
            int n = in.nextInt();
            for (int i = 0; i < n; i++) list.add(in.nextInt());
            ArrayList<Integer> list1 = new ArrayList<>(list);
            int max1 = Collections.max(list);
            Collections.sort(list);
            //out.println(list);
            int max2 = list.get(n - 2);

            for (int i = 0; i < n; i++) {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            }
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(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;
        Scanner in = new Scanner(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 Scanner in = new Scanner(inputStream); in new Scanner(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, Scanner in, PrintWriter out) {
            ArrayList<Integer> list = new ArrayList<>();
            int n = in.nextInt();
            for (int i = 0; i < n; i++) list.add(in.nextInt());
            ArrayList<Integer> list1 = new ArrayList<>(list);
            int max1 = Collections.max(list);
            Collections.sort(list);
            //out.println(list);
            int max2 = list.get(n - 2);

            for (int i = 0; i < n; i++) {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            }
        }

    } CExceptionHandling public void solve(int testNumber, Scanner in, PrintWriter out) {
            ArrayList<Integer> list = new ArrayList<>();
            int n = in.nextInt();
            for (int i = 0; i < n; i++) list.add(in.nextInt());
            ArrayList<Integer> list1 = new ArrayList<>(list);
            int max1 = Collections.max(list);
            Collections.sort(list);
            //out.println(list);
            int max2 = list.get(n - 2);

            for (int i = 0; i < n; i++) {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            }
        } solve {
            ArrayList<Integer> list = new ArrayList<>();
            int n = in.nextInt();
            for (int i = 0; i < n; i++) list.add(in.nextInt());
            ArrayList<Integer> list1 = new ArrayList<>(list);
            int max1 = Collections.max(list);
            Collections.sort(list);
            //out.println(list);
            int max2 = list.get(n - 2);

            for (int i = 0; i < n; i++) {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            }
        } ArrayList<Integer> list = new ArrayList<>(); list new ArrayList<>() int n = in.nextInt(); n in.nextInt() in.nextInt in for (int i = 0; i < n; i++) list.add(in.nextInt()); int i = 0; int i = 0; i 0 i < n i n i++ i++ i list.add(in.nextInt()); list.add(in.nextInt()) list.add list in.nextInt() in.nextInt in ArrayList<Integer> list1 = new ArrayList<>(list); list1 new ArrayList<>(list) int max1 = Collections.max(list); max1 Collections.max(list) Collections.max Collections list Collections.sort(list) Collections.sort Collections list int max2 = list.get(n - 2); max2 list.get(n - 2) list.get list n - 2 n 2 for (int i = 0; i < n; i++) {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            } {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            } int ele = list1.get(i); ele list1.get(i) list1.get list1 i if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                } ele < max1 ele max1 out.println(max1) out.println out max1 {
                    out.println(max2);
                } out.println(max2) out.println out max2 int testNumber testNumber Scanner in in PrintWriter out out public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(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, Scanner in, PrintWriter out) {
            ArrayList<Integer> list = new ArrayList<>();
            int n = in.nextInt();
            for (int i = 0; i < n; i++) list.add(in.nextInt());
            ArrayList<Integer> list1 = new ArrayList<>(list);
            int max1 = Collections.max(list);
            Collections.sort(list);
            //out.println(list);
            int max2 = list.get(n - 2);

            for (int i = 0; i < n; i++) {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            }
        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(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, Scanner in, PrintWriter out) {
            ArrayList<Integer> list = new ArrayList<>();
            int n = in.nextInt();
            for (int i = 0; i < n; i++) list.add(in.nextInt());
            ArrayList<Integer> list1 = new ArrayList<>(list);
            int max1 = Collections.max(list);
            Collections.sort(list);
            //out.println(list);
            int max2 = list.get(n - 2);

            for (int i = 0; i < n; i++) {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            }
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhijeetkns
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(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, Scanner in, PrintWriter out) {
            ArrayList<Integer> list = new ArrayList<>();
            int n = in.nextInt();
            for (int i = 0; i < n; i++) list.add(in.nextInt());
            ArrayList<Integer> list1 = new ArrayList<>(list);
            int max1 = Collections.max(list);
            Collections.sort(list);
            //out.println(list);
            int max2 = list.get(n - 2);

            for (int i = 0; i < n; i++) {
                int ele = list1.get(i);
                if (ele < max1) out.println(max1);
                else {
                    out.println(max2);
                }
            }
        }

    }
}

