import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	int[] b = new int[n];
	for (int i=0; i<n; i++) {
	    a[i] = sc.nextInt();
	    b[i] = a[i];
	}
	Arrays.sort(b);
	StringBuilder sb = new StringBuilder();
	for (int i=0; i<n; i++) {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	}
	System.out.print(sb.toString());
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	int[] b = new int[n];
	for (int i=0; i<n; i++) {
	    a[i] = sc.nextInt();
	    b[i] = a[i];
	}
	Arrays.sort(b);
	StringBuilder sb = new StringBuilder();
	for (int i=0; i<n; i++) {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	}
	System.out.print(sb.toString());
    }
} Main public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	int[] b = new int[n];
	for (int i=0; i<n; i++) {
	    a[i] = sc.nextInt();
	    b[i] = a[i];
	}
	Arrays.sort(b);
	StringBuilder sb = new StringBuilder();
	for (int i=0; i<n; i++) {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	}
	System.out.print(sb.toString());
    } main {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	int[] b = new int[n];
	for (int i=0; i<n; i++) {
	    a[i] = sc.nextInt();
	    b[i] = a[i];
	}
	Arrays.sort(b);
	StringBuilder sb = new StringBuilder();
	for (int i=0; i<n; i++) {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	}
	System.out.print(sb.toString());
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc 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] = sc.nextInt();
	    b[i] = a[i];
	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
	    a[i] = sc.nextInt();
	    b[i] = a[i];
	} {
	    a[i] = sc.nextInt();
	    b[i] = a[i];
	} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc b[i] = a[i] b[i] b i a[i] a i Arrays.sort(b) Arrays.sort Arrays b StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i=0; i<n; i++) {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	} {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	} if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); } b[n-1] == a[i] b[n-1] b n-1 n 1 a[i] a i sb.append(b[n-2]+"\n") sb.append sb b[n-2]+"\n" b[n-2] b n-2 n 2 "\n" { sb.append(b[n-1]+"\n"); } sb.append(b[n-1]+"\n") sb.append sb b[n-1]+"\n" b[n-1] b n-1 n 1 "\n" System.out.print(sb.toString()) System.out.print System.out System System.out sb.toString() sb.toString sb String[] args args public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	int[] b = new int[n];
	for (int i=0; i<n; i++) {
	    a[i] = sc.nextInt();
	    b[i] = a[i];
	}
	Arrays.sort(b);
	StringBuilder sb = new StringBuilder();
	for (int i=0; i<n; i++) {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	}
	System.out.print(sb.toString());
    }
} public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	int[] b = new int[n];
	for (int i=0; i<n; i++) {
	    a[i] = sc.nextInt();
	    b[i] = a[i];
	}
	Arrays.sort(b);
	StringBuilder sb = new StringBuilder();
	for (int i=0; i<n; i++) {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	}
	System.out.print(sb.toString());
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	int[] b = new int[n];
	for (int i=0; i<n; i++) {
	    a[i] = sc.nextInt();
	    b[i] = a[i];
	}
	Arrays.sort(b);
	StringBuilder sb = new StringBuilder();
	for (int i=0; i<n; i++) {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	}
	System.out.print(sb.toString());
    }
}
