import java.util.*;

public class Main {
	Scanner sc;
	int N;
	int[] A;
	
	int max;
	int maxIndex; // if dual max, -1
	
//=============
// constructor
//
	public Main() {
		sc = new Scanner(System.in);
	}
	
//==================
// instance methods
//
	void out(Object o) {
		System.out.println(o);
		System.out.flush();
	}
	
	int maxExcept(int index) {
		int max = -1;
		for (int i = 0; i < N; i++) {
			if (i == index) continue;
			if (max < A[i]) max = A[i];
		}
		return max;
	}
	
	public void exec() throws Exception {
		N = sc.nextInt();
		A = new int[N]; // 0, 1, ... (N-1)
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int[] copy = Arrays.copyOf(A, N);
		Arrays.sort(copy);
		max = copy[N-1];
		
		int maxcnt = 0;
		maxIndex = -1;
		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			}
		}
		if (maxcnt > 1) maxIndex = -1;
		
		for (int i = 0; i < N; i++) {
			if (i == maxIndex) out(copy[N-2]);
			else out(max);
		}
	}
	
//======
// main
//
	public static void main(String[] args) throws Exception {
		Main m = new Main();
		m.exec();
	}

} import java.util.*; util.* java public class Main {
	Scanner sc;
	int N;
	int[] A;
	
	int max;
	int maxIndex; // if dual max, -1
	
//=============
// constructor
//
	public Main() {
		sc = new Scanner(System.in);
	}
	
//==================
// instance methods
//
	void out(Object o) {
		System.out.println(o);
		System.out.flush();
	}
	
	int maxExcept(int index) {
		int max = -1;
		for (int i = 0; i < N; i++) {
			if (i == index) continue;
			if (max < A[i]) max = A[i];
		}
		return max;
	}
	
	public void exec() throws Exception {
		N = sc.nextInt();
		A = new int[N]; // 0, 1, ... (N-1)
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int[] copy = Arrays.copyOf(A, N);
		Arrays.sort(copy);
		max = copy[N-1];
		
		int maxcnt = 0;
		maxIndex = -1;
		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			}
		}
		if (maxcnt > 1) maxIndex = -1;
		
		for (int i = 0; i < N; i++) {
			if (i == maxIndex) out(copy[N-2]);
			else out(max);
		}
	}
	
//======
// main
//
	public static void main(String[] args) throws Exception {
		Main m = new Main();
		m.exec();
	}

} Main Scanner sc; sc int N; N int[] A; A int max; max int maxIndex; // if dual max, -1 maxIndex //=============
// constructor
//
	public Main() {
		sc = new Scanner(System.in);
	} Main {
		sc = new Scanner(System.in);
	} sc = new Scanner(System.in) sc new Scanner(System.in) //==================
// instance methods
//
	void out(Object o) {
		System.out.println(o);
		System.out.flush();
	} out {
		System.out.println(o);
		System.out.flush();
	} System.out.println(o) System.out.println System.out System System.out o System.out.flush() System.out.flush System.out System System.out Object o o int maxExcept(int index) {
		int max = -1;
		for (int i = 0; i < N; i++) {
			if (i == index) continue;
			if (max < A[i]) max = A[i];
		}
		return max;
	} maxExcept {
		int max = -1;
		for (int i = 0; i < N; i++) {
			if (i == index) continue;
			if (max < A[i]) max = A[i];
		}
		return max;
	} int max = -1; max -1 1 for (int i = 0; i < N; i++) {
			if (i == index) continue;
			if (max < A[i]) max = A[i];
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (i == index) continue;
			if (max < A[i]) max = A[i];
		} {
			if (i == index) continue;
			if (max < A[i]) max = A[i];
		} if (i == index) continue; i == index i index continue; if (max < A[i]) max = A[i]; max < A[i] max A[i] A i max = A[i] max A[i] A i return max; max int index index public void exec() throws Exception {
		N = sc.nextInt();
		A = new int[N]; // 0, 1, ... (N-1)
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int[] copy = Arrays.copyOf(A, N);
		Arrays.sort(copy);
		max = copy[N-1];
		
		int maxcnt = 0;
		maxIndex = -1;
		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			}
		}
		if (maxcnt > 1) maxIndex = -1;
		
		for (int i = 0; i < N; i++) {
			if (i == maxIndex) out(copy[N-2]);
			else out(max);
		}
	} exec {
		N = sc.nextInt();
		A = new int[N]; // 0, 1, ... (N-1)
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int[] copy = Arrays.copyOf(A, N);
		Arrays.sort(copy);
		max = copy[N-1];
		
		int maxcnt = 0;
		maxIndex = -1;
		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			}
		}
		if (maxcnt > 1) maxIndex = -1;
		
		for (int i = 0; i < N; i++) {
			if (i == maxIndex) out(copy[N-2]);
			else out(max);
		}
	} N = sc.nextInt() N sc.nextInt() sc.nextInt sc A = new int[N] A new int[N] N for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			A[i] = sc.nextInt();
		} {
			A[i] = sc.nextInt();
		} A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int[] copy = Arrays.copyOf(A, N); copy Arrays.copyOf(A, N) Arrays.copyOf Arrays A N Arrays.sort(copy) Arrays.sort Arrays copy max = copy[N-1] max copy[N-1] copy N-1 N 1 int maxcnt = 0; maxcnt 0 maxIndex = -1 maxIndex -1 1 for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			}
		} {
			if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			}
		} if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			} A[i] == max A[i] A i max {
				maxcnt++;
				maxIndex = i;
			} maxcnt++ maxcnt maxIndex = i maxIndex i if (maxcnt > 1) maxIndex = -1; maxcnt > 1 maxcnt 1 maxIndex = -1 maxIndex -1 1 for (int i = 0; i < N; i++) {
			if (i == maxIndex) out(copy[N-2]);
			else out(max);
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (i == maxIndex) out(copy[N-2]);
			else out(max);
		} {
			if (i == maxIndex) out(copy[N-2]);
			else out(max);
		} if (i == maxIndex) out(copy[N-2]);
			else out(max); i == maxIndex i maxIndex out(copy[N-2]) out copy[N-2] copy N-2 N 2 out(max) out max //======
