import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		b = a.clone();

		Arrays.sort(a);
		int first = a[n - 1];
		int second = a[n - 2];

		for (int i = 0; i < n; i++) {
			if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		b = a.clone();

		Arrays.sort(a);
		int first = a[n - 1];
		int second = a[n - 2];

		for (int i = 0; i < n; i++) {
			if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		b = a.clone();

		Arrays.sort(a);
		int first = a[n - 1];
		int second = a[n - 2];

		for (int i = 0; i < n; i++) {
			if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		b = a.clone();

		Arrays.sort(a);
		int first = a[n - 1];
		int second = a[n - 2];

		for (int i = 0; i < n; i++) {
			if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int a[] = new int[n]; a new int[n] n int b[] = new int[n]; b new int[n] n for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = Integer.parseInt(br.readLine());
		} {
			a[i] = Integer.parseInt(br.readLine());
		} a[i] = Integer.parseInt(br.readLine()) a[i] a i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br b = a.clone() b a.clone() a.clone a Arrays.sort(a) Arrays.sort Arrays a int first = a[n - 1]; first a[n - 1] a n - 1 n 1 int second = a[n - 2]; second a[n - 2] a n - 2 n 2 for (int i = 0; i < n; i++) {
			if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} {
			if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			} b[i] == first b[i] b i first {
				System.out.println(second);
			} System.out.println(second) System.out.println System.out System System.out second {
				System.out.println(first);
			} System.out.println(first) System.out.println System.out System System.out first String args[] args public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		b = a.clone();

		Arrays.sort(a);
		int first = a[n - 1];
		int second = a[n - 2];

		for (int i = 0; i < n; i++) {
			if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	}
} public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		b = a.clone();

		Arrays.sort(a);
		int first = a[n - 1];
		int second = a[n - 2];

		for (int i = 0; i < n; i++) {
			if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		b = a.clone();

		Arrays.sort(a);
		int first = a[n - 1];
		int second = a[n - 2];

		for (int i = 0; i < n; i++) {
			if (b[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	}
}
