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

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			Integer a[] = new Integer[n];
			Integer b[] = new Integer[n];
			
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				b[i] = a[i];

			}
			
			Arrays.sort(b, Collections.reverseOrder());
			int max = b[0];
			int sec = b[1];
			
			for (int i = 0; i < n; i++) {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			}

		}

	}

} import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			Integer a[] = new Integer[n];
			Integer b[] = new Integer[n];
			
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				b[i] = a[i];

			}
			
			Arrays.sort(b, Collections.reverseOrder());
			int max = b[0];
			int sec = b[1];
			
			for (int i = 0; i < n; i++) {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			}

		}

	}

} Main public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			Integer a[] = new Integer[n];
			Integer b[] = new Integer[n];
			
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				b[i] = a[i];

			}
			
			Arrays.sort(b, Collections.reverseOrder());
			int max = b[0];
			int sec = b[1];
			
			for (int i = 0; i < n; i++) {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			}

		}

	} main {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			Integer a[] = new Integer[n];
			Integer b[] = new Integer[n];
			
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				b[i] = a[i];

			}
			
			Arrays.sort(b, Collections.reverseOrder());
			int max = b[0];
			int sec = b[1];
			
			for (int i = 0; i < n; i++) {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			}

		}

	} try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			Integer a[] = new Integer[n];
			Integer b[] = new Integer[n];
			
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				b[i] = a[i];

			}
			
			Arrays.sort(b, Collections.reverseOrder());
			int max = b[0];
			int sec = b[1];
			
			for (int i = 0; i < n; i++) {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			}

		} {

			int n = sc.nextInt();
			Integer a[] = new Integer[n];
			Integer b[] = new Integer[n];
			
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				b[i] = a[i];

			}
			
			Arrays.sort(b, Collections.reverseOrder());
			int max = b[0];
			int sec = b[1];
			
			for (int i = 0; i < n; i++) {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			}

		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc Integer a[] = new Integer[n]; a new Integer[n] n Integer b[] = new Integer[n]; b new Integer[n] n for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				b[i] = a[i];

			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				a[i] = sc.nextInt();
				b[i] = a[i];

			} {
				a[i] = sc.nextInt();
				b[i] = a[i];

			} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc b[i] = a[i] b[i] b i a[i] a i Arrays.sort(b, Collections.reverseOrder()) Arrays.sort Arrays b Collections.reverseOrder() Collections.reverseOrder Collections int max = b[0]; max b[0] b 0 int sec = b[1]; sec b[1] b 1 for (int i = 0; i < n; i++) {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			} {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			} if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				} a[i] == max a[i] a i max {
					System.out.println(sec);
				} System.out.println(sec) System.out.println System.out System System.out sec {
					System.out.println(max);
				} System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			Integer a[] = new Integer[n];
			Integer b[] = new Integer[n];
			
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				b[i] = a[i];

			}
			
			Arrays.sort(b, Collections.reverseOrder());
			int max = b[0];
			int sec = b[1];
			
			for (int i = 0; i < n; i++) {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			}

		}

	}

} public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			Integer a[] = new Integer[n];
			Integer b[] = new Integer[n];
			
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				b[i] = a[i];

			}
			
			Arrays.sort(b, Collections.reverseOrder());
			int max = b[0];
			int sec = b[1];
			
			for (int i = 0; i < n; i++) {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			}

		}

	}

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

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			Integer a[] = new Integer[n];
			Integer b[] = new Integer[n];
			
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				b[i] = a[i];

			}
			
			Arrays.sort(b, Collections.reverseOrder());
			int max = b[0];
			int sec = b[1];
			
			for (int i = 0; i < n; i++) {
				if (a[i] == max) {
					System.out.println(sec);
				} else {
					System.out.println(max);
				}

			}

		}

	}

}