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<>();
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            }
            List<Integer> sortedNums = new ArrayList<>(numbers);
            Collections.sort(sortedNums, Collections.reverseOrder());
            for (int i=0; i<N; i++) {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            }
            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<>();
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            }
            List<Integer> sortedNums = new ArrayList<>(numbers);
            Collections.sort(sortedNums, Collections.reverseOrder());
            for (int i=0; i<N; i++) {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            }
            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<>();
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            }
            List<Integer> sortedNums = new ArrayList<>(numbers);
            Collections.sort(sortedNums, Collections.reverseOrder());
            for (int i=0; i<N; i++) {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            }
            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<>();
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            }
            List<Integer> sortedNums = new ArrayList<>(numbers);
            Collections.sort(sortedNums, Collections.reverseOrder());
            for (int i=0; i<N; i++) {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            }
            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<>();
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            }
            List<Integer> sortedNums = new ArrayList<>(numbers);
            Collections.sort(sortedNums, Collections.reverseOrder());
            for (int i=0; i<N; i++) {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            }
            reader.close();
        }
        catch(Exception e) {} catch(Exception e) {} Exception e {} {
            int N = Integer.parseInt(reader.readLine());
            List<Integer> numbers = new ArrayList<>();
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            }
            List<Integer> sortedNums = new ArrayList<>(numbers);
            Collections.sort(sortedNums, Collections.reverseOrder());
            for (int i=0; i<N; i++) {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            }
            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<>() for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            } int i=0; int i=0; i 0 i<N i N i++ i++ i {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            } {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            } numbers.add(i, Integer.parseInt(reader.readLine())) numbers.add numbers i Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader List<Integer> sortedNums = new ArrayList<>(numbers); sortedNums new ArrayList<>(numbers) Collections.sort(sortedNums, Collections.reverseOrder()) Collections.sort Collections sortedNums Collections.reverseOrder() Collections.reverseOrder Collections for (int i=0; i<N; i++) {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            } int i=0; int i=0; i 0 i<N i N i++ i++ i {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            } {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            } if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                } numbers.get(i) == sortedNums.get(0) numbers.get(i) numbers.get numbers i sortedNums.get(0) sortedNums.get sortedNums 0 {
                    System.out.println(sortedNums.get(1));
                } System.out.println(sortedNums.get(1)) System.out.println System.out System System.out sortedNums.get(1) sortedNums.get sortedNums 1 {
                    System.out.println(sortedNums.get(0));
                } System.out.println(sortedNums.get(0)) System.out.println System.out System System.out sortedNums.get(0) sortedNums.get sortedNums 0 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<>();
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            }
            List<Integer> sortedNums = new ArrayList<>(numbers);
            Collections.sort(sortedNums, Collections.reverseOrder());
            for (int i=0; i<N; i++) {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            }
            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<>();
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            }
            List<Integer> sortedNums = new ArrayList<>(numbers);
            Collections.sort(sortedNums, Collections.reverseOrder());
            for (int i=0; i<N; i++) {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            }
            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<>();
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(reader.readLine()));
            }
            List<Integer> sortedNums = new ArrayList<>(numbers);
            Collections.sort(sortedNums, Collections.reverseOrder());
            for (int i=0; i<N; i++) {
                if (numbers.get(i) == sortedNums.get(0)) {
                    System.out.println(sortedNums.get(1));
                }
                else {
                    System.out.println(sortedNums.get(0));
                }
            }
            reader.close();
        }
        catch(Exception e) {}
    }
}