/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

import java.util.*;
import java.util.Collections; // sorting use
import java.io.*;
import static java.lang.System.*;

public class Main{
	public static void main(String[] args){
		int n;
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>();
		ArrayList<Integer> b = new ArrayList<Integer>();

		n = sc.nextInt();
		a = new ArrayList<Integer>();
		b = new ArrayList<Integer>();

		for(int i = 0; i < n; ++i){
			a.add(sc.nextInt());
			b.add(a.get(i));
		}
		Collections.sort(b);
		Collections.reverse(b);
		for(int i = 0; i < n; ++i){
			if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			}
		}
	}
} import java.util.*; util.* java import java.util.Collections; // sorting use Collections java.util import java.io.*; io.* java import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; public class Main{
	public static void main(String[] args){
		int n;
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>();
		ArrayList<Integer> b = new ArrayList<Integer>();

		n = sc.nextInt();
		a = new ArrayList<Integer>();
		b = new ArrayList<Integer>();

		for(int i = 0; i < n; ++i){
			a.add(sc.nextInt());
			b.add(a.get(i));
		}
		Collections.sort(b);
		Collections.reverse(b);
		for(int i = 0; i < n; ++i){
			if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			}
		}
	}
} Main public static void main(String[] args){
		int n;
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>();
		ArrayList<Integer> b = new ArrayList<Integer>();

		n = sc.nextInt();
		a = new ArrayList<Integer>();
		b = new ArrayList<Integer>();

		for(int i = 0; i < n; ++i){
			a.add(sc.nextInt());
			b.add(a.get(i));
		}
		Collections.sort(b);
		Collections.reverse(b);
		for(int i = 0; i < n; ++i){
			if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			}
		}
	} main {
		int n;
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>();
		ArrayList<Integer> b = new ArrayList<Integer>();

		n = sc.nextInt();
		a = new ArrayList<Integer>();
		b = new ArrayList<Integer>();

		for(int i = 0; i < n; ++i){
			a.add(sc.nextInt());
			b.add(a.get(i));
		}
		Collections.sort(b);
		Collections.reverse(b);
		for(int i = 0; i < n; ++i){
			if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			}
		}
	} int n; n Scanner sc = new Scanner(System.in); sc new Scanner(System.in) ArrayList<Integer> a = new ArrayList<Integer>(); a new ArrayList<Integer>() ArrayList<Integer> b = new ArrayList<Integer>(); b new ArrayList<Integer>() n = sc.nextInt() n sc.nextInt() sc.nextInt sc a = new ArrayList<Integer>() a new ArrayList<Integer>() b = new ArrayList<Integer>() b new ArrayList<Integer>() for(int i = 0; i < n; ++i){
			a.add(sc.nextInt());
			b.add(a.get(i));
		} int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
			a.add(sc.nextInt());
			b.add(a.get(i));
		} {
			a.add(sc.nextInt());
			b.add(a.get(i));
		} a.add(sc.nextInt()) a.add a sc.nextInt() sc.nextInt sc b.add(a.get(i)) b.add b a.get(i) a.get a i Collections.sort(b) Collections.sort Collections b Collections.reverse(b) Collections.reverse Collections b for(int i = 0; i < n; ++i){
			if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			}
		} int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
			if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			}
		} {
			if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			}
		} if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			} a.get(i) == b.get(0) a.get(i) a.get a i b.get(0) b.get b 0 {
				out.println(b.get(1));
			} out.println(b.get(1)) out.println out b.get(1) b.get b 1 {
				out.println(b.get(0));
			} out.println(b.get(0)) out.println out b.get(0) b.get b 0 String[] args args public class Main{
	public static void main(String[] args){
		int n;
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>();
		ArrayList<Integer> b = new ArrayList<Integer>();

		n = sc.nextInt();
		a = new ArrayList<Integer>();
		b = new ArrayList<Integer>();

		for(int i = 0; i < n; ++i){
			a.add(sc.nextInt());
			b.add(a.get(i));
		}
		Collections.sort(b);
		Collections.reverse(b);
		for(int i = 0; i < n; ++i){
			if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			}
		}
	}
} public class Main{
	public static void main(String[] args){
		int n;
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>();
		ArrayList<Integer> b = new ArrayList<Integer>();

		n = sc.nextInt();
		a = new ArrayList<Integer>();
		b = new ArrayList<Integer>();

		for(int i = 0; i < n; ++i){
			a.add(sc.nextInt());
			b.add(a.get(i));
		}
		Collections.sort(b);
		Collections.reverse(b);
		for(int i = 0; i < n; ++i){
			if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			}
		}
	}
} Main
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

import java.util.*;
import java.util.Collections; // sorting use
import java.io.*;
import static java.lang.System.*;

public class Main{
	public static void main(String[] args){
		int n;
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>();
		ArrayList<Integer> b = new ArrayList<Integer>();

		n = sc.nextInt();
		a = new ArrayList<Integer>();
		b = new ArrayList<Integer>();

		for(int i = 0; i < n; ++i){
			a.add(sc.nextInt());
			b.add(a.get(i));
		}
		Collections.sort(b);
		Collections.reverse(b);
		for(int i = 0; i < n; ++i){
			if(a.get(i) == b.get(0)){
				out.println(b.get(1));
			}
			else{
				out.println(b.get(0));
			}
		}
	}
}
