import java.util.*;
import java.math.*;
class Main {
    //
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ary = new int[n];
        int[] b = new int[n];
        int max = 0;
        int sec = 0;
        for(int i = 0;i < n;i++){
            ary[i] = sc.nextInt();
            b[i] = ary[i];
        }
        
        Arrays.sort(b);
        max = b[n-1];
        sec = b[n-2];
        for(int i = 0;i < n;i++){
            int ans = max;
            if(ary[i]==max){
                ans = sec;
            }
            System.out.println(ans);
        }
    }
} import java.util.*; util.* java import java.math.*; math.* java class Main {
    //
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ary = new int[n];
        int[] b = new int[n];
        int max = 0;
        int sec = 0;
        for(int i = 0;i < n;i++){
            ary[i] = sc.nextInt();
            b[i] = ary[i];
        }
        
        Arrays.sort(b);
        max = b[n-1];
        sec = b[n-2];
        for(int i = 0;i < n;i++){
            int ans = max;
            if(ary[i]==max){
                ans = sec;
            }
            System.out.println(ans);
        }
    }
} Main //
    static final int MOD = 1_000_000_007; // 10^9+7 MOD 1_000_000_007 //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9 INF 1_000_000_000 static final int MAX = 10_000_000; MAX 10_000_000 public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ary = new int[n];
        int[] b = new int[n];
        int max = 0;
        int sec = 0;
        for(int i = 0;i < n;i++){
            ary[i] = sc.nextInt();
            b[i] = ary[i];
        }
        
        Arrays.sort(b);
        max = b[n-1];
        sec = b[n-2];
        for(int i = 0;i < n;i++){
            int ans = max;
            if(ary[i]==max){
                ans = sec;
            }
            System.out.println(ans);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ary = new int[n];
        int[] b = new int[n];
        int max = 0;
        int sec = 0;
        for(int i = 0;i < n;i++){
            ary[i] = sc.nextInt();
            b[i] = ary[i];
        }
        
        Arrays.sort(b);
        max = b[n-1];
        sec = b[n-2];
        for(int i = 0;i < n;i++){
            int ans = max;
            if(ary[i]==max){
                ans = sec;
            }
            System.out.println(ans);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] ary = new int[n]; ary new int[n] n int[] b = new int[n]; b new int[n] n int max = 0; max 0 int sec = 0; sec 0 for(int i = 0;i < n;i++){
            ary[i] = sc.nextInt();
            b[i] = ary[i];
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            ary[i] = sc.nextInt();
            b[i] = ary[i];
        } {
            ary[i] = sc.nextInt();
            b[i] = ary[i];
        } ary[i] = sc.nextInt() ary[i] ary i sc.nextInt() sc.nextInt sc b[i] = ary[i] b[i] b i ary[i] ary i Arrays.sort(b) Arrays.sort Arrays b max = b[n-1] max b[n-1] b n-1 n 1 sec = b[n-2] sec b[n-2] b n-2 n 2 for(int i = 0;i < n;i++){
            int ans = max;
            if(ary[i]==max){
                ans = sec;
            }
            System.out.println(ans);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int ans = max;
            if(ary[i]==max){
                ans = sec;
            }
            System.out.println(ans);
        } {
            int ans = max;
            if(ary[i]==max){
                ans = sec;
            }
            System.out.println(ans);
        } int ans = max; ans max if(ary[i]==max){
                ans = sec;
            } ary[i]==max ary[i] ary i max {
                ans = sec;
            } ans = sec ans sec System.out.println(ans) System.out.println System.out System System.out ans String args[] args
import java.util.*;
import java.math.*;
class Main {
    //
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ary = new int[n];
        int[] b = new int[n];
        int max = 0;
        int sec = 0;
        for(int i = 0;i < n;i++){
            ary[i] = sc.nextInt();
            b[i] = ary[i];
        }
        
        Arrays.sort(b);
        max = b[n-1];
        sec = b[n-2];
        for(int i = 0;i < n;i++){
            int ans = max;
            if(ary[i]==max){
                ans = sec;
            }
            System.out.println(ans);
        }
    }
}