import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	Scanner scan = new Scanner(System.in);
	
	void compute() {
		int N = scan.nextInt();
		int m = 0;
		int n = 0;
		Integer[] t = new Integer[N];
		for(int i=0; i<N; i++) {
			t[i] = scan.nextInt();
			if(m < t[i]) {
				m = t[i];
				n = i;
			}
		}
		Arrays.sort(t, Collections.reverseOrder());
		for(int i=0; i<N; i++) {
			if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			}
		}
	}

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

} import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util public class Main {
	Scanner scan = new Scanner(System.in);
	
	void compute() {
		int N = scan.nextInt();
		int m = 0;
		int n = 0;
		Integer[] t = new Integer[N];
		for(int i=0; i<N; i++) {
			t[i] = scan.nextInt();
			if(m < t[i]) {
				m = t[i];
				n = i;
			}
		}
		Arrays.sort(t, Collections.reverseOrder());
		for(int i=0; i<N; i++) {
			if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			}
		}
	}

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

} Main Scanner scan = new Scanner(System.in); scan new Scanner(System.in) void compute() {
		int N = scan.nextInt();
		int m = 0;
		int n = 0;
		Integer[] t = new Integer[N];
		for(int i=0; i<N; i++) {
			t[i] = scan.nextInt();
			if(m < t[i]) {
				m = t[i];
				n = i;
			}
		}
		Arrays.sort(t, Collections.reverseOrder());
		for(int i=0; i<N; i++) {
			if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			}
		}
	} compute {
		int N = scan.nextInt();
		int m = 0;
		int n = 0;
		Integer[] t = new Integer[N];
		for(int i=0; i<N; i++) {
			t[i] = scan.nextInt();
			if(m < t[i]) {
				m = t[i];
				n = i;
			}
		}
		Arrays.sort(t, Collections.reverseOrder());
		for(int i=0; i<N; i++) {
			if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			}
		}
	} int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int m = 0; m 0 int n = 0; n 0 Integer[] t = new Integer[N]; t new Integer[N] N for(int i=0; i<N; i++) {
			t[i] = scan.nextInt();
			if(m < t[i]) {
				m = t[i];
				n = i;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			t[i] = scan.nextInt();
			if(m < t[i]) {
				m = t[i];
				n = i;
			}
		} {
			t[i] = scan.nextInt();
			if(m < t[i]) {
				m = t[i];
				n = i;
			}
		} t[i] = scan.nextInt() t[i] t i scan.nextInt() scan.nextInt scan if(m < t[i]) {
				m = t[i];
				n = i;
			} m < t[i] m t[i] t i {
				m = t[i];
				n = i;
			} m = t[i] m t[i] t i n = i n i Arrays.sort(t, Collections.reverseOrder()) Arrays.sort Arrays t Collections.reverseOrder() Collections.reverseOrder Collections for(int i=0; i<N; i++) {
			if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			}
		} {
			if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			}
		} if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			} n != i n i {
				System.out.println(m);
			} System.out.println(m) System.out.println System.out System System.out m {
				System.out.println(t[1]);
			} System.out.println(t[1]) System.out.println System.out System System.out t[1] t 1 public static void main(String[] args) {
		new Main().compute();
	} main {
		new Main().compute();
	} new Main().compute() new Main().compute new Main() String[] args args public class Main {
	Scanner scan = new Scanner(System.in);
	
	void compute() {
		int N = scan.nextInt();
		int m = 0;
		int n = 0;
		Integer[] t = new Integer[N];
		for(int i=0; i<N; i++) {
			t[i] = scan.nextInt();
			if(m < t[i]) {
				m = t[i];
				n = i;
			}
		}
		Arrays.sort(t, Collections.reverseOrder());
		for(int i=0; i<N; i++) {
			if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			}
		}
	}

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

} public class Main {
	Scanner scan = new Scanner(System.in);
	
	void compute() {
		int N = scan.nextInt();
		int m = 0;
		int n = 0;
		Integer[] t = new Integer[N];
		for(int i=0; i<N; i++) {
			t[i] = scan.nextInt();
			if(m < t[i]) {
				m = t[i];
				n = i;
			}
		}
		Arrays.sort(t, Collections.reverseOrder());
		for(int i=0; i<N; i++) {
			if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			}
		}
	}

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

} Main
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	Scanner scan = new Scanner(System.in);
	
	void compute() {
		int N = scan.nextInt();
		int m = 0;
		int n = 0;
		Integer[] t = new Integer[N];
		for(int i=0; i<N; i++) {
			t[i] = scan.nextInt();
			if(m < t[i]) {
				m = t[i];
				n = i;
			}
		}
		Arrays.sort(t, Collections.reverseOrder());
		for(int i=0; i<N; i++) {
			if(n != i) {
				System.out.println(m);
			} else {
				System.out.println(t[1]);
			}
		}
	}

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

}
