
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];

		int maxA = 0;
		int maxAIndex = -1;
		int maxA2 = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

		for (int i = 0; i < N; i++) {

			if (i == maxAIndex) {
				continue;
			}

			if (maxA2 <= A[i]) {
				maxA2 = A[i];
			}
		}

		for (int i = 0; i < N; i++) {

			if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			}
		}
	}
} 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 A[] = new int[N];

		int maxA = 0;
		int maxAIndex = -1;
		int maxA2 = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

		for (int i = 0; i < N; i++) {

			if (i == maxAIndex) {
				continue;
			}

			if (maxA2 <= A[i]) {
				maxA2 = A[i];
			}
		}

		for (int i = 0; i < N; i++) {

			if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			}
		}
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];

		int maxA = 0;
		int maxAIndex = -1;
		int maxA2 = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

		for (int i = 0; i < N; i++) {

			if (i == maxAIndex) {
				continue;
			}

			if (maxA2 <= A[i]) {
				maxA2 = A[i];
			}
		}

		for (int i = 0; i < N; i++) {

			if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			}
		}
	} main {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];

		int maxA = 0;
		int maxAIndex = -1;
		int maxA2 = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

		for (int i = 0; i < N; i++) {

			if (i == maxAIndex) {
				continue;
			}

			if (maxA2 <= A[i]) {
				maxA2 = A[i];
			}
		}

		for (int i = 0; i < N; i++) {

			if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int A[] = new int[N]; A new int[N] N int maxA = 0; maxA 0 int maxAIndex = -1; maxAIndex -1 1 int maxA2 = 0; maxA2 0 for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		} {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		} A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			} maxA <= A[i] maxA A[i] A i {
				maxA = A[i];
				maxAIndex = i;
			} maxA = A[i] maxA A[i] A i maxAIndex = i maxAIndex i for (int i = 0; i < N; i++) {

			if (i == maxAIndex) {
				continue;
			}

			if (maxA2 <= A[i]) {
				maxA2 = A[i];
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {

			if (i == maxAIndex) {
				continue;
			}

			if (maxA2 <= A[i]) {
				maxA2 = A[i];
			}
		} {

			if (i == maxAIndex) {
				continue;
			}

			if (maxA2 <= A[i]) {
				maxA2 = A[i];
			}
		} if (i == maxAIndex) {
				continue;
			} i == maxAIndex i maxAIndex {
				continue;
			} continue; if (maxA2 <= A[i]) {
				maxA2 = A[i];
			} maxA2 <= A[i] maxA2 A[i] A i {
				maxA2 = A[i];
			} maxA2 = A[i] maxA2 A[i] A i for (int i = 0; i < N; i++) {

			if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {

			if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			}
		} {

			if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			}
		} if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			} !(i == maxAIndex) (i == maxAIndex) i maxAIndex {
				System.out.println(maxA);
			} System.out.println(maxA) System.out.println System.out System System.out maxA {
				System.out.println(maxA2);
			} System.out.println(maxA2) System.out.println System.out System System.out maxA2 String[] args args public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];

		int maxA = 0;
		int maxAIndex = -1;
		int maxA2 = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

		for (int i = 0; i < N; i++) {

			if (i == maxAIndex) {
				continue;
			}

			if (maxA2 <= A[i]) {
				maxA2 = A[i];
			}
		}

		for (int i = 0; i < N; i++) {

			if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			}
		}
	}
} public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];

		int maxA = 0;
		int maxAIndex = -1;
		int maxA2 = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

		for (int i = 0; i < N; i++) {

			if (i == maxAIndex) {
				continue;
			}

			if (maxA2 <= A[i]) {
				maxA2 = A[i];
			}
		}

		for (int i = 0; i < N; i++) {

			if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			}
		}
	}
} Main

import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];

		int maxA = 0;
		int maxAIndex = -1;
		int maxA2 = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

		for (int i = 0; i < N; i++) {

			if (i == maxAIndex) {
				continue;
			}

			if (maxA2 <= A[i]) {
				maxA2 = A[i];
			}
		}

		for (int i = 0; i < N; i++) {

			if (!(i == maxAIndex)) {
				System.out.println(maxA);
			} else {
				System.out.println(maxA2);
			}
		}
	}
}