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[] arr = new int[n];

		int maxAll = 0;
		int maxIndex = 0;

		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		}

		for (int i = 0; i < n; i++) {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			}
		}
	}
} 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[] arr = new int[n];

		int maxAll = 0;
		int maxIndex = 0;

		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		}

		for (int i = 0; i < n; i++) {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());

		int[] arr = new int[n];

		int maxAll = 0;
		int maxIndex = 0;

		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		}

		for (int i = 0; i < n; i++) {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());

		int[] arr = new int[n];

		int maxAll = 0;
		int maxIndex = 0;

		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		}

		for (int i = 0; i < n; i++) {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				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[] arr = new int[n]; arr new int[n] n int maxAll = 0; maxAll 0 int maxIndex = 0; maxIndex 0 for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		} {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		} arr[i] = Integer.parseInt(sc.next()) arr[i] arr i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			} arr[i] > maxAll arr[i] arr i maxAll {
				maxAll = arr[i];
				maxIndex = i;
			} maxAll = arr[i] maxAll arr[i] arr i maxIndex = i maxIndex i for (int i = 0; i < n; i++) {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			}
		} {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			}
		} if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			} i != maxIndex i maxIndex {
				System.out.println(maxAll);
			} System.out.println(maxAll) System.out.println System.out System System.out maxAll {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			} int max = 0; max 0 for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				} int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				} {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				} if(j==i)continue; j==i j i continue; if(max < arr[j]) {
						max = arr[j];
					} max < arr[j] max arr[j] arr j {
						max = arr[j];
					} max = arr[j] max arr[j] arr j 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[] arr = new int[n];

		int maxAll = 0;
		int maxIndex = 0;

		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		}

		for (int i = 0; i < n; i++) {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				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[] arr = new int[n];

		int maxAll = 0;
		int maxIndex = 0;

		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		}

		for (int i = 0; i < n; i++) {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			}
		}
	}
} Main
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[] arr = new int[n];

		int maxAll = 0;
		int maxIndex = 0;

		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		}

		for (int i = 0; i < n; i++) {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			}
		}
	}
}