import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i <= n; i++) {
			list.add(sc.nextInt());
		}
		List<Integer> sorted = (List<Integer>)list.clone(); 
		Collections.sort(sorted);

		int max = sorted.get(n - 1);
		int maxMinus1 = sorted.get(n - 2);
		for(int i = 0; i < n; i++) {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		}
	}
} import java.util.*; util.* java public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i <= n; i++) {
			list.add(sc.nextInt());
		}
		List<Integer> sorted = (List<Integer>)list.clone(); 
		Collections.sort(sorted);

		int max = sorted.get(n - 1);
		int maxMinus1 = sorted.get(n - 2);
		for(int i = 0; i < n; i++) {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		}
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i <= n; i++) {
			list.add(sc.nextInt());
		}
		List<Integer> sorted = (List<Integer>)list.clone(); 
		Collections.sort(sorted);

		int max = sorted.get(n - 1);
		int maxMinus1 = sorted.get(n - 2);
		for(int i = 0; i < n; i++) {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i <= n; i++) {
			list.add(sc.nextInt());
		}
		List<Integer> sorted = (List<Integer>)list.clone(); 
		Collections.sort(sorted);

		int max = sorted.get(n - 1);
		int maxMinus1 = sorted.get(n - 2);
		for(int i = 0; i < n; i++) {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() for(int i = 1; i <= n; i++) {
			list.add(sc.nextInt());
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			list.add(sc.nextInt());
		} {
			list.add(sc.nextInt());
		} list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc List<Integer> sorted = (List<Integer>)list.clone(); sorted (List<Integer>)list.clone() list.clone list Collections.sort(sorted) Collections.sort Collections sorted int max = sorted.get(n - 1); max sorted.get(n - 1) sorted.get sorted n - 1 n 1 int maxMinus1 = sorted.get(n - 2); maxMinus1 sorted.get(n - 2) sorted.get sorted n - 2 n 2 for(int i = 0; i < n; i++) {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		} {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		} int ai = list.get(i); ai list.get(i) list.get list i if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			} ai != max ai max {
				System.out.println(max);
			} System.out.println(max) System.out.println System.out System System.out max {
				System.out.println(maxMinus1);
			} System.out.println(maxMinus1) System.out.println System.out System System.out maxMinus1 String args[] args public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i <= n; i++) {
			list.add(sc.nextInt());
		}
		List<Integer> sorted = (List<Integer>)list.clone(); 
		Collections.sort(sorted);

		int max = sorted.get(n - 1);
		int maxMinus1 = sorted.get(n - 2);
		for(int i = 0; i < n; i++) {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		}
	}
} public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i <= n; i++) {
			list.add(sc.nextInt());
		}
		List<Integer> sorted = (List<Integer>)list.clone(); 
		Collections.sort(sorted);

		int max = sorted.get(n - 1);
		int maxMinus1 = sorted.get(n - 2);
		for(int i = 0; i < n; i++) {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		}
	}
} Main
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i <= n; i++) {
			list.add(sc.nextInt());
		}
		List<Integer> sorted = (List<Integer>)list.clone(); 
		Collections.sort(sorted);

		int max = sorted.get(n - 1);
		int maxMinus1 = sorted.get(n - 2);
		for(int i = 0; i < n; i++) {
			int ai = list.get(i);
			if (ai != max) {
				System.out.println(max);
			} else {
				System.out.println(maxMinus1);
			}
		}
	}
}