import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] arr = new int[N];
		int[] sortedArr = new int[N];
		for(int i =0; i< N; i++) {
			arr[i] = sc.nextInt();
			sortedArr[i] = arr[i];
		}
		Arrays.sort(sortedArr);
		int first = sortedArr[N-1];
		int second = sortedArr[N-2];
		StringBuilder sb = new StringBuilder();
		for(int i =0; i< N; i++) {
			if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}

} import java.util.Arrays; Arrays java.util 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[] arr = new int[N];
		int[] sortedArr = new int[N];
		for(int i =0; i< N; i++) {
			arr[i] = sc.nextInt();
			sortedArr[i] = arr[i];
		}
		Arrays.sort(sortedArr);
		int first = sortedArr[N-1];
		int second = sortedArr[N-2];
		StringBuilder sb = new StringBuilder();
		for(int i =0; i< N; i++) {
			if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] arr = new int[N];
		int[] sortedArr = new int[N];
		for(int i =0; i< N; i++) {
			arr[i] = sc.nextInt();
			sortedArr[i] = arr[i];
		}
		Arrays.sort(sortedArr);
		int first = sortedArr[N-1];
		int second = sortedArr[N-2];
		StringBuilder sb = new StringBuilder();
		for(int i =0; i< N; i++) {
			if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] arr = new int[N];
		int[] sortedArr = new int[N];
		for(int i =0; i< N; i++) {
			arr[i] = sc.nextInt();
			sortedArr[i] = arr[i];
		}
		Arrays.sort(sortedArr);
		int first = sortedArr[N-1];
		int second = sortedArr[N-2];
		StringBuilder sb = new StringBuilder();
		for(int i =0; i< N; i++) {
			if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] arr = new int[N]; arr new int[N] N int[] sortedArr = new int[N]; sortedArr new int[N] N for(int i =0; i< N; i++) {
			arr[i] = sc.nextInt();
			sortedArr[i] = arr[i];
		} int i =0; int i =0; i 0 i< N i N i++ i++ i {
			arr[i] = sc.nextInt();
			sortedArr[i] = arr[i];
		} {
			arr[i] = sc.nextInt();
			sortedArr[i] = arr[i];
		} arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc sortedArr[i] = arr[i] sortedArr[i] sortedArr i arr[i] arr i Arrays.sort(sortedArr) Arrays.sort Arrays sortedArr int first = sortedArr[N-1]; first sortedArr[N-1] sortedArr N-1 N 1 int second = sortedArr[N-2]; second sortedArr[N-2] sortedArr N-2 N 2 StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i =0; i< N; i++) {
			if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			}
			sb.append("\n");
		} int i =0; int i =0; i 0 i< N i N i++ i++ i {
			if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			}
			sb.append("\n");
		} {
			if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			}
			sb.append("\n");
		} if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			} arr[i] == first arr[i] arr i first {
				sb.append(second);
			} sb.append(second) sb.append sb second {
				sb.append(first);
			} sb.append(first) sb.append sb first sb.append("\n") sb.append sb "\n" System.out.print(sb) System.out.print System.out System System.out sb String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] arr = new int[N];
		int[] sortedArr = new int[N];
		for(int i =0; i< N; i++) {
			arr[i] = sc.nextInt();
			sortedArr[i] = arr[i];
		}
		Arrays.sort(sortedArr);
		int first = sortedArr[N-1];
		int second = sortedArr[N-2];
		StringBuilder sb = new StringBuilder();
		for(int i =0; i< N; i++) {
			if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] arr = new int[N];
		int[] sortedArr = new int[N];
		for(int i =0; i< N; i++) {
			arr[i] = sc.nextInt();
			sortedArr[i] = arr[i];
		}
		Arrays.sort(sortedArr);
		int first = sortedArr[N-1];
		int second = sortedArr[N-2];
		StringBuilder sb = new StringBuilder();
		for(int i =0; i< N; i++) {
			if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] arr = new int[N];
		int[] sortedArr = new int[N];
		for(int i =0; i< N; i++) {
			arr[i] = sc.nextInt();
			sortedArr[i] = arr[i];
		}
		Arrays.sort(sortedArr);
		int first = sortedArr[N-1];
		int second = sortedArr[N-2];
		StringBuilder sb = new StringBuilder();
		for(int i =0; i< N; i++) {
			if(arr[i] == first) {
				sb.append(second);
			}else {
				sb.append(first);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}

}
