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 = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		int b[];
		b = a.clone();
		Arrays.sort(b);

		int max = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		}

	}

} 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 = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		int b[];
		b = a.clone();
		Arrays.sort(b);

		int max = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		}

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		int b[];
		b = a.clone();
		Arrays.sort(b);

		int max = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		}

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

		int b[];
		b = a.clone();
		Arrays.sort(b);

		int max = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = Integer.parseInt(sc.next());
		} {
			a[i] = Integer.parseInt(sc.next());
		} a[i] = Integer.parseInt(sc.next()) a[i] a i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int b[]; b b = a.clone() b a.clone() a.clone a Arrays.sort(b) Arrays.sort Arrays b int max = 0; max 0 for (int i = 0; i < n; i++) {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		} {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		} if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			} a[i] != b[n - 1] a[i] a i b[n - 1] b n - 1 n 1 {
				max = b[n - 1];
			} max = b[n - 1] max b[n - 1] b n - 1 n 1 {
				max = b[n - 2];
			} max = b[n - 2] max b[n - 2] b n - 2 n 2 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) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		int b[];
		b = a.clone();
		Arrays.sort(b);

		int max = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		}

	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		int b[];
		b = a.clone();
		Arrays.sort(b);

		int max = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		}

	}

} 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 = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		int b[];
		b = a.clone();
		Arrays.sort(b);

		int max = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		}

	}

}
