import java.util.Scanner;

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 first = 0;
		int second  = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if(first < a[i]) {
				second = first;
				first = a[i];
			}
			else if(second < a[i]) {
				second = a[i];
			}
		}
		for(int i =0 ;i < n; i++) {
			if(a[i] == first) {
				System.out.println(second);
			}
			else {
				System.out.println(first);
			}
		}
	}
} import java.util.Scanner; Scanner 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];
		int first = 0;
		int second  = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if(first < a[i]) {
				second = first;
				first = a[i];
			}
			else if(second < a[i]) {
				second = a[i];
			}
		}
		for(int i =0 ;i < n; i++) {
			if(a[i] == first) {
				System.out.println(second);
			}
			else {
				System.out.println(first);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int first = 0;
		int second  = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if(first < a[i]) {
				second = first;
				first = a[i];
			}
			else if(second < a[i]) {
				second = a[i];
			}
		}
		for(int i =0 ;i < n; i++) {
			if(a[i] == first) {
				System.out.println(second);
			}
			else {
				System.out.println(first);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int first = 0;
		int second  = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if(first < a[i]) {
				second = first;
				first = a[i];
			}
			else if(second < a[i]) {
				second = a[i];
			}
		}
		for(int i =0 ;i < n; i++) {
			if(a[i] == first) {
				System.out.println(second);
			}
			else {
				System.out.println(first);
			}
		}
	} 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 first = 0; first 0 int second  = 0; second 0 for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if(first < a[i]) {
				second = first;
				first = a[i];
			}
			else if(second < a[i]) {
				second = a[i];
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = sc.nextInt();
			if(first < a[i]) {
				second = first;
				first = a[i];
			}
			else if(second < a[i]) {
				second = a[i];
			}
		} {
			a[i] = sc.nextInt();
			if(first < a[i]) {
				second = first;
				first = a[i];
			}
			else if(second < a[i]) {
				second = a[i];
			}
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc if(first < a[i]) {
				second = first;
				first = a[i];
			}
			else if(second < a[i]) {
				second = a[i];
			} first < a[i] first a[i] a i {
				second = first;
				first = a[i];
			} second = first second first first = a[i] first a[i] a i if(second < a[i]) {
				second = a[i];
			} second < a[i] second a[i] a i {
				second = a[i];
			} second = a[i] second a[i] a i for(int i =0 ;i < n; i++) {
			if(a[i] == first) {
				System.out.println(second);
			}
			else {
				System.out.println(first);
			}
		} int i =0 ; int i =0 ; i 0 i < n i n i++ i++ i {
			if(a[i] == first) {
				System.out.println(second);
			}
			else {
				System.out.println(first);
			}
		} {
			if(a[i] == first) {
				System.out.println(second);
			}
			else {
				System.out.println(first);
			}
		} if(a[i] == first) {
				System.out.println(second);
			}
			else {
				System.out.println(first);
			} a[i] == first a[i] a i first {
				System.out.println(second);
			} System.out.println(second) System.out.println System.out System System.out second {
				System.out.println(first);
			} System.out.println(first) System.out.println System.out System System.out first 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 first = 0;
		int second  = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if(first < a[i]) {
				second = first;
				first = a[i];
			}
			else if(second < a[i]) {
				second = a[i];
			}
		}
		for(int i =0 ;i < n; i++) {
			if(a[i] == first) {
				System.out.println(second);
			}
			else {
				System.out.println(first);
			}
		}
	}
} 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 first = 0;
		int second  = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if(first < a[i]) {
				second = first;
				first = a[i];
			}
			else if(second < a[i]) {
				second = a[i];
			}
		}
		for(int i =0 ;i < n; i++) {
			if(a[i] == first) {
				System.out.println(second);
			}
			else {
				System.out.println(first);
			}
		}
	}
} Main
import java.util.Scanner;

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