import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int max1 = 0;
        int max2 = 0;

        int max_index = 0;

        for (int i = 0; i < n; i++) {
            if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int max1 = 0;
        int max2 = 0;

        int max_index = 0;

        for (int i = 0; i < n; i++) {
            if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int max1 = 0;
        int max2 = 0;

        int max_index = 0;

        for (int i = 0; i < n; i++) {
            if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }
	} main {
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int max1 = 0;
        int max2 = 0;

        int max_index = 0;

        for (int i = 0; i < n; i++) {
            if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }
	} 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 for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int max1 = 0; max1 0 int max2 = 0; max2 0 int max_index = 0; max_index 0 for (int i = 0; i < n; i++) {
            if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            }
        } {
            if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            }
        } if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            } max1 < a[i] max1 a[i] a i {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } max2 = max1 max2 max1 max1 = a[i] max1 a[i] a i max_index = i max_index i if(max2 < a[i]) {
                max2 = a[i];
            } max2 < a[i] max2 a[i] a i {
                max2 = a[i];
            } max2 = a[i] max2 a[i] a i for (int i = 0; i < n; i++) {
            if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        } {
            if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        } if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            } max_index == i max_index i {
                System.out.println(max2);
            } System.out.println(max2) System.out.println System.out System System.out max2 {
                System.out.println(max1);
            } System.out.println(max1) System.out.println System.out System System.out max1 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];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int max1 = 0;
        int max2 = 0;

        int max_index = 0;

        for (int i = 0; i < n; i++) {
            if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int max1 = 0;
        int max2 = 0;

        int max_index = 0;

        for (int i = 0; i < n; i++) {
            if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }
	}
} Main
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int max1 = 0;
        int max2 = 0;

        int max_index = 0;

        for (int i = 0; i < n; i++) {
            if (max1 < a[i]) {
                max2 = max1;
                max1 = a[i];
                max_index = i;
            } else if(max2 < a[i]) {
                max2 = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (max_index == i) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }
	}
}
