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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=a[i];
		}
		scan.close();
		Arrays.sort(b);
		for(int i=0;i<n;i++) {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		}
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=a[i];
		}
		scan.close();
		Arrays.sort(b);
		for(int i=0;i<n;i++) {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		}
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=a[i];
		}
		scan.close();
		Arrays.sort(b);
		for(int i=0;i<n;i++) {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		}
	} main {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=a[i];
		}
		scan.close();
		Arrays.sort(b);
		for(int i=0;i<n;i++) {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int a[]=new int[n]; a new int[n] n int b[]=new int[n]; b new int[n] n for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=a[i];
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			a[i]=scan.nextInt();
			b[i]=a[i];
		} {
			a[i]=scan.nextInt();
			b[i]=a[i];
		} a[i]=scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan b[i]=a[i] b[i] b i a[i] a i scan.close() scan.close scan Arrays.sort(b) Arrays.sort Arrays b for(int i=0;i<n;i++) {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		} {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		} System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]) System.out.println System.out System System.out (a[i]!=b[n-1])?b[n-1]:b[n-2] (a[i]!=b[n-1]) a[i] a i b[n-1] b n-1 n 1 b[n-1] b n-1 n 1 b[n-2] b n-2 n 2 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=a[i];
		}
		scan.close();
		Arrays.sort(b);
		for(int i=0;i<n;i++) {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=a[i];
		}
		scan.close();
		Arrays.sort(b);
		for(int i=0;i<n;i++) {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		}
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=a[i];
		}
		scan.close();
		Arrays.sort(b);
		for(int i=0;i<n;i++) {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		}
	}
}