import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        int max1 = a[0];
        for (int i = 1; i < a.length; i++) {
            max1 = Math.max(max1, a[i]);
        }
        int max2 = max1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != max1) {
                max2 = a[i];
                break;
            }
        }
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                continue;
            }
            max2 = Math.max(max2, a[i]);
        }
        int maxNumber = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                maxNumber++;
            }
        }
        if (maxNumber == 1) {
            for (int i = 0; i < a.length; i++) {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            }
        } else {
            for (int i = 0; i < a.length; i++) {
                System.out.println(max1);
            }
        }
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        int max1 = a[0];
        for (int i = 1; i < a.length; i++) {
            max1 = Math.max(max1, a[i]);
        }
        int max2 = max1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != max1) {
                max2 = a[i];
                break;
            }
        }
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                continue;
            }
            max2 = Math.max(max2, a[i]);
        }
        int maxNumber = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                maxNumber++;
            }
        }
        if (maxNumber == 1) {
            for (int i = 0; i < a.length; i++) {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            }
        } else {
            for (int i = 0; i < a.length; i++) {
                System.out.println(max1);
            }
        }
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        int max1 = a[0];
        for (int i = 1; i < a.length; i++) {
            max1 = Math.max(max1, a[i]);
        }
        int max2 = max1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != max1) {
                max2 = a[i];
                break;
            }
        }
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                continue;
            }
            max2 = Math.max(max2, a[i]);
        }
        int maxNumber = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                maxNumber++;
            }
        }
        if (maxNumber == 1) {
            for (int i = 0; i < a.length; i++) {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            }
        } else {
            for (int i = 0; i < a.length; i++) {
                System.out.println(max1);
            }
        }
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        int max1 = a[0];
        for (int i = 1; i < a.length; i++) {
            max1 = Math.max(max1, a[i]);
        }
        int max2 = max1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != max1) {
                max2 = a[i];
                break;
            }
        }
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                continue;
            }
            max2 = Math.max(max2, a[i]);
        }
        int maxNumber = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                maxNumber++;
            }
        }
        if (maxNumber == 1) {
            for (int i = 0; i < a.length; i++) {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            }
        } else {
            for (int i = 0; i < a.length; i++) {
                System.out.println(max1);
            }
        }
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int max1 = a[0]; max1 a[0] a 0 for (int i = 1; i < a.length; i++) {
            max1 = Math.max(max1, a[i]);
        } int i = 1; int i = 1; i 1 i < a.length i a.length a a.length i++ i++ i {
            max1 = Math.max(max1, a[i]);
        } {
            max1 = Math.max(max1, a[i]);
        } max1 = Math.max(max1, a[i]) max1 Math.max(max1, a[i]) Math.max Math max1 a[i] a i int max2 = max1; max2 max1 for (int i = 0; i < a.length; i++) {
            if (a[i] != max1) {
                max2 = a[i];
                break;
            }
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            if (a[i] != max1) {
                max2 = a[i];
                break;
            }
        } {
            if (a[i] != max1) {
                max2 = a[i];
                break;
            }
        } if (a[i] != max1) {
                max2 = a[i];
                break;
            } a[i] != max1 a[i] a i max1 {
                max2 = a[i];
                break;
            } max2 = a[i] max2 a[i] a i break; for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                continue;
            }
            max2 = Math.max(max2, a[i]);
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            if (a[i] == max1) {
                continue;
            }
            max2 = Math.max(max2, a[i]);
        } {
            if (a[i] == max1) {
                continue;
            }
            max2 = Math.max(max2, a[i]);
        } if (a[i] == max1) {
                continue;
            } a[i] == max1 a[i] a i max1 {
                continue;
            } continue; max2 = Math.max(max2, a[i]) max2 Math.max(max2, a[i]) Math.max Math max2 a[i] a i int maxNumber = 0; maxNumber 0 for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                maxNumber++;
            }
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            if (a[i] == max1) {
                maxNumber++;
            }
        } {
            if (a[i] == max1) {
                maxNumber++;
            }
        } if (a[i] == max1) {
                maxNumber++;
            } a[i] == max1 a[i] a i max1 {
                maxNumber++;
            } maxNumber++ maxNumber if (maxNumber == 1) {
            for (int i = 0; i < a.length; i++) {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            }
        } else {
            for (int i = 0; i < a.length; i++) {
                System.out.println(max1);
            }
        } maxNumber == 1 maxNumber 1 {
            for (int i = 0; i < a.length; i++) {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            }
        } for (int i = 0; i < a.length; i++) {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            } {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            } if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                } a[i] == max1 a[i] a i max1 {
                    System.out.println(max2);
                } System.out.println(max2) System.out.println System.out System System.out max2 {
                    System.out.println(max1);
                } System.out.println(max1) System.out.println System.out System System.out max1 {
            for (int i = 0; i < a.length; i++) {
                System.out.println(max1);
            }
        } for (int i = 0; i < a.length; i++) {
                System.out.println(max1);
            } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
                System.out.println(max1);
            } {
                System.out.println(max1);
            } System.out.println(max1) System.out.println System.out System System.out max1 sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        int max1 = a[0];
        for (int i = 1; i < a.length; i++) {
            max1 = Math.max(max1, a[i]);
        }
        int max2 = max1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != max1) {
                max2 = a[i];
                break;
            }
        }
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                continue;
            }
            max2 = Math.max(max2, a[i]);
        }
        int maxNumber = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                maxNumber++;
            }
        }
        if (maxNumber == 1) {
            for (int i = 0; i < a.length; i++) {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            }
        } else {
            for (int i = 0; i < a.length; i++) {
                System.out.println(max1);
            }
        }
        sc.close();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        int max1 = a[0];
        for (int i = 1; i < a.length; i++) {
            max1 = Math.max(max1, a[i]);
        }
        int max2 = max1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != max1) {
                max2 = a[i];
                break;
            }
        }
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                continue;
            }
            max2 = Math.max(max2, a[i]);
        }
        int maxNumber = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                maxNumber++;
            }
        }
        if (maxNumber == 1) {
            for (int i = 0; i < a.length; i++) {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            }
        } else {
            for (int i = 0; i < a.length; i++) {
                System.out.println(max1);
            }
        }
        sc.close();
    }
} Main
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        int max1 = a[0];
        for (int i = 1; i < a.length; i++) {
            max1 = Math.max(max1, a[i]);
        }
        int max2 = max1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != max1) {
                max2 = a[i];
                break;
            }
        }
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                continue;
            }
            max2 = Math.max(max2, a[i]);
        }
        int maxNumber = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == max1) {
                maxNumber++;
            }
        }
        if (maxNumber == 1) {
            for (int i = 0; i < a.length; i++) {
                if (a[i] == max1) {
                    System.out.println(max2);
                } else {
                    System.out.println(max1);
                }
            }
        } else {
            for (int i = 0; i < a.length; i++) {
                System.out.println(max1);
            }
        }
        sc.close();
    }
}