import java.util.*;

public class Main {
    static long mod = 1000000007;

    public static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        } else if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] lis = new int[n];

        for (int i = 0; i < n; ++i) {
            lis[i] = sc.nextInt();
        }
        int[] sorted = Arrays.copyOf(lis, n);
        Arrays.sort(sorted);

        for (int i = 0; i < n; ++i) {
            if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            }
        }
    }
} import java.util.*; util.* java public class Main {
    static long mod = 1000000007;

    public static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        } else if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] lis = new int[n];

        for (int i = 0; i < n; ++i) {
            lis[i] = sc.nextInt();
        }
        int[] sorted = Arrays.copyOf(lis, n);
        Arrays.sort(sorted);

        for (int i = 0; i < n; ++i) {
            if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            }
        }
    }
} Main static long mod = 1000000007; mod 1000000007 public static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        } else if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    } gcd {
        if (a == 0) {
            return b;
        } else if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    } if (a == 0) {
            return b;
        } else if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        } a == 0 a 0 {
            return b;
        } return b; b if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        } b == 0 b 0 {
            return a;
        } return a; a {
            return gcd(b, a % b);
        } return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] lis = new int[n];

        for (int i = 0; i < n; ++i) {
            lis[i] = sc.nextInt();
        }
        int[] sorted = Arrays.copyOf(lis, n);
        Arrays.sort(sorted);

        for (int i = 0; i < n; ++i) {
            if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] lis = new int[n];

        for (int i = 0; i < n; ++i) {
            lis[i] = sc.nextInt();
        }
        int[] sorted = Arrays.copyOf(lis, n);
        Arrays.sort(sorted);

        for (int i = 0; i < n; ++i) {
            if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] lis = new int[n]; lis new int[n] n for (int i = 0; i < n; ++i) {
            lis[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
            lis[i] = sc.nextInt();
        } {
            lis[i] = sc.nextInt();
        } lis[i] = sc.nextInt() lis[i] lis i sc.nextInt() sc.nextInt sc int[] sorted = Arrays.copyOf(lis, n); sorted Arrays.copyOf(lis, n) Arrays.copyOf Arrays lis n Arrays.sort(sorted) Arrays.sort Arrays sorted for (int i = 0; i < n; ++i) {
            if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            }
        } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
            if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            }
        } {
            if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            }
        } if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            } sorted[n-1] == lis[i] sorted[n-1] sorted n-1 n 1 lis[i] lis i {
                System.out.println(sorted[n-2]);
            } System.out.println(sorted[n-2]) System.out.println System.out System System.out sorted[n-2] sorted n-2 n 2 {
                System.out.println(sorted[n-1]);
            } System.out.println(sorted[n-1]) System.out.println System.out System System.out sorted[n-1] sorted n-1 n 1 String[] args args public class Main {
    static long mod = 1000000007;

    public static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        } else if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] lis = new int[n];

        for (int i = 0; i < n; ++i) {
            lis[i] = sc.nextInt();
        }
        int[] sorted = Arrays.copyOf(lis, n);
        Arrays.sort(sorted);

        for (int i = 0; i < n; ++i) {
            if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            }
        }
    }
} public class Main {
    static long mod = 1000000007;

    public static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        } else if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] lis = new int[n];

        for (int i = 0; i < n; ++i) {
            lis[i] = sc.nextInt();
        }
        int[] sorted = Arrays.copyOf(lis, n);
        Arrays.sort(sorted);

        for (int i = 0; i < n; ++i) {
            if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            }
        }
    }
} Main
import java.util.*;

public class Main {
    static long mod = 1000000007;

    public static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        } else if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] lis = new int[n];

        for (int i = 0; i < n; ++i) {
            lis[i] = sc.nextInt();
        }
        int[] sorted = Arrays.copyOf(lis, n);
        Arrays.sort(sorted);

        for (int i = 0; i < n; ++i) {
            if (sorted[n-1] == lis[i]) {
                System.out.println(sorted[n-2]);
            } else {
                System.out.println(sorted[n-1]);
            }
        }
    }
}
