import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxi = 0;
        int maxv = 0;
        int seci = 0;
        int secv = 0;
        for(int i = 0; i < n; i++){
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        }
    }
}
 import java.util.*; util.* java import java.io.*; io.* java import java.math.*; math.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxi = 0;
        int maxv = 0;
        int seci = 0;
        int secv = 0;
        for(int i = 0; i < n; i++){
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxi = 0;
        int maxv = 0;
        int seci = 0;
        int secv = 0;
        for(int i = 0; i < n; i++){
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxi = 0;
        int maxv = 0;
        int seci = 0;
        int secv = 0;
        for(int i = 0; i < n; i++){
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int maxi = 0; maxi 0 int maxv = 0; maxv 0 int seci = 0; seci 0 int secv = 0; secv 0 for(int i = 0; i < n; i++){
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        } {
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        } int v = sc.nextInt(); v sc.nextInt() sc.nextInt sc if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            } v > maxv v maxv {
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            } secv = maxv secv maxv seci = maxi seci maxi maxv = v maxv v maxi = i maxi i if(v > secv){
                secv = v;
                seci = i;
            } v > secv v secv {
                secv = v;
                seci = i;
            } secv = v secv v seci = i seci i for(int i = 0; i < n; i++){
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        } {
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        } if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            } i == maxi i maxi {
                System.out.println(secv);
            } System.out.println(secv) System.out.println System.out System System.out secv {
                System.out.println(maxv);
            } System.out.println(maxv) System.out.println System.out System System.out maxv String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxi = 0;
        int maxv = 0;
        int seci = 0;
        int secv = 0;
        for(int i = 0; i < n; i++){
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxi = 0;
        int maxv = 0;
        int seci = 0;
        int secv = 0;
        for(int i = 0; i < n; i++){
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        }
    }
} Main
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxi = 0;
        int maxv = 0;
        int seci = 0;
        int secv = 0;
        for(int i = 0; i < n; i++){
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        }
    }
}

