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

public class Main {

   void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int max = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        }

       int[] work = Arrays.copyOf(A, A.length);
       Arrays.sort(work);

       // Max が複数個あったら、どれを省いても出力はmaxにすべき。
       if (work[N - 1] == work[N - 2]) {
           for (int i = 0; i < N; i++) {
                System.out.println(max);
           }
           return;
       }

       // Max が一個しかなかったら、出力はmaxかnextMaxのどちらか。
       // なので、ここでnextMaxを求める。
       int nextMax = 0;
       for (int i = N - 1; i > 0; i--) {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        }

       for (int i = 0; i < N; i++) {
           if (A[i] == max) {
               System.out.println(nextMax);
           }
           else {
               System.out.println(max);
           }
       }


    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}
 import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

   void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int max = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        }

       int[] work = Arrays.copyOf(A, A.length);
       Arrays.sort(work);

       // Max が複数個あったら、どれを省いても出力はmaxにすべき。
       if (work[N - 1] == work[N - 2]) {
           for (int i = 0; i < N; i++) {
                System.out.println(max);
           }
           return;
       }

       // Max が一個しかなかったら、出力はmaxかnextMaxのどちらか。
       // なので、ここでnextMaxを求める。
       int nextMax = 0;
       for (int i = N - 1; i > 0; i--) {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        }

       for (int i = 0; i < N; i++) {
           if (A[i] == max) {
               System.out.println(nextMax);
           }
           else {
               System.out.println(max);
           }
       }


    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} Main void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int max = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        }

       int[] work = Arrays.copyOf(A, A.length);
       Arrays.sort(work);

       // Max が複数個あったら、どれを省いても出力はmaxにすべき。
       if (work[N - 1] == work[N - 2]) {
           for (int i = 0; i < N; i++) {
                System.out.println(max);
           }
           return;
       }

       // Max が一個しかなかったら、出力はmaxかnextMaxのどちらか。
       // なので、ここでnextMaxを求める。
       int nextMax = 0;
       for (int i = N - 1; i > 0; i--) {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        }

       for (int i = 0; i < N; i++) {
           if (A[i] == max) {
               System.out.println(nextMax);
           }
           else {
               System.out.println(max);
           }
       }


    } solve {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int max = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        }

       int[] work = Arrays.copyOf(A, A.length);
       Arrays.sort(work);

       // Max が複数個あったら、どれを省いても出力はmaxにすべき。
       if (work[N - 1] == work[N - 2]) {
           for (int i = 0; i < N; i++) {
                System.out.println(max);
           }
           return;
       }

       // Max が一個しかなかったら、出力はmaxかnextMaxのどちらか。
       // なので、ここでnextMaxを求める。
       int nextMax = 0;
       for (int i = N - 1; i > 0; i--) {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        }

       for (int i = 0; i < N; i++) {
           if (A[i] == max) {
               System.out.println(nextMax);
           }
           else {
               System.out.println(max);
           }
       }


    } 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 max = 0; max 0 for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        } {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc max = Math.max(max, A[i]) max Math.max(max, A[i]) Math.max Math max A[i] A i int[] work = Arrays.copyOf(A, A.length); work Arrays.copyOf(A, A.length) Arrays.copyOf Arrays A A.length A A.length Arrays.sort(work) Arrays.sort Arrays work if (work[N - 1] == work[N - 2]) {
           for (int i = 0; i < N; i++) {
                System.out.println(max);
           }
           return;
       } work[N - 1] == work[N - 2] work[N - 1] work N - 1 N 1 work[N - 2] work N - 2 N 2 {
           for (int i = 0; i < N; i++) {
                System.out.println(max);
           }
           return;
       } for (int i = 0; i < N; i++) {
                System.out.println(max);
           } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                System.out.println(max);
           } {
                System.out.println(max);
           } System.out.println(max) System.out.println System.out System System.out max return; int nextMax = 0; nextMax 0 for (int i = N - 1; i > 0; i--) {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        } int i = N - 1; int i = N - 1; i N - 1 N 1 i > 0 i 0 i-- i-- i {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        } {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        } if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            } work[i] != work[i - 1] work[i] work i work[i - 1] work i - 1 i 1 {
                nextMax = work[i - 1];
                break;
            } nextMax = work[i - 1] nextMax work[i - 1] work i - 1 i 1 break; for (int i = 0; i < N; i++) {
           if (A[i] == max) {
               System.out.println(nextMax);
           }
           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(nextMax);
           }
           else {
               System.out.println(max);
           }
       } {
           if (A[i] == max) {
               System.out.println(nextMax);
           }
           else {
               System.out.println(max);
           }
       } if (A[i] == max) {
               System.out.println(nextMax);
           }
           else {
               System.out.println(max);
           } A[i] == max A[i] A i max {
               System.out.println(nextMax);
           } System.out.println(nextMax) System.out.println System.out System System.out nextMax {
               System.out.println(max);
           } System.out.println(max) System.out.println System.out System System.out max // Main
    public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args public class Main {

   void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int max = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        }

       int[] work = Arrays.copyOf(A, A.length);
       Arrays.sort(work);

       // Max が複数個あったら、どれを省いても出力はmaxにすべき。
       if (work[N - 1] == work[N - 2]) {
           for (int i = 0; i < N; i++) {
                System.out.println(max);
           }
           return;
       }

       // Max が一個しかなかったら、出力はmaxかnextMaxのどちらか。
       // なので、ここでnextMaxを求める。
       int nextMax = 0;
       for (int i = N - 1; i > 0; i--) {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        }

       for (int i = 0; i < N; i++) {
           if (A[i] == max) {
               System.out.println(nextMax);
           }
           else {
               System.out.println(max);
           }
       }


    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} public class Main {

   void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int max = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        }

       int[] work = Arrays.copyOf(A, A.length);
       Arrays.sort(work);

       // Max が複数個あったら、どれを省いても出力はmaxにすべき。
       if (work[N - 1] == work[N - 2]) {
           for (int i = 0; i < N; i++) {
                System.out.println(max);
           }
           return;
       }

       // Max が一個しかなかったら、出力はmaxかnextMaxのどちらか。
       // なので、ここでnextMaxを求める。
       int nextMax = 0;
       for (int i = N - 1; i > 0; i--) {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        }

       for (int i = 0; i < N; i++) {
           if (A[i] == max) {
               System.out.println(nextMax);
           }
           else {
               System.out.println(max);
           }
       }


    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

   void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int max = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
        }

       int[] work = Arrays.copyOf(A, A.length);
       Arrays.sort(work);

       // Max が複数個あったら、どれを省いても出力はmaxにすべき。
       if (work[N - 1] == work[N - 2]) {
           for (int i = 0; i < N; i++) {
                System.out.println(max);
           }
           return;
       }

       // Max が一個しかなかったら、出力はmaxかnextMaxのどちらか。
       // なので、ここでnextMaxを求める。
       int nextMax = 0;
       for (int i = N - 1; i > 0; i--) {
            if (work[i] != work[i - 1]) {
                nextMax = work[i - 1];
                break;
            }
        }

       for (int i = 0; i < N; i++) {
           if (A[i] == max) {
               System.out.println(nextMax);
           }
           else {
               System.out.println(max);
           }
       }


    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

