import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        int max = 0;
        for(int i = 0; i < n; i++){
            if(max <= a[i]){
                max = a[i];
            }
        }
        int max2 = 0;
        int c = 0;
        for(int i = 0; i < n; i++){
            if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            }
            if(a[i] == max){
                c++;
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        int max = 0;
        for(int i = 0; i < n; i++){
            if(max <= a[i]){
                max = a[i];
            }
        }
        int max2 = 0;
        int c = 0;
        for(int i = 0; i < n; i++){
            if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            }
            if(a[i] == max){
                c++;
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        int max = 0;
        for(int i = 0; i < n; i++){
            if(max <= a[i]){
                max = a[i];
            }
        }
        int max2 = 0;
        int c = 0;
        for(int i = 0; i < n; i++){
            if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            }
            if(a[i] == max){
                c++;
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
        }
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        int max = 0;
        for(int i = 0; i < n; i++){
            if(max <= a[i]){
                max = a[i];
            }
        }
        int max2 = 0;
        int c = 0;
        for(int i = 0; i < n; i++){
            if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            }
            if(a[i] == max){
                c++;
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] a = new int[n]; a new int[n] n for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = scan.nextInt();
        } {
            a[i] = scan.nextInt();
        } a[i] = scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan int max = 0; max 0 for(int i = 0; i < n; i++){
            if(max <= a[i]){
                max = a[i];
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(max <= a[i]){
                max = a[i];
            }
        } {
            if(max <= a[i]){
                max = a[i];
            }
        } if(max <= a[i]){
                max = a[i];
            } max <= a[i] max a[i] a i {
                max = a[i];
            } max = a[i] max a[i] a i int max2 = 0; max2 0 int c = 0; c 0 for(int i = 0; i < n; i++){
            if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            }
            if(a[i] == max){
                c++;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            }
            if(a[i] == max){
                c++;
            }
        } {
            if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            }
            if(a[i] == max){
                c++;
            }
        } if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            } max2 < a[i] && a[i] != max max2 < a[i] max2 a[i] a i a[i] != max a[i] a i max {
                max2 = a[i];
            } max2 = a[i] max2 a[i] a i if(a[i] == max){
                c++;
            } a[i] == max a[i] a i max {
                c++;
            } c++ c for(int i = 0; i < n; i++){
            if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
        } {
            if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
        } if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            } a[i] == max && c < 2 a[i] == max a[i] a i max c < 2 c 2 {
                System.out.println(max2);
            } System.out.println(max2) System.out.println System.out System System.out max2 {
                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 scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        int max = 0;
        for(int i = 0; i < n; i++){
            if(max <= a[i]){
                max = a[i];
            }
        }
        int max2 = 0;
        int c = 0;
        for(int i = 0; i < n; i++){
            if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            }
            if(a[i] == max){
                c++;
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        int max = 0;
        for(int i = 0; i < n; i++){
            if(max <= a[i]){
                max = a[i];
            }
        }
        int max2 = 0;
        int c = 0;
        for(int i = 0; i < n; i++){
            if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            }
            if(a[i] == max){
                c++;
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        int max = 0;
        for(int i = 0; i < n; i++){
            if(max <= a[i]){
                max = a[i];
            }
        }
        int max2 = 0;
        int c = 0;
        for(int i = 0; i < n; i++){
            if(max2 < a[i] && a[i] != max){
                max2 = a[i];
            }
            if(a[i] == max){
                c++;
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i] == max && c < 2){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
        }
    }
}