import java.util.*;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int max1 = 0;
		int max2 = 0;
		int cnt[] = new int[200000+1];
		int a[] = new int[200000];
		for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		}
		for(int i=0; i<n; i++) {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		}
		sc.close();
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int max1 = 0;
		int max2 = 0;
		int cnt[] = new int[200000+1];
		int a[] = new int[200000];
		for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		}
		for(int i=0; i<n; i++) {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		}
		sc.close();
	}
} Main public static void main(String[] args) {
		Main main = new Main();
		main.run();
	} main {
		Main main = new Main();
		main.run();
	} Main main = new Main(); main new Main() main.run() main.run main String[] args args public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int max1 = 0;
		int max2 = 0;
		int cnt[] = new int[200000+1];
		int a[] = new int[200000];
		for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		}
		for(int i=0; i<n; i++) {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		}
		sc.close();
	} run {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int max1 = 0;
		int max2 = 0;
		int cnt[] = new int[200000+1];
		int a[] = new int[200000];
		for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		}
		for(int i=0; i<n; i++) {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int max1 = 0; max1 0 int max2 = 0; max2 0 int cnt[] = new int[200000+1]; cnt new int[200000+1] 200000+1 200000 1 int a[] = new int[200000]; a new int[200000] 200000 for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		} {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		} int v = sc.nextInt(); v sc.nextInt() sc.nextInt sc if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			} max1 < v max1 v {
				max2 = max1;
				max1 = v;
			} max2 = max1 max2 max1 max1 = v max1 v if(max2 < v){
				max2 = v;
			} max2 < v max2 v {
				max2 = v;
			} max2 = v max2 v a[i]=v a[i] a i v cnt[v]++ cnt[v] cnt v for(int i=0; i<n; i++) {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		} {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		} int v = a[i]; v a[i] a i if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			} v==max1 && cnt[v]==1 v==max1 v max1 cnt[v]==1 cnt[v] cnt v 1 {
				System.out.println(max2);
			} System.out.println(max2) System.out.println System.out System System.out max2 {
				System.out.println(max1);
			} System.out.println(max1) System.out.println System.out System System.out max1 sc.close() sc.close sc public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int max1 = 0;
		int max2 = 0;
		int cnt[] = new int[200000+1];
		int a[] = new int[200000];
		for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		}
		for(int i=0; i<n; i++) {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		}
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int max1 = 0;
		int max2 = 0;
		int cnt[] = new int[200000+1];
		int a[] = new int[200000];
		for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		}
		for(int i=0; i<n; i++) {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		}
		sc.close();
	}
} Main
import java.util.*;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int max1 = 0;
		int max2 = 0;
		int cnt[] = new int[200000+1];
		int a[] = new int[200000];
		for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		}
		for(int i=0; i<n; i++) {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		}
		sc.close();
	}
}
