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 < n; i++){
            a[i] = sc.nextInt();
        }
        
        int max = 0;
        int second = 0;
        int maxNum = 0;
        boolean multiMax = false;
        
        for(int i = 0; i < n; i++){
            if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            }
        }
        
        StringBuilder sb = new StringBuilder();
        String br = System.lineSeparator();
        if(multiMax){
            for(int i = 0; i < n; i++){
                sb.append(max).append(br);
            }
        }else{
            for(int i = 0; i < n; i++){
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            }
        }
        
        System.out.println(sb);
    }
} 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 < n; i++){
            a[i] = sc.nextInt();
        }
        
        int max = 0;
        int second = 0;
        int maxNum = 0;
        boolean multiMax = false;
        
        for(int i = 0; i < n; i++){
            if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            }
        }
        
        StringBuilder sb = new StringBuilder();
        String br = System.lineSeparator();
        if(multiMax){
            for(int i = 0; i < n; i++){
                sb.append(max).append(br);
            }
        }else{
            for(int i = 0; i < n; i++){
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            }
        }
        
        System.out.println(sb);
    }
} 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 < n; i++){
            a[i] = sc.nextInt();
        }
        
        int max = 0;
        int second = 0;
        int maxNum = 0;
        boolean multiMax = false;
        
        for(int i = 0; i < n; i++){
            if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            }
        }
        
        StringBuilder sb = new StringBuilder();
        String br = System.lineSeparator();
        if(multiMax){
            for(int i = 0; i < n; i++){
                sb.append(max).append(br);
            }
        }else{
            for(int i = 0; i < n; i++){
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            }
        }
        
        System.out.println(sb);
    } main {
        
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        
        int max = 0;
        int second = 0;
        int maxNum = 0;
        boolean multiMax = false;
        
        for(int i = 0; i < n; i++){
            if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            }
        }
        
        StringBuilder sb = new StringBuilder();
        String br = System.lineSeparator();
        if(multiMax){
            for(int i = 0; i < n; i++){
                sb.append(max).append(br);
            }
        }else{
            for(int i = 0; i < n; i++){
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            }
        }
        
        System.out.println(sb);
    } 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 < n; i++){
            a[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n 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 max = 0; max 0 int second = 0; second 0 int maxNum = 0; maxNum 0 boolean multiMax = false; multiMax false for(int i = 0; i < n; i++){
            if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            }
        } {
            if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            }
        } if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            } a[i] > max a[i] a i max {
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            } second = max second max max = a[i] max a[i] a i maxNum = i maxNum i multiMax = false multiMax false if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            } a[i] == max a[i] a i max {
                multiMax = true;
            } multiMax = true multiMax true if(a[i] > second){
                second = a[i];
            } a[i] > second a[i] a i second {
                second = a[i];
            } second = a[i] second a[i] a i StringBuilder sb = new StringBuilder(); sb new StringBuilder() String br = System.lineSeparator(); br System.lineSeparator() System.lineSeparator System if(multiMax){
            for(int i = 0; i < n; i++){
                sb.append(max).append(br);
            }
        }else{
            for(int i = 0; i < n; i++){
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            }
        } multiMax {
            for(int i = 0; i < n; i++){
                sb.append(max).append(br);
            }
        } for(int i = 0; i < n; i++){
                sb.append(max).append(br);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                sb.append(max).append(br);
            } {
                sb.append(max).append(br);
            } sb.append(max).append(br) sb.append(max).append sb.append(max) sb.append sb max br {
            for(int i = 0; i < n; i++){
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            }
        } for(int i = 0; i < n; i++){
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            } {
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            } if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                } i == maxNum i maxNum {
                    sb.append(second).append(br);
                } sb.append(second).append(br) sb.append(second).append sb.append(second) sb.append sb second br {
                    sb.append(max).append(br);
                } sb.append(max).append(br) sb.append(max).append sb.append(max) sb.append sb max br System.out.println(sb) System.out.println System.out System System.out sb 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 < n; i++){
            a[i] = sc.nextInt();
        }
        
        int max = 0;
        int second = 0;
        int maxNum = 0;
        boolean multiMax = false;
        
        for(int i = 0; i < n; i++){
            if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            }
        }
        
        StringBuilder sb = new StringBuilder();
        String br = System.lineSeparator();
        if(multiMax){
            for(int i = 0; i < n; i++){
                sb.append(max).append(br);
            }
        }else{
            for(int i = 0; i < n; i++){
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            }
        }
        
        System.out.println(sb);
    }
} 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 < n; i++){
            a[i] = sc.nextInt();
        }
        
        int max = 0;
        int second = 0;
        int maxNum = 0;
        boolean multiMax = false;
        
        for(int i = 0; i < n; i++){
            if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            }
        }
        
        StringBuilder sb = new StringBuilder();
        String br = System.lineSeparator();
        if(multiMax){
            for(int i = 0; i < n; i++){
                sb.append(max).append(br);
            }
        }else{
            for(int i = 0; i < n; i++){
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            }
        }
        
        System.out.println(sb);
    }
} 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 < n; i++){
            a[i] = sc.nextInt();
        }
        
        int max = 0;
        int second = 0;
        int maxNum = 0;
        boolean multiMax = false;
        
        for(int i = 0; i < n; i++){
            if(a[i] > max){
                second = max;
                max = a[i];
                maxNum = i;
                multiMax = false;
            }else if(a[i] == max){
                multiMax = true;
            }else if(a[i] > second){
                second = a[i];
            }
        }
        
        StringBuilder sb = new StringBuilder();
        String br = System.lineSeparator();
        if(multiMax){
            for(int i = 0; i < n; i++){
                sb.append(max).append(br);
            }
        }else{
            for(int i = 0; i < n; i++){
                if(i == maxNum){
                    sb.append(second).append(br);
                }else{
                    sb.append(max).append(br);
                }
            }
        }
        
        System.out.println(sb);
    }
}