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 sprt = array.OrderByDescending(item => item.Value).GroupBy(item => item.Value);
            //var indexies = sprt.First().Select(group => group.Index);
            //var first = sprt.First().Key;
            //var second = 
            foreach (var item in array)
            {
                Console.WriteLine(array.Max((a) =>
                { if (a.Index != item.Index)
                    {
                       return  a.Value;
                    }
                else
                    { return 0; }

                }));
            }

            //List<int> i_first = new List<int>();
            //int v_first = 0;
            //int v_second = 0;
            //int max = array.Max();
            //int max = array.M
            //for (int i = 0; i < count; i++)
            //{
            //    if (array[i] == max)
            //    {
            //        i_first.Add(i);
            //    }
            //    else
            //    {
            //    }
                
            //    Console.WriteLine(max);
            //}
  
        }
    }
    struct Temp { public int Index { get; set; } public int Value { get; set; } }
}
