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

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            List<Temp> array = new List<Temp>();
            for (int i = 0; i < count; i++)
            {
                array.Add(new Temp() { Index = i, Value = int.Parse(Console.ReadLine()) });
            }

            // 単純に1版大きいのは同じでそのindexの時だけ2番目が必要
            var groups = array.OrderByDescending(item => item.Value).GroupBy(item => item.Value);
            var indicies = groups.First().Select(group => group.Index);
            var first = groups.First().Key;

            int value = 0;
            for (int i = 0; i < count; i++)
            {
                if (indicies.Count() > 1)
                {
                    value = first;
                }
                else
                {
                    value = indicies.Contains(i) ? groups.ElementAt(1).Key : first;
                }
                Console.WriteLine(value);
            }
        }
    }
    struct Temp { public int Index { get; set; } public int Value { get; set; } }
}