// main
//
	public static void main(String[] args) throws Exception {
		Main m = new Main();
		m.exec();
	} main {
		Main m = new Main();
		m.exec();
	} Main m = new Main(); m new Main() m.exec() m.exec m String[] args args public class Main {
	Scanner sc;
	int N;
	int[] A;
	
	int max;
	int maxIndex; // if dual max, -1
	
//=============
// constructor
//
	public Main() {
		sc = new Scanner(System.in);
	}
	
//==================
// instance methods
//
	void out(Object o) {
		System.out.println(o);
		System.out.flush();
	}
	
	int maxExcept(int index) {
		int max = -1;
		for (int i = 0; i < N; i++) {
			if (i == index) continue;
			if (max < A[i]) max = A[i];
		}
		return max;
	}
	
	public void exec() throws Exception {
		N = sc.nextInt();
		A = new int[N]; // 0, 1, ... (N-1)
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int[] copy = Arrays.copyOf(A, N);
		Arrays.sort(copy);
		max = copy[N-1];
		
		int maxcnt = 0;
		maxIndex = -1;
		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			}
		}
		if (maxcnt > 1) maxIndex = -1;
		
		for (int i = 0; i < N; i++) {
			if (i == maxIndex) out(copy[N-2]);
			else out(max);
		}
	}
	
//======
// main
//
	public static void main(String[] args) throws Exception {
		Main m = new Main();
		m.exec();
	}

} public class Main {
	Scanner sc;
	int N;
	int[] A;
	
	int max;
	int maxIndex; // if dual max, -1
	
//=============
// constructor
//
	public Main() {
		sc = new Scanner(System.in);
	}
	
//==================
// instance methods
//
	void out(Object o) {
		System.out.println(o);
		System.out.flush();
	}
	
	int maxExcept(int index) {
		int max = -1;
		for (int i = 0; i < N; i++) {
			if (i == index) continue;
			if (max < A[i]) max = A[i];
		}
		return max;
	}
	
	public void exec() throws Exception {
		N = sc.nextInt();
		A = new int[N]; // 0, 1, ... (N-1)
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int[] copy = Arrays.copyOf(A, N);
		Arrays.sort(copy);
		max = copy[N-1];
		
		int maxcnt = 0;
		maxIndex = -1;
		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			}
		}
		if (maxcnt > 1) maxIndex = -1;
		
		for (int i = 0; i < N; i++) {
			if (i == maxIndex) out(copy[N-2]);
			else out(max);
		}
	}
	
//======
// main
//
	public static void main(String[] args) throws Exception {
		Main m = new Main();
		m.exec();
	}

} Main
import java.util.*;

public class Main {
	Scanner sc;
	int N;
	int[] A;
	
	int max;
	int maxIndex; // if dual max, -1
	
//=============
// constructor
//
	public Main() {
		sc = new Scanner(System.in);
	}
	
//==================
// instance methods
//
	void out(Object o) {
		System.out.println(o);
		System.out.flush();
	}
	
	int maxExcept(int index) {
		int max = -1;
		for (int i = 0; i < N; i++) {
			if (i == index) continue;
			if (max < A[i]) max = A[i];
		}
		return max;
	}
	
	public void exec() throws Exception {
		N = sc.nextInt();
		A = new int[N]; // 0, 1, ... (N-1)
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int[] copy = Arrays.copyOf(A, N);
		Arrays.sort(copy);
		max = copy[N-1];
		
		int maxcnt = 0;
		maxIndex = -1;
		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				maxcnt++;
				maxIndex = i;
			}
		}
		if (maxcnt > 1) maxIndex = -1;
		
		for (int i = 0; i < N; i++) {
			if (i == maxIndex) out(copy[N-2]);
			else out(max);
		}
	}
	
//======
// main
//
	public static void main(String[] args) throws Exception {
		Main m = new Main();
		m.exec();
	}

}