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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        var n = long.Parse(Console.ReadLine());
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = long.Parse(Console.ReadLine());
        }


        long Max = a.Max();
        long Second = 0;
        IEnumerable<long> tmp = a.Where( value => value<Max );
        if (tmp.Count() ==  0 )
        {
            Second = Max;
            
        }
        else
        {
            Second = tmp.Max();
        }

        for (int i = 0; i < n; i++)
        {
            if (a[i] == Max)
            {
                Console.WriteLine(Second);
            }
            else
            {
                Console.WriteLine(Max);
            }
        }
    }
}
