import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        int n = Integer.valueOf(arr01[0]);

        ArrayList<Integer> list01 = new ArrayList<Integer>();

        for (int i = 1; i < 1 + n; i++) {

            list01.add(Integer.valueOf(mylist.get(i)));

        }

        ArrayList<Integer> list02 = new ArrayList<Integer>(list01);

        //昇順でソート
        Collections.sort(list02);
        //降順でソート
        Collections.reverse(list02);

        int maxdata = list02.get(0);
        int seconddata = list02.get(1);

        for (int i = 0; i < list01.size(); i++) {

            int temp = list01.get(i);

            //            System.out.println(temp);
            if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            }

        }
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        int n = Integer.valueOf(arr01[0]);

        ArrayList<Integer> list01 = new ArrayList<Integer>();

        for (int i = 1; i < 1 + n; i++) {

            list01.add(Integer.valueOf(mylist.get(i)));

        }

        ArrayList<Integer> list02 = new ArrayList<Integer>(list01);

        //昇順でソート
        Collections.sort(list02);
        //降順でソート
        Collections.reverse(list02);

        int maxdata = list02.get(0);
        int seconddata = list02.get(1);

        for (int i = 0; i < list01.size(); i++) {

            int temp = list01.get(i);

            //            System.out.println(temp);
            if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            }

        }
    }

} Main public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        int n = Integer.valueOf(arr01[0]);

        ArrayList<Integer> list01 = new ArrayList<Integer>();

        for (int i = 1; i < 1 + n; i++) {

            list01.add(Integer.valueOf(mylist.get(i)));

        }

        ArrayList<Integer> list02 = new ArrayList<Integer>(list01);

        //昇順でソート
        Collections.sort(list02);
        //降順でソート
        Collections.reverse(list02);

        int maxdata = list02.get(0);
        int seconddata = list02.get(1);

        for (int i = 0; i < list01.size(); i++) {

            int temp = list01.get(i);

            //            System.out.println(temp);
            if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            }

        }
    } main {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        int n = Integer.valueOf(arr01[0]);

        ArrayList<Integer> list01 = new ArrayList<Integer>();

        for (int i = 1; i < 1 + n; i++) {

            list01.add(Integer.valueOf(mylist.get(i)));

        }

        ArrayList<Integer> list02 = new ArrayList<Integer>(list01);

        //昇順でソート
        Collections.sort(list02);
        //降順でソート
        Collections.reverse(list02);

        int maxdata = list02.get(0);
        int seconddata = list02.get(1);

        for (int i = 0; i < list01.size(); i++) {

            int temp = list01.get(i);

            //            System.out.println(temp);
            if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            }

        }
    } InputStreamReader is = new InputStreamReader(System.in); is new InputStreamReader(System.in) BufferedReader reader = new BufferedReader(is); reader new BufferedReader(is) List<String> mylist = new ArrayList<>(); mylist new ArrayList<>() String strinput = reader.readLine(); strinput reader.readLine() reader.readLine reader while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        } strinput != null strinput null {

            mylist.add(strinput);
            strinput = reader.readLine();

        } mylist.add(strinput) mylist.add mylist strinput strinput = reader.readLine() strinput reader.readLine() reader.readLine reader String arr01[] = mylist.get(0).split(" "); arr01 mylist.get(0).split(" ") mylist.get(0).split mylist.get(0) mylist.get mylist 0 " " int n = Integer.valueOf(arr01[0]); n Integer.valueOf(arr01[0]) Integer.valueOf Integer arr01[0] arr01 0 ArrayList<Integer> list01 = new ArrayList<Integer>(); list01 new ArrayList<Integer>() for (int i = 1; i < 1 + n; i++) {

            list01.add(Integer.valueOf(mylist.get(i)));

        } int i = 1; int i = 1; i 1 i < 1 + n i 1 + n 1 n i++ i++ i {

            list01.add(Integer.valueOf(mylist.get(i)));

        } {

            list01.add(Integer.valueOf(mylist.get(i)));

        } list01.add(Integer.valueOf(mylist.get(i))) list01.add list01 Integer.valueOf(mylist.get(i)) Integer.valueOf Integer mylist.get(i) mylist.get mylist i ArrayList<Integer> list02 = new ArrayList<Integer>(list01); list02 new ArrayList<Integer>(list01) Collections.sort(list02) Collections.sort Collections list02 Collections.reverse(list02) Collections.reverse Collections list02 int maxdata = list02.get(0); maxdata list02.get(0) list02.get list02 0 int seconddata = list02.get(1); seconddata list02.get(1) list02.get list02 1 for (int i = 0; i < list01.size(); i++) {

            int temp = list01.get(i);

            //            System.out.println(temp);
            if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            }

        } int i = 0; int i = 0; i 0 i < list01.size() i list01.size() list01.size list01 i++ i++ i {

            int temp = list01.get(i);

            //            System.out.println(temp);
            if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            }

        } {

            int temp = list01.get(i);

            //            System.out.println(temp);
            if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            }

        } int temp = list01.get(i); temp list01.get(i) list01.get list01 i if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            } temp == maxdata temp maxdata {
                System.out.println(seconddata);
            } System.out.println(seconddata) System.out.println System.out System System.out seconddata {
                System.out.println(maxdata);

            } System.out.println(maxdata) System.out.println System.out System System.out maxdata String[] args args public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        int n = Integer.valueOf(arr01[0]);

        ArrayList<Integer> list01 = new ArrayList<Integer>();

        for (int i = 1; i < 1 + n; i++) {

            list01.add(Integer.valueOf(mylist.get(i)));

        }

        ArrayList<Integer> list02 = new ArrayList<Integer>(list01);

        //昇順でソート
        Collections.sort(list02);
        //降順でソート
        Collections.reverse(list02);

        int maxdata = list02.get(0);
        int seconddata = list02.get(1);

        for (int i = 0; i < list01.size(); i++) {

            int temp = list01.get(i);

            //            System.out.println(temp);
            if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            }

        }
    }

} public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        int n = Integer.valueOf(arr01[0]);

        ArrayList<Integer> list01 = new ArrayList<Integer>();

        for (int i = 1; i < 1 + n; i++) {

            list01.add(Integer.valueOf(mylist.get(i)));

        }

        ArrayList<Integer> list02 = new ArrayList<Integer>(list01);

        //昇順でソート
        Collections.sort(list02);
        //降順でソート
        Collections.reverse(list02);

        int maxdata = list02.get(0);
        int seconddata = list02.get(1);

        for (int i = 0; i < list01.size(); i++) {

            int temp = list01.get(i);

            //            System.out.println(temp);
            if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            }

        }
    }

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        int n = Integer.valueOf(arr01[0]);

        ArrayList<Integer> list01 = new ArrayList<Integer>();

        for (int i = 1; i < 1 + n; i++) {

            list01.add(Integer.valueOf(mylist.get(i)));

        }

        ArrayList<Integer> list02 = new ArrayList<Integer>(list01);

        //昇順でソート
        Collections.sort(list02);
        //降順でソート
        Collections.reverse(list02);

        int maxdata = list02.get(0);
        int seconddata = list02.get(1);

        for (int i = 0; i < list01.size(); i++) {

            int temp = list01.get(i);

            //            System.out.println(temp);
            if (temp == maxdata) {
                System.out.println(seconddata);
            } else {
                System.out.println(maxdata);

            }

        }
    }

}
