import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		int max_i = 0;
		int max = 0;
		int second_i = 0;
		int second = 0;
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    }
		}
		
		// 計算
		
		// 出力
		for(int i = 0; i < n; i++){
		    if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    }
		}
	}

} import java.util.*; util.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; import java.math.BigInteger; BigInteger java.math public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		int max_i = 0;
		int max = 0;
		int second_i = 0;
		int second = 0;
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    }
		}
		
		// 計算
		
		// 出力
		for(int i = 0; i < n; i++){
		    if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    }
		}
	}

} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		int max_i = 0;
		int max = 0;
		int second_i = 0;
		int second = 0;
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    }
		}
		
		// 計算
		
		// 出力
		for(int i = 0; i < n; i++){
		    if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    }
		}
	} main {
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		int max_i = 0;
		int max = 0;
		int second_i = 0;
		int second = 0;
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    }
		}
		
		// 計算
		
		// 出力
		for(int i = 0; i < n; i++){
		    if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    }
		}
	} 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 int max_i = 0; max_i 0 int max = 0; max 0 int second_i = 0; second_i 0 int second = 0; second 0 for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    }
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		    a[i] = sc.nextInt();
		    if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    }
		} {
		    a[i] = sc.nextInt();
		    if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    }
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    } a[i] >= max a[i] a i max {
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    } second = max second max second_i = max_i second_i max_i max = a[i] max a[i] a i max_i = i max_i i if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    } a[i] >= second a[i] a i second {
		        second = a[i];
		        second_i = i;
		    } second = a[i] second a[i] a i second_i = i second_i i for(int i = 0; i < n; i++){
		    if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    }
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		    if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    }
		} {
		    if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    }
		} if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    } i == max_i i max_i {
                System.out.println(a[second_i]);
		    } System.out.println(a[second_i]) System.out.println System.out System System.out a[second_i] a second_i {
		        System.out.println(a[max_i]);
		    } System.out.println(a[max_i]) System.out.println System.out System System.out a[max_i] a max_i 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];
		int max_i = 0;
		int max = 0;
		int second_i = 0;
		int second = 0;
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    }
		}
		
		// 計算
		
		// 出力
		for(int i = 0; i < n; i++){
		    if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    }
		}
	}

} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		int max_i = 0;
		int max = 0;
		int second_i = 0;
		int second = 0;
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    }
		}
		
		// 計算
		
		// 出力
		for(int i = 0; i < n; i++){
		    if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    }
		}
	}

} Main
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		int max_i = 0;
		int max = 0;
		int second_i = 0;
		int second = 0;
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    if(a[i] >= max){
		        second = max;
		        second_i = max_i;
		        max = a[i];
		        max_i = i;
		    }else if(a[i] >= second){
		        second = a[i];
		        second_i = i;
		    }
		}
		
		// 計算
		
		// 出力
		for(int i = 0; i < n; i++){
		    if(i == max_i){
                System.out.println(a[second_i]);
		    }else{
		        System.out.println(a[max_i]);
		    }
		}
	}

}
