import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] ARRAY = new int[N];

        int maxIndex = 0;
        int max = 0;
        for (int i=0; i<N; i++) {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        }

        int[] MAX_ARRAY = new int[N];
        for (int i=0; i<N; i++) {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        }

        for (int i=0; i<N; i++) {
            System.out.println(MAX_ARRAY[i]);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] ARRAY = new int[N];

        int maxIndex = 0;
        int max = 0;
        for (int i=0; i<N; i++) {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        }

        int[] MAX_ARRAY = new int[N];
        for (int i=0; i<N; i++) {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        }

        for (int i=0; i<N; i++) {
            System.out.println(MAX_ARRAY[i]);
        }
    }
} Main public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] ARRAY = new int[N];

        int maxIndex = 0;
        int max = 0;
        for (int i=0; i<N; i++) {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        }

        int[] MAX_ARRAY = new int[N];
        for (int i=0; i<N; i++) {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        }

        for (int i=0; i<N; i++) {
            System.out.println(MAX_ARRAY[i]);
        }
    } main {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] ARRAY = new int[N];

        int maxIndex = 0;
        int max = 0;
        for (int i=0; i<N; i++) {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        }

        int[] MAX_ARRAY = new int[N];
        for (int i=0; i<N; i++) {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        }

        for (int i=0; i<N; i++) {
            System.out.println(MAX_ARRAY[i]);
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] ARRAY = new int[N]; ARRAY new int[N] N int maxIndex = 0; maxIndex 0 int max = 0; max 0 for (int i=0; i<N; i++) {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        } {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        } ARRAY[i] = scanner.nextInt() ARRAY[i] ARRAY i scanner.nextInt() scanner.nextInt scanner if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            } ARRAY[i] > max ARRAY[i] ARRAY i max {
                max = ARRAY[i];
                maxIndex = i;
            } max = ARRAY[i] max ARRAY[i] ARRAY i maxIndex = i maxIndex i int[] MAX_ARRAY = new int[N]; MAX_ARRAY new int[N] N for (int i=0; i<N; i++) {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        } {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        } if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            } i == maxIndex i maxIndex {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            } int max2 = 0; max2 0 for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                } int k=0; int k=0; k 0 k<N k N k++ k++ k {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                } {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                } if (k == i) {
                        continue;
                    } k == i k i {
                        continue;
                    } continue; if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    } ARRAY[k] > max2 ARRAY[k] ARRAY k max2 {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    } max2 = ARRAY[k] max2 ARRAY[k] ARRAY k MAX_ARRAY[i] = max2 MAX_ARRAY[i] MAX_ARRAY i max2 continue; MAX_ARRAY[i] = max MAX_ARRAY[i] MAX_ARRAY i max for (int i=0; i<N; i++) {
            System.out.println(MAX_ARRAY[i]);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            System.out.println(MAX_ARRAY[i]);
        } {
            System.out.println(MAX_ARRAY[i]);
        } System.out.println(MAX_ARRAY[i]) System.out.println System.out System System.out MAX_ARRAY[i] MAX_ARRAY i String[] args args public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] ARRAY = new int[N];

        int maxIndex = 0;
        int max = 0;
        for (int i=0; i<N; i++) {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        }

        int[] MAX_ARRAY = new int[N];
        for (int i=0; i<N; i++) {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        }

        for (int i=0; i<N; i++) {
            System.out.println(MAX_ARRAY[i]);
        }
    }
} public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] ARRAY = new int[N];

        int maxIndex = 0;
        int max = 0;
        for (int i=0; i<N; i++) {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        }

        int[] MAX_ARRAY = new int[N];
        for (int i=0; i<N; i++) {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        }

        for (int i=0; i<N; i++) {
            System.out.println(MAX_ARRAY[i]);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] ARRAY = new int[N];

        int maxIndex = 0;
        int max = 0;
        for (int i=0; i<N; i++) {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        }

        int[] MAX_ARRAY = new int[N];
        for (int i=0; i<N; i++) {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        }

        for (int i=0; i<N; i++) {
            System.out.println(MAX_ARRAY[i]);
        }
    }
}
