using System;
using System.IO;
using System.Text;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static object Solve(Scanner scan) {
        var N = scan.NextInt();
        var A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.NextInt();
        }
        Array.Sort(A);
        var sb = new StringBuilder();
        var max = A[^1];
        var next = A[^2];
        for (int i = 0; i < N; i++) {
            if (A[i] != max) {
                sb.Append(max).AppendLine();
                continue;
            }
            if (A[i] == max) sb.Append(next).AppendLine();
        }
        return sb.ToString();
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
}