import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int max = 0;
        int maxSecond = 0;
        int maxNum = 0;

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            }
            if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            }
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                maxNum++;
            }
        }

        if (maxNum == 1) {
            for (int i = 0; i < n; i++) {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                System.out.println(max);
            }
        }
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int max = 0;
        int maxSecond = 0;
        int maxNum = 0;

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            }
            if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            }
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                maxNum++;
            }
        }

        if (maxNum == 1) {
            for (int i = 0; i < n; i++) {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                System.out.println(max);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int max = 0;
        int maxSecond = 0;
        int maxNum = 0;

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            }
            if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            }
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                maxNum++;
            }
        }

        if (maxNum == 1) {
            for (int i = 0; i < n; i++) {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                System.out.println(max);
            }
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int max = 0;
        int maxSecond = 0;
        int maxNum = 0;

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            }
            if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            }
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                maxNum++;
            }
        }

        if (maxNum == 1) {
            for (int i = 0; i < n; i++) {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                System.out.println(max);
            }
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] a = new int[n]; a new int[n] n int max = 0; max 0 int maxSecond = 0; maxSecond 0 int maxNum = 0; maxNum 0 for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            }
            if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = scanner.nextInt();
            if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            }
            if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            }
        } {
            a[i] = scanner.nextInt();
            if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            }
            if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            }
        } a[i] = scanner.nextInt() a[i] a i scanner.nextInt() scanner.nextInt scanner if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            } a[i] > max a[i] a i max {
                maxSecond = max;
                max = a[i];
            } maxSecond = max maxSecond max max = a[i] max a[i] a i if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            } a[i] != max a[i] a i max {
                maxSecond = Math.max(maxSecond, a[i]);
            } maxSecond = Math.max(maxSecond, a[i]) maxSecond Math.max(maxSecond, a[i]) Math.max Math maxSecond a[i] a i for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                maxNum++;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (a[i] == max) {
                maxNum++;
            }
        } {
            if (a[i] == max) {
                maxNum++;
            }
        } if (a[i] == max) {
                maxNum++;
            } a[i] == max a[i] a i max {
                maxNum++;
            } maxNum++ maxNum if (maxNum == 1) {
            for (int i = 0; i < n; i++) {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                System.out.println(max);
            }
        } maxNum == 1 maxNum 1 {
            for (int i = 0; i < n; i++) {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            }
        } for (int i = 0; i < n; i++) {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            } {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            } if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                } a[i] == max a[i] a i max {
                    System.out.println(maxSecond);
                } System.out.println(maxSecond) System.out.println System.out System System.out maxSecond {
                    System.out.println(max);
                } System.out.println(max) System.out.println System.out System System.out max {
            for (int i = 0; i < n; i++) {
                System.out.println(max);
            }
        } for (int i = 0; i < n; i++) {
                System.out.println(max);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                System.out.println(max);
            } {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int max = 0;
        int maxSecond = 0;
        int maxNum = 0;

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            }
            if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            }
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                maxNum++;
            }
        }

        if (maxNum == 1) {
            for (int i = 0; i < n; i++) {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                System.out.println(max);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int max = 0;
        int maxSecond = 0;
        int maxNum = 0;

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            }
            if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            }
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                maxNum++;
            }
        }

        if (maxNum == 1) {
            for (int i = 0; i < n; i++) {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                System.out.println(max);
            }
        }
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int max = 0;
        int maxSecond = 0;
        int maxNum = 0;

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] > max) {
                maxSecond = max;
                max = a[i];
            }
            if (a[i] != max) {
                maxSecond = Math.max(maxSecond, a[i]);
            }
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                maxNum++;
            }
        }

        if (maxNum == 1) {
            for (int i = 0; i < n; i++) {
                if (a[i] == max) {
                    System.out.println(maxSecond);
                } else {
                    System.out.println(max);
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                System.out.println(max);
            }
        }
    }
}
