import java.io.*;
import java.util.*;
import java.util.Arrays;
import java.util.List;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int[] copyA = new int[N];
        copyA = (int[])A.clone();
        quick_sort(copyA, 0, N-1);
        int max = copyA[N - 1];
        int max2 = copyA[N - 2];
        for (int i = 0; i < N; i++) {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
        scan.close();
    }

    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
} import java.io.*; io.* java import java.util.*; util.* java import java.util.Arrays; Arrays java.util import java.util.List; List 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];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int[] copyA = new int[N];
        copyA = (int[])A.clone();
        quick_sort(copyA, 0, N-1);
        int max = copyA[N - 1];
        int max2 = copyA[N - 2];
        for (int i = 0; i < N; i++) {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
        scan.close();
    }

    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int[] copyA = new int[N];
        copyA = (int[])A.clone();
        quick_sort(copyA, 0, N-1);
        int max = copyA[N - 1];
        int max2 = copyA[N - 2];
        for (int i = 0; i < N; i++) {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
        scan.close();
    } main {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int[] copyA = new int[N];
        copyA = (int[])A.clone();
        quick_sort(copyA, 0, N-1);
        int max = copyA[N - 1];
        int max2 = copyA[N - 2];
        for (int i = 0; i < N; i++) {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
        scan.close();
    } 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 for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = scan.nextInt();
        } {
            A[i] = scan.nextInt();
        } A[i] = scan.nextInt() A[i] A i scan.nextInt() scan.nextInt scan int[] copyA = new int[N]; copyA new int[N] N copyA = (int[])A.clone() copyA (int[])A.clone() A.clone A quick_sort(copyA, 0, N-1) quick_sort copyA 0 N-1 N 1 int max = copyA[N - 1]; max copyA[N - 1] copyA N - 1 N 1 int max2 = copyA[N - 2]; max2 copyA[N - 2] copyA N - 2 N 2 for (int i = 0; i < N; i++) {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        } {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        } if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            } A[i] == max A[i] A i max {
                System.out.println(max2);
            } System.out.println(max2) System.out.println System.out System System.out max2 {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max scan.close() scan.close scan String[] args args static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    } quick_sort {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    } if (left >= right) {
            return;
        } left >= right left right {
            return;
        } return; int p = d[(left + right) / 2]; p d[(left + right) / 2] d (left + right) / 2 (left + right) left right 2 int l = left l left r = right r right tmp; tmp while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        } l <= r l r {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        } while (d[l] < p) {
                l++;
            } d[l] < p d[l] d l p {
                l++;
            } l++ l while (d[r] > p) {
                r--;
            } d[r] > p d[r] d r p {
                r--;
            } r-- r if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            } l <= r l r {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            } tmp = d[l] tmp d[l] d l d[l] = d[r] d[l] d l d[r] d r d[r] = tmp d[r] d r tmp l++ l r-- r quick_sort(d, left, r) quick_sort d left r quick_sort(d, l, right) quick_sort d l right int[] d d int left left int right right public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int[] copyA = new int[N];
        copyA = (int[])A.clone();
        quick_sort(copyA, 0, N-1);
        int max = copyA[N - 1];
        int max2 = copyA[N - 2];
        for (int i = 0; i < N; i++) {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
        scan.close();
    }

    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int[] copyA = new int[N];
        copyA = (int[])A.clone();
        quick_sort(copyA, 0, N-1);
        int max = copyA[N - 1];
        int max2 = copyA[N - 2];
        for (int i = 0; i < N; i++) {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
        scan.close();
    }

    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
} Main
import java.io.*;
import java.util.*;
import java.util.Arrays;
import java.util.List;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int[] copyA = new int[N];
        copyA = (int[])A.clone();
        quick_sort(copyA, 0, N-1);
        int max = copyA[N - 1];
        int max2 = copyA[N - 2];
        for (int i = 0; i < N; i++) {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
        scan.close();
    }

    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
}