import java.util.*;

class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int max = 0;
      	int sec = 0;
      	int N = sc.nextInt();
      	int[] A = new int[N];
      	for(int i = 0;i < N;i++){
          	A[i] = sc.nextInt();
          	if(A[i] > max){
              	max = A[i];
            }else if(A[i] <= max && A[i] > sec){
              	sec = A[i];
            }
        }
      	for(int i = 0;i < N;i++){
        	System.out.println(A[i]==max ? sec : max);
        }
    }
} import java.util.*; util.* java class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int max = 0;
      	int sec = 0;
      	int N = sc.nextInt();
      	int[] A = new int[N];
      	for(int i = 0;i < N;i++){
          	A[i] = sc.nextInt();
          	if(A[i] > max){
              	max = A[i];
            }else if(A[i] <= max && A[i] > sec){
              	sec = A[i];
            }
        }
      	for(int i = 0;i < N;i++){
        	System.out.println(A[i]==max ? sec : max);
        }
    }
} Main public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int max = 0;
      	int sec = 0;
      	int N = sc.nextInt();
      	int[] A = new int[N];
      	for(int i = 0;i < N;i++){
          	A[i] = sc.nextInt();
          	if(A[i] > max){
              	max = A[i];
            }else if(A[i] <= max && A[i] > sec){
              	sec = A[i];
            }
        }
      	for(int i = 0;i < N;i++){
        	System.out.println(A[i]==max ? sec : max);
        }
    } main {
    	Scanner sc = new Scanner(System.in);
      	int max = 0;
      	int sec = 0;
      	int N = sc.nextInt();
      	int[] A = new int[N];
      	for(int i = 0;i < N;i++){
          	A[i] = sc.nextInt();
          	if(A[i] > max){
              	max = A[i];
            }else if(A[i] <= max && A[i] > sec){
              	sec = A[i];
            }
        }
      	for(int i = 0;i < N;i++){
        	System.out.println(A[i]==max ? sec : max);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int max = 0; max 0 int sec = 0; sec 0 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();
          	if(A[i] > max){
              	max = A[i];
            }else if(A[i] <= max && A[i] > sec){
              	sec = A[i];
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
          	A[i] = sc.nextInt();
          	if(A[i] > max){
              	max = A[i];
            }else if(A[i] <= max && A[i] > sec){
              	sec = A[i];
            }
        } {
          	A[i] = sc.nextInt();
          	if(A[i] > max){
              	max = A[i];
            }else if(A[i] <= max && A[i] > sec){
              	sec = A[i];
            }
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc if(A[i] > max){
              	max = A[i];
            }else if(A[i] <= max && A[i] > sec){
              	sec = A[i];
            } A[i] > max A[i] A i max {
              	max = A[i];
            } max = A[i] max A[i] A i if(A[i] <= max && A[i] > sec){
              	sec = A[i];
            } A[i] <= max && A[i] > sec A[i] <= max A[i] A i max A[i] > sec A[i] A i sec {
              	sec = A[i];
            } sec = A[i] sec A[i] A i for(int i = 0;i < N;i++){
        	System.out.println(A[i]==max ? sec : max);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
        	System.out.println(A[i]==max ? sec : max);
        } {
        	System.out.println(A[i]==max ? sec : max);
        } System.out.println(A[i]==max ? sec : max) System.out.println System.out System System.out A[i]==max ? sec : max A[i]==max A[i] A i max sec max String[] args args
import java.util.*;

class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int max = 0;
      	int sec = 0;
      	int N = sc.nextInt();
      	int[] A = new int[N];
      	for(int i = 0;i < N;i++){
          	A[i] = sc.nextInt();
          	if(A[i] > max){
              	max = A[i];
            }else if(A[i] <= max && A[i] > sec){
              	sec = A[i];
            }
        }
      	for(int i = 0;i < N;i++){
        	System.out.println(A[i]==max ? sec : max);
        }
    }
}