import 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];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int[] sorted = (int[])(arr.clone());
		Arrays.sort(sorted);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    }
		    sb.append("\n");
		}
		System.out.print(sb);
   }
} 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[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int[] sorted = (int[])(arr.clone());
		Arrays.sort(sorted);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    }
		    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];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int[] sorted = (int[])(arr.clone());
		Arrays.sort(sorted);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    }
		    sb.append("\n");
		}
		System.out.print(sb);
   } main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int[] sorted = (int[])(arr.clone());
		Arrays.sort(sorted);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    }
		    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 for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		    arr[i] = sc.nextInt();
		} {
		    arr[i] = sc.nextInt();
		} arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc int[] sorted = (int[])(arr.clone()); sorted (int[])(arr.clone()) arr.clone arr Arrays.sort(sorted) Arrays.sort Arrays sorted StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < n; i++) {
		    if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    }
		    sb.append("\n");
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		    if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    }
		    sb.append("\n");
		} {
		    if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    }
		    sb.append("\n");
		} if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    } arr[i] == sorted[n - 1] arr[i] arr i sorted[n - 1] sorted n - 1 n 1 {
		        sb.append(sorted[n - 2]);
		    } sb.append(sorted[n - 2]) sb.append sb sorted[n - 2] sorted n - 2 n 2 {
		        sb.append(sorted[n - 1]);
		    } sb.append(sorted[n - 1]) sb.append sb sorted[n - 1] sorted n - 1 n 1 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];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int[] sorted = (int[])(arr.clone());
		Arrays.sort(sorted);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    }
		    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];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int[] sorted = (int[])(arr.clone());
		Arrays.sort(sorted);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    }
		    sb.append("\n");
		}
		System.out.print(sb);
   }
} Main
import 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];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int[] sorted = (int[])(arr.clone());
		Arrays.sort(sorted);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (arr[i] == sorted[n - 1]) {
		        sb.append(sorted[n - 2]);
		    } else {
		        sb.append(sorted[n - 1]);
		    }
		    sb.append("\n");
		}
		System.out.print(sb);
   }
}
