import java.util.*;
import java.util.Collections;

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 maxidx = 0;
        int secmax = 0;
        int secmaxidx = 0;
        for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > max) {
                max = A[i];
                maxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                System.out.println(secmax);
            }else {
                System.out.println(max);
            }
        }
    }
} import java.util.*; util.* java import java.util.Collections; Collections 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 maxidx = 0;
        int secmax = 0;
        int secmaxidx = 0;
        for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > max) {
                max = A[i];
                maxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                System.out.println(secmax);
            }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 maxidx = 0;
        int secmax = 0;
        int secmaxidx = 0;
        for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > max) {
                max = A[i];
                maxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                System.out.println(secmax);
            }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 maxidx = 0;
        int secmax = 0;
        int secmaxidx = 0;
        for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > max) {
                max = A[i];
                maxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                System.out.println(secmax);
            }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 maxidx = 0; maxidx 0 int secmax = 0; secmax 0 int secmaxidx = 0; secmaxidx 0 for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > max) {
                max = A[i];
                maxidx = i;
            }
        } 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) {
                max = A[i];
                maxidx = i;
            }
        } {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > max) {
                max = A[i];
                maxidx = i;
            }
        } 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) {
                max = A[i];
                maxidx = i;
            } A[i] > max A[i] A i max {
                max = A[i];
                maxidx = i;
            } max = A[i] max A[i] A i maxidx = i maxidx i for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        } {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        } if(i == maxidx) {
                continue;
            } i == maxidx i maxidx {
                continue;
            } continue; if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            } A[i] > secmax A[i] A i secmax {
                secmax = A[i];
                secmaxidx = i;
            } secmax = A[i] secmax A[i] A i secmaxidx = i secmaxidx i for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                System.out.println(secmax);
            }else {
                System.out.println(max);
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(i == maxidx) {
                System.out.println(secmax);
            }else {
                System.out.println(max);
            }
        } {
            if(i == maxidx) {
                System.out.println(secmax);
            }else {
                System.out.println(max);
            }
        } if(i == maxidx) {
                System.out.println(secmax);
            }else {
                System.out.println(max);
            } i == maxidx i maxidx {
                System.out.println(secmax);
            } System.out.println(secmax) System.out.println System.out System System.out secmax {
                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 maxidx = 0;
        int secmax = 0;
        int secmaxidx = 0;
        for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > max) {
                max = A[i];
                maxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                System.out.println(secmax);
            }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 maxidx = 0;
        int secmax = 0;
        int secmaxidx = 0;
        for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > max) {
                max = A[i];
                maxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                System.out.println(secmax);
            }else {
                System.out.println(max);
            }
        }
    }
} Main
import java.util.*;
import java.util.Collections;

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 maxidx = 0;
        int secmax = 0;
        int secmaxidx = 0;
        for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > max) {
                max = A[i];
                maxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                System.out.println(secmax);
            }else {
                System.out.println(max);
            }
        }
    }
}