import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int max = 0;
        int max2 = 0;
        for(int i = 0;i<n;i++){
            a[i] = Integer.parseInt(sc.next());
            
            if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            }
        }
        for(int i = 0;i<n;i++){
            if(max == a[i]){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
            
        }
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int max = 0;
        int max2 = 0;
        for(int i = 0;i<n;i++){
            a[i] = Integer.parseInt(sc.next());
            
            if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            }
        }
        for(int i = 0;i<n;i++){
            if(max == a[i]){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
            
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int max = 0;
        int max2 = 0;
        for(int i = 0;i<n;i++){
            a[i] = Integer.parseInt(sc.next());
            
            if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            }
        }
        for(int i = 0;i<n;i++){
            if(max == a[i]){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
            
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int max = 0;
        int max2 = 0;
        for(int i = 0;i<n;i++){
            a[i] = Integer.parseInt(sc.next());
            
            if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            }
        }
        for(int i = 0;i<n;i++){
            if(max == a[i]){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
            
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] a = new int[n]; a new int[n] n int max = 0; max 0 int max2 = 0; max2 0 for(int i = 0;i<n;i++){
            a[i] = Integer.parseInt(sc.next());
            
            if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            a[i] = Integer.parseInt(sc.next());
            
            if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            }
        } {
            a[i] = Integer.parseInt(sc.next());
            
            if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            }
        } a[i] = Integer.parseInt(sc.next()) a[i] a i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            } a[i] == max a[i] a i max {
                max2 = max;
            } max2 = max max2 max {
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            } if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                } max < a[i] max a[i] a i {
                    max2 = max;
                    max = Math.max(a[i],max);
                } max2 = max max2 max max = Math.max(a[i],max) max Math.max(a[i],max) Math.max Math a[i] a i max {
                    max2 = Math.max(a[i],max2);
                } max2 = Math.max(a[i],max2) max2 Math.max(a[i],max2) Math.max Math a[i] a i max2 for(int i = 0;i<n;i++){
            if(max == a[i]){
                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(max == a[i]){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
            
        } {
            if(max == a[i]){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
            
        } if(max == a[i]){
                System.out.println(max2);
            }else{
                System.out.println(max);
            } max == a[i] max a[i] a i {
                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 sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int max = 0;
        int max2 = 0;
        for(int i = 0;i<n;i++){
            a[i] = Integer.parseInt(sc.next());
            
            if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            }
        }
        for(int i = 0;i<n;i++){
            if(max == a[i]){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
            
        }
    }
} public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int max = 0;
        int max2 = 0;
        for(int i = 0;i<n;i++){
            a[i] = Integer.parseInt(sc.next());
            
            if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            }
        }
        for(int i = 0;i<n;i++){
            if(max == a[i]){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
            
        }
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int max = 0;
        int max2 = 0;
        for(int i = 0;i<n;i++){
            a[i] = Integer.parseInt(sc.next());
            
            if(a[i] == max){
                max2 = max;
            }else{
                if(max < a[i]){
                    max2 = max;
                    max = Math.max(a[i],max);
                }else{
                    max2 = Math.max(a[i],max2);
                }
            }
        }
        for(int i = 0;i<n;i++){
            if(max == a[i]){
                System.out.println(max2);
            }else{
                System.out.println(max);
            }
            
        }
    }
}