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());
        var max = A.Max();
        var secondmax = B.Max();

        if (max == secondmax)
            for (int i = 0; i < N; ++i)
                Console.WriteLine(max);
        else
        {
            var indx = B.IndexOf(B.Max());
          for(int i = 0; i < indx - 1; ++i)
            {
                Console.WriteLine(max);
            }
            Console.WriteLine(secondmax);
            for(int i = indx + 1; i < N; ++i)
            {
                Console.WriteLine(max);
            }

        }


    }

}

