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

public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            int max = 1, second = 1;
            boolean flag = false;
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            }

            for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            }
            reader.close();
        }
        catch(Exception e) {}
    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            int max = 1, second = 1;
            boolean flag = false;
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            }

            for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            }
            reader.close();
        }
        catch(Exception e) {}
    }
} Main public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            int max = 1, second = 1;
            boolean flag = false;
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            }

            for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            }
            reader.close();
        }
        catch(Exception e) {}
    } main {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            int max = 1, second = 1;
            boolean flag = false;
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            }

            for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            }
            reader.close();
        }
        catch(Exception e) {}
    } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) try {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            int max = 1, second = 1;
            boolean flag = false;
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            }

            for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            }
            reader.close();
        }
        catch(Exception e) {} catch(Exception e) {} Exception e {} {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            int max = 1, second = 1;
            boolean flag = false;
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            }

            for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            }
            reader.close();
        } int N = Integer.parseInt(reader.readLine()); N Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader List<Integer> numbers = new ArrayList<>(); numbers new ArrayList<>() int max = 1 max 1 second = 1; second 1 boolean flag = false; flag false for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            } int i=0; int i=0; i 0 i<N i N i++ i++ i {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            } {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            } numbers.add(i, Integer.parseInt(reader.readLine())) numbers.add numbers i Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                } numbers.get(i) > max numbers.get(i) numbers.get numbers i max {
                    max = numbers.get(i);
                    flag = false;
                } max = numbers.get(i) max numbers.get(i) numbers.get numbers i flag = false flag false if (numbers.get(i) == max) {
                    flag = true;
                } numbers.get(i) == max numbers.get(i) numbers.get numbers i max {
                    flag = true;
                } flag = true flag true if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                } !flag && numbers.get(i) > second && max > numbers.get(i) !flag && numbers.get(i) > second && max > numbers.get(i) !flag flag numbers.get(i) > second numbers.get(i) numbers.get numbers i second max > numbers.get(i) max numbers.get(i) numbers.get numbers i {
                    second = numbers.get(i);
                } second = numbers.get(i) second numbers.get(i) numbers.get numbers i if (flag) {
                    second = max;
                } flag {
                    second = max;
                } second = max second max for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            } int i=0; int i=0; i 0 i<N i N i++ i++ i {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            } {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            } if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                } numbers.get(i) == max numbers.get(i) numbers.get numbers i max {
                    System.out.println(second);
                } System.out.println(second) System.out.println System.out System System.out second {
                    System.out.println(max);
                } System.out.println(max) System.out.println System.out System System.out max reader.close() reader.close reader String[] args args public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            int max = 1, second = 1;
            boolean flag = false;
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            }

            for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            }
            reader.close();
        }
        catch(Exception e) {}
    }
} public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            int max = 1, second = 1;
            boolean flag = false;
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            }

            for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            }
            reader.close();
        }
        catch(Exception e) {}
    }
} Main
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            int max = 1, second = 1;
            boolean flag = false;
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    flag = false;
                }
                else if (numbers.get(i) == max) {
                    flag = true;
                }
                if (!flag && numbers.get(i) > second && max > numbers.get(i)) {
                    second = numbers.get(i);
                }
                else if (flag) {
                    second = max;
                }
            }

            for (int i=0; i<N; i++) {
                if (numbers.get(i) == max) {
                    System.out.println(second);
                }
                else {
                    System.out.println(max);
                }
            }
            reader.close();
        }
        catch(Exception e) {}
    }
}