import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			map.put(i, a);
			A[i] = a;
		}
		sc.close();
		// System.out.println("--------------");
		Arrays.sort(A);
		for(int i = 0; i < N; i++) {
			int except = map.get(i);
			System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]);
		}
	}
}	 import java.util.Arrays; Arrays java.util import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			map.put(i, a);
			A[i] = a;
		}
		sc.close();
		// System.out.println("--------------");
		Arrays.sort(A);
		for(int i = 0; i < N; i++) {
			int except = map.get(i);
			System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			map.put(i, a);
			A[i] = a;
		}
		sc.close();
		// System.out.println("--------------");
		Arrays.sort(A);
		for(int i = 0; i < N; i++) {
			int except = map.get(i);
			System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			map.put(i, a);
			A[i] = a;
		}
		sc.close();
		// System.out.println("--------------");
		Arrays.sort(A);
		for(int i = 0; i < N; i++) {
			int except = map.get(i);
			System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc Map<Integer, Integer> map = new HashMap<Integer, Integer>(); map new HashMap<Integer, Integer>() int[] A = new int[N]; A new int[N] N for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			map.put(i, a);
			A[i] = a;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int a = sc.nextInt();
			map.put(i, a);
			A[i] = a;
		} {
			int a = sc.nextInt();
			map.put(i, a);
			A[i] = a;
		} int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc map.put(i, a) map.put map i a A[i] = a A[i] A i a sc.close() sc.close sc Arrays.sort(A) Arrays.sort Arrays A for(int i = 0; i < N; i++) {
			int except = map.get(i);
			System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]);
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int except = map.get(i);
			System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]);
		} {
			int except = map.get(i);
			System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]);
		} int except = map.get(i); except map.get(i) map.get map i System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]) System.out.println System.out System System.out A[N - 1] == except ? A[N - 2] : A[N - 1] A[N - 1] == except A[N - 1] A N - 1 N 1 except A[N - 2] A N - 2 N 2 A[N - 1] A N - 1 N 1 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			map.put(i, a);
			A[i] = a;
		}
		sc.close();
		// System.out.println("--------------");
		Arrays.sort(A);
		for(int i = 0; i < N; i++) {
			int except = map.get(i);
			System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			map.put(i, a);
			A[i] = a;
		}
		sc.close();
		// System.out.println("--------------");
		Arrays.sort(A);
		for(int i = 0; i < N; i++) {
			int except = map.get(i);
			System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]);
		}
	}
} Main
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			map.put(i, a);
			A[i] = a;
		}
		sc.close();
		// System.out.println("--------------");
		Arrays.sort(A);
		for(int i = 0; i < N; i++) {
			int except = map.get(i);
			System.out.println(A[N - 1] == except ? A[N - 2] : A[N - 1]);
		}
	}
}	
