import java.util.*;

public class Main{
	public static void main(String args[]){
    	Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
      
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = scanner.nextInt();
        }
		
        int max_first = 0;
        int max_second = 0;
        int count_max_first = 0;
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_first){
                max_first = A[i];
            }
        } 
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            }
        } 
      
        if(count_max_first > 1){
            max_second = max_first;
        }
      
        for(int i = 0; i < N; i++){
            if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } 
    }
} import java.util.*; util.* java public class Main{
	public static void main(String args[]){
    	Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
      
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = scanner.nextInt();
        }
		
        int max_first = 0;
        int max_second = 0;
        int count_max_first = 0;
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_first){
                max_first = A[i];
            }
        } 
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            }
        } 
      
        if(count_max_first > 1){
            max_second = max_first;
        }
      
        for(int i = 0; i < N; i++){
            if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } 
    }
} Main public static void main(String args[]){
    	Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
      
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = scanner.nextInt();
        }
		
        int max_first = 0;
        int max_second = 0;
        int count_max_first = 0;
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_first){
                max_first = A[i];
            }
        } 
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            }
        } 
      
        if(count_max_first > 1){
            max_second = max_first;
        }
      
        for(int i = 0; i < N; i++){
            if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } 
    } main {
    	Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
      
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = scanner.nextInt();
        }
		
        int max_first = 0;
        int max_second = 0;
        int count_max_first = 0;
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_first){
                max_first = A[i];
            }
        } 
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            }
        } 
      
        if(count_max_first > 1){
            max_second = max_first;
        }
      
        for(int i = 0; i < N; i++){
            if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } 
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] A = new int[N]; A new int[N] N for(int i = 0; i < N; i++){
            A[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = scanner.nextInt();
        } {
            A[i] = scanner.nextInt();
        } A[i] = scanner.nextInt() A[i] A i scanner.nextInt() scanner.nextInt scanner int max_first = 0; max_first 0 int max_second = 0; max_second 0 int count_max_first = 0; count_max_first 0 for(int i = 0; i < N; i++){
            if(A[i] > max_first){
                max_first = A[i];
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(A[i] > max_first){
                max_first = A[i];
            }
        } {
            if(A[i] > max_first){
                max_first = A[i];
            }
        } if(A[i] > max_first){
                max_first = A[i];
            } A[i] > max_first A[i] A i max_first {
                max_first = A[i];
            } max_first = A[i] max_first A[i] A i for(int i = 0; i < N; i++){
            if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            }
        } {
            if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            }
        } if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            } A[i] > max_second && A[i] != max_first A[i] > max_second A[i] A i max_second A[i] != max_first A[i] A i max_first {
                max_second = A[i];
            } max_second = A[i] max_second A[i] A i if(A[i] == max_first) {
                count_max_first++;
            } A[i] == max_first A[i] A i max_first {
                count_max_first++;
            } count_max_first++ count_max_first if(count_max_first > 1){
            max_second = max_first;
        } count_max_first > 1 count_max_first 1 {
            max_second = max_first;
        } max_second = max_first max_second max_first for(int i = 0; i < N; i++){
            if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } {
            if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            } A[i] == max_first A[i] A i max_first {
                System.out.println(max_second);
            } System.out.println(max_second) System.out.println System.out System System.out max_second {
                System.out.println(max_first);
            } System.out.println(max_first) System.out.println System.out System System.out max_first String args[] args public class Main{
	public static void main(String args[]){
    	Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
      
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = scanner.nextInt();
        }
		
        int max_first = 0;
        int max_second = 0;
        int count_max_first = 0;
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_first){
                max_first = A[i];
            }
        } 
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            }
        } 
      
        if(count_max_first > 1){
            max_second = max_first;
        }
      
        for(int i = 0; i < N; i++){
            if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } 
    }
} public class Main{
	public static void main(String args[]){
    	Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
      
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = scanner.nextInt();
        }
		
        int max_first = 0;
        int max_second = 0;
        int count_max_first = 0;
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_first){
                max_first = A[i];
            }
        } 
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            }
        } 
      
        if(count_max_first > 1){
            max_second = max_first;
        }
      
        for(int i = 0; i < N; i++){
            if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } 
    }
} Main
import java.util.*;

public class Main{
	public static void main(String args[]){
    	Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
      
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = scanner.nextInt();
        }
		
        int max_first = 0;
        int max_second = 0;
        int count_max_first = 0;
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_first){
                max_first = A[i];
            }
        } 
      
        for(int i = 0; i < N; i++){
            if(A[i] > max_second && A[i] != max_first){
                max_second = A[i];
            } else if(A[i] == max_first) {
                count_max_first++;
            }
        } 
      
        if(count_max_first > 1){
            max_second = max_first;
        }
      
        for(int i = 0; i < N; i++){
            if(A[i] == max_first){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } 
    }
}