

import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long n;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A= new long[N];
        long f = 0;
        long s = 0;
        int cf = 0;
        int cs = 0;
        for(int i = 0;i< N;i++){
            A[i] = sc.nextLong();
            if(f < A[i]){
                f = A[i];
                cf = i;
            }
        }
        for(int i = 0;i < N;i++){
            if(i == cf){
                continue;
            }
            if(s <= A[i]){
                s = A[i];
            }
        }
        for(int i =0;i < N;i++){
            if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            }
        }
    }

    int gcd(int m, int n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
} import java.util.*; util.* java public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long n;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A= new long[N];
        long f = 0;
        long s = 0;
        int cf = 0;
        int cs = 0;
        for(int i = 0;i< N;i++){
            A[i] = sc.nextLong();
            if(f < A[i]){
                f = A[i];
                cf = i;
            }
        }
        for(int i = 0;i < N;i++){
            if(i == cf){
                continue;
            }
            if(s <= A[i]){
                s = A[i];
            }
        }
        for(int i =0;i < N;i++){
            if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            }
        }
    }

    int gcd(int m, int n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
} Main long INF = Long.MAX_VALUE; INF Long.MAX_VALUE Long Long.MAX_VALUE long[] dp; dp long n; n public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A= new long[N];
        long f = 0;
        long s = 0;
        int cf = 0;
        int cs = 0;
        for(int i = 0;i< N;i++){
            A[i] = sc.nextLong();
            if(f < A[i]){
                f = A[i];
                cf = i;
            }
        }
        for(int i = 0;i < N;i++){
            if(i == cf){
                continue;
            }
            if(s <= A[i]){
                s = A[i];
            }
        }
        for(int i =0;i < N;i++){
            if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            }
        }
    } solve {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A= new long[N];
        long f = 0;
        long s = 0;
        int cf = 0;
        int cs = 0;
        for(int i = 0;i< N;i++){
            A[i] = sc.nextLong();
            if(f < A[i]){
                f = A[i];
                cf = i;
            }
        }
        for(int i = 0;i < N;i++){
            if(i == cf){
                continue;
            }
            if(s <= A[i]){
                s = A[i];
            }
        }
        for(int i =0;i < N;i++){
            if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc long[] A= new long[N]; A new long[N] N long f = 0; f 0 long s = 0; s 0 int cf = 0; cf 0 int cs = 0; cs 0 for(int i = 0;i< N;i++){
            A[i] = sc.nextLong();
            if(f < A[i]){
                f = A[i];
                cf = i;
            }
        } int i = 0; int i = 0; i 0 i< N i N i++ i++ i {
            A[i] = sc.nextLong();
            if(f < A[i]){
                f = A[i];
                cf = i;
            }
        } {
            A[i] = sc.nextLong();
            if(f < A[i]){
                f = A[i];
                cf = i;
            }
        } A[i] = sc.nextLong() A[i] A i sc.nextLong() sc.nextLong sc if(f < A[i]){
                f = A[i];
                cf = i;
            } f < A[i] f A[i] A i {
                f = A[i];
                cf = i;
            } f = A[i] f A[i] A i cf = i cf i for(int i = 0;i < N;i++){
            if(i == cf){
                continue;
            }
            if(s <= A[i]){
                s = A[i];
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(i == cf){
                continue;
            }
            if(s <= A[i]){
                s = A[i];
            }
        } {
            if(i == cf){
                continue;
            }
            if(s <= A[i]){
                s = A[i];
            }
        } if(i == cf){
                continue;
            } i == cf i cf {
                continue;
            } continue; if(s <= A[i]){
                s = A[i];
            } s <= A[i] s A[i] A i {
                s = A[i];
            } s = A[i] s A[i] A i for(int i =0;i < N;i++){
            if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            }
        } int i =0; int i =0; i 0 i < N i N i++ i++ i {
            if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            }
        } {
            if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            }
        } if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            } cf == i cf i {
                System.out.println(s);
            } System.out.println(s) System.out.println System.out System System.out s {
                System.out.println(f);
            } System.out.println(f) System.out.println System.out System System.out f int gcd(int m, int n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    } gcd {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    } if (m < n) {
            return gcd(n, m);
        } m < n m n {
            return gcd(n, m);
        } return gcd(n, m); gcd(n, m) gcd n m if (n == 0) {
            return m;
        } n == 0 n 0 {
            return m;
        } return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n int m m int n n public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long n;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A= new long[N];
        long f = 0;
        long s = 0;
        int cf = 0;
        int cs = 0;
        for(int i = 0;i< N;i++){
            A[i] = sc.nextLong();
            if(f < A[i]){
                f = A[i];
                cf = i;
            }
        }
        for(int i = 0;i < N;i++){
            if(i == cf){
                continue;
            }
            if(s <= A[i]){
                s = A[i];
            }
        }
        for(int i =0;i < N;i++){
            if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            }
        }
    }

    int gcd(int m, int n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
} public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long n;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A= new long[N];
        long f = 0;
        long s = 0;
        int cf = 0;
        int cs = 0;
        for(int i = 0;i< N;i++){
            A[i] = sc.nextLong();
            if(f < A[i]){
                f = A[i];
                cf = i;
            }
        }
        for(int i = 0;i < N;i++){
            if(i == cf){
                continue;
            }
            if(s <= A[i]){
                s = A[i];
            }
        }
        for(int i =0;i < N;i++){
            if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            }
        }
    }

    int gcd(int m, int n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
} Main


import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long n;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A= new long[N];
        long f = 0;
        long s = 0;
        int cf = 0;
        int cs = 0;
        for(int i = 0;i< N;i++){
            A[i] = sc.nextLong();
            if(f < A[i]){
                f = A[i];
                cf = i;
            }
        }
        for(int i = 0;i < N;i++){
            if(i == cf){
                continue;
            }
            if(s <= A[i]){
                s = A[i];
            }
        }
        for(int i =0;i < N;i++){
            if(cf == i){
                System.out.println(s);
            }else{
                System.out.println(f);
            }
        }
    }

    int gcd(int m, int n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
}
