import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

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

		sc.close();

		int[] left = new int[N];
		int[] right = new int[N];

		left[0] = A[0];
		for (int i = 1; i < N; i++) {
			left[i] = Math.max(left[i - 1], A[i]);
		}

		right[N - 1] = A[N - 1];
		for (int i = N - 2; i >= 0; i--) {
			right[i] = Math.max(right[i + 1], A[i]);
		}

		StringBuilder sb = new StringBuilder();

		sb.append(right[1]);
		sb.append("\n");
		for (int i = 1; i < N - 1; i++) {
			int l = left[i - 1];
			int r = right[i + 1];

			sb.append(Math.max(l, r));
			sb.append("\n");
		}
		sb.append(left[N - 2]);
		sb.append("\n");

		out.print(sb.toString());

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io import java.util.Scanner; Scanner java.util public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

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

		sc.close();

		int[] left = new int[N];
		int[] right = new int[N];

		left[0] = A[0];
		for (int i = 1; i < N; i++) {
			left[i] = Math.max(left[i - 1], A[i]);
		}

		right[N - 1] = A[N - 1];
		for (int i = N - 2; i >= 0; i--) {
			right[i] = Math.max(right[i + 1], A[i]);
		}

		StringBuilder sb = new StringBuilder();

		sb.append(right[1]);
		sb.append("\n");
		for (int i = 1; i < N - 1; i++) {
			int l = left[i - 1];
			int r = right[i + 1];

			sb.append(Math.max(l, r));
			sb.append("\n");
		}
		sb.append(left[N - 2]);
		sb.append("\n");

		out.print(sb.toString());

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} Main InputStream in = System.in; in System.in System System.in PrintStream out = System.out; out System.out System System.out public void _main(String[] args) {
		Scanner sc = new Scanner(in);

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

		sc.close();

		int[] left = new int[N];
		int[] right = new int[N];

		left[0] = A[0];
		for (int i = 1; i < N; i++) {
			left[i] = Math.max(left[i - 1], A[i]);
		}

		right[N - 1] = A[N - 1];
		for (int i = N - 2; i >= 0; i--) {
			right[i] = Math.max(right[i + 1], A[i]);
		}

		StringBuilder sb = new StringBuilder();

		sb.append(right[1]);
		sb.append("\n");
		for (int i = 1; i < N - 1; i++) {
			int l = left[i - 1];
			int r = right[i + 1];

			sb.append(Math.max(l, r));
			sb.append("\n");
		}
		sb.append(left[N - 2]);
		sb.append("\n");

		out.print(sb.toString());

	} _main {
		Scanner sc = new Scanner(in);

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

		sc.close();

		int[] left = new int[N];
		int[] right = new int[N];

		left[0] = A[0];
		for (int i = 1; i < N; i++) {
			left[i] = Math.max(left[i - 1], A[i]);
		}

		right[N - 1] = A[N - 1];
		for (int i = N - 2; i >= 0; i--) {
			right[i] = Math.max(right[i + 1], A[i]);
		}

		StringBuilder sb = new StringBuilder();

		sb.append(right[1]);
		sb.append("\n");
		for (int i = 1; i < N - 1; i++) {
			int l = left[i - 1];
			int r = right[i + 1];

			sb.append(Math.max(l, r));
			sb.append("\n");
		}
		sb.append(left[N - 2]);
		sb.append("\n");

		out.print(sb.toString());

	} Scanner sc = new Scanner(in); sc new Scanner(in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A = nextIntArray(sc, N); A nextIntArray(sc, N) nextIntArray sc N sc.close() sc.close sc int[] left = new int[N]; left new int[N] N int[] right = new int[N]; right new int[N] N left[0] = A[0] left[0] left 0 A[0] A 0 for (int i = 1; i < N; i++) {
			left[i] = Math.max(left[i - 1], A[i]);
		} int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
			left[i] = Math.max(left[i - 1], A[i]);
		} {
			left[i] = Math.max(left[i - 1], A[i]);
		} left[i] = Math.max(left[i - 1], A[i]) left[i] left i Math.max(left[i - 1], A[i]) Math.max Math left[i - 1] left i - 1 i 1 A[i] A i right[N - 1] = A[N - 1] right[N - 1] right N - 1 N 1 A[N - 1] A N - 1 N 1 for (int i = N - 2; i >= 0; i--) {
			right[i] = Math.max(right[i + 1], A[i]);
		} int i = N - 2; int i = N - 2; i N - 2 N 2 i >= 0 i 0 i-- i-- i {
			right[i] = Math.max(right[i + 1], A[i]);
		} {
			right[i] = Math.max(right[i + 1], A[i]);
		} right[i] = Math.max(right[i + 1], A[i]) right[i] right i Math.max(right[i + 1], A[i]) Math.max Math right[i + 1] right i + 1 i 1 A[i] A i StringBuilder sb = new StringBuilder(); sb new StringBuilder() sb.append(right[1]) sb.append sb right[1] right 1 sb.append("\n") sb.append sb "\n" for (int i = 1; i < N - 1; i++) {
			int l = left[i - 1];
			int r = right[i + 1];

			sb.append(Math.max(l, r));
			sb.append("\n");
		} int i = 1; int i = 1; i 1 i < N - 1 i N - 1 N 1 i++ i++ i {
			int l = left[i - 1];
			int r = right[i + 1];

			sb.append(Math.max(l, r));
			sb.append("\n");
		} {
			int l = left[i - 1];
			int r = right[i + 1];

			sb.append(Math.max(l, r));
			sb.append("\n");
		} int l = left[i - 1]; l left[i - 1] left i - 1 i 1 int r = right[i + 1]; r right[i + 1] right i + 1 i 1 sb.append(Math.max(l, r)) sb.append sb Math.max(l, r) Math.max Math l r sb.append("\n") sb.append sb "\n" sb.append(left[N - 2]) sb.append sb left[N - 2] left N - 2 N 2 sb.append("\n") sb.append sb "\n" out.print(sb.toString()) out.print out sb.toString() sb.toString sb String[] args args public static void main(String[] args) {
		new Main()._main(args);
	} main {
		new Main()._main(args);
	} new Main()._main(args) new Main()._main new Main() args String[] args args @SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	} nextIntArray {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	} int[] result = new int[n]; result new int[n] n for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			result[i] = sc.nextInt();
		} {
			result[i] = sc.nextInt();
		} result[i] = sc.nextInt() result[i] result i sc.nextInt() sc.nextInt sc return result; result Scanner sc sc int n n public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

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

		sc.close();

		int[] left = new int[N];
		int[] right = new int[N];

		left[0] = A[0];
		for (int i = 1; i < N; i++) {
			left[i] = Math.max(left[i - 1], A[i]);
		}

		right[N - 1] = A[N - 1];
		for (int i = N - 2; i >= 0; i--) {
			right[i] = Math.max(right[i + 1], A[i]);
		}

		StringBuilder sb = new StringBuilder();

		sb.append(right[1]);
		sb.append("\n");
		for (int i = 1; i < N - 1; i++) {
			int l = left[i - 1];
			int r = right[i + 1];

			sb.append(Math.max(l, r));
			sb.append("\n");
		}
		sb.append(left[N - 2]);
		sb.append("\n");

		out.print(sb.toString());

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

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

		sc.close();

		int[] left = new int[N];
		int[] right = new int[N];

		left[0] = A[0];
		for (int i = 1; i < N; i++) {
			left[i] = Math.max(left[i - 1], A[i]);
		}

		right[N - 1] = A[N - 1];
		for (int i = N - 2; i >= 0; i--) {
			right[i] = Math.max(right[i + 1], A[i]);
		}

		StringBuilder sb = new StringBuilder();

		sb.append(right[1]);
		sb.append("\n");
		for (int i = 1; i < N - 1; i++) {
			int l = left[i - 1];
			int r = right[i + 1];

			sb.append(Math.max(l, r));
			sb.append("\n");
		}
		sb.append(left[N - 2]);
		sb.append("\n");

		out.print(sb.toString());

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} Main
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

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

		sc.close();

		int[] left = new int[N];
		int[] right = new int[N];

		left[0] = A[0];
		for (int i = 1; i < N; i++) {
			left[i] = Math.max(left[i - 1], A[i]);
		}

		right[N - 1] = A[N - 1];
		for (int i = N - 2; i >= 0; i--) {
			right[i] = Math.max(right[i + 1], A[i]);
		}

		StringBuilder sb = new StringBuilder();

		sb.append(right[1]);
		sb.append("\n");
		for (int i = 1; i < N - 1; i++) {
			int l = left[i - 1];
			int r = right[i + 1];

			sb.append(Math.max(l, r));
			sb.append("\n");
		}
		sb.append(left[N - 2]);
		sb.append("\n");

		out.print(sb.toString());

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}
