using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = new List<int>();
        for (int i = 0; i < N; ++i)
            A.Add(int.Parse(Console.ReadLine()));
        var B = new List<int>(A);
        B.Remove(B.Max());

        if (A.Max() == B.Max())
            for (int i = 0; i < N; ++i)
                Console.WriteLine(A.Max());
        else
        {
            A.ForEach(delegate (int i)
            {
                if (A.Max() == i)
                {
                    var exce = new List<int>(A);
                    exce.Remove(i);
                    Console.WriteLine(exce.Max());
                }
                else
                {
                    Console.WriteLine(A.Max());
                }

            });

        }


    }

}

