import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; ++i){
            a[i] = input.nextInt();
            b[i] = a[i];
        }
        Arrays.sort(b);
        int minx = b[n - 2];
        int maxx = b[n - 1];
        for(int i = 0; i < n; ++i){
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        }
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; ++i){
            a[i] = input.nextInt();
            b[i] = a[i];
        }
        Arrays.sort(b);
        int minx = b[n - 2];
        int maxx = b[n - 1];
        for(int i = 0; i < n; ++i){
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        }
    }
} Main public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; ++i){
            a[i] = input.nextInt();
            b[i] = a[i];
        }
        Arrays.sort(b);
        int minx = b[n - 2];
        int maxx = b[n - 1];
        for(int i = 0; i < n; ++i){
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        }
    } main {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; ++i){
            a[i] = input.nextInt();
            b[i] = a[i];
        }
        Arrays.sort(b);
        int minx = b[n - 2];
        int maxx = b[n - 1];
        for(int i = 0; i < n; ++i){
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        }
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int n = input.nextInt(); n input.nextInt() input.nextInt input int[] a = new int[n]; a new int[n] n int[] b = new int[n]; b new int[n] n for(int i = 0; i < n; ++i){
            a[i] = input.nextInt();
            b[i] = a[i];
        } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
            a[i] = input.nextInt();
            b[i] = a[i];
        } {
            a[i] = input.nextInt();
            b[i] = a[i];
        } a[i] = input.nextInt() a[i] a i input.nextInt() input.nextInt input b[i] = a[i] b[i] b i a[i] a i Arrays.sort(b) Arrays.sort Arrays b int minx = b[n - 2]; minx b[n - 2] b n - 2 n 2 int maxx = b[n - 1]; maxx b[n - 1] b n - 1 n 1 for(int i = 0; i < n; ++i){
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        } {
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        } if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx); a[i] == maxx a[i] a i maxx System.out.println(minx) System.out.println System.out System System.out minx System.out.println(maxx) System.out.println System.out System System.out maxx String[] args args public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; ++i){
            a[i] = input.nextInt();
            b[i] = a[i];
        }
        Arrays.sort(b);
        int minx = b[n - 2];
        int maxx = b[n - 1];
        for(int i = 0; i < n; ++i){
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; ++i){
            a[i] = input.nextInt();
            b[i] = a[i];
        }
        Arrays.sort(b);
        int minx = b[n - 2];
        int maxx = b[n - 1];
        for(int i = 0; i < n; ++i){
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        }
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; ++i){
            a[i] = input.nextInt();
            b[i] = a[i];
        }
        Arrays.sort(b);
        int minx = b[n - 2];
        int maxx = b[n - 1];
        for(int i = 0; i < n; ++i){
            if(a[i] == maxx) System.out.println(minx);
            else System.out.println(maxx);
        }
    }
}
