using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = new int[N];
        for(int i = 0; i < N; i++)
        {
            A[i] = int.Parse(Console.ReadLine());
        }
        int MaxA = A.Max();
        int count = 0;
        int secondMax = 0;
        for(int i = 0; i < N; i++)
        {
            if(A[i] == MaxA)
            {
                count += 1;
            }
            if(A[i] < MaxA)
            {
                secondMax = A[i];
            }
        }
        for (int i = 0; i < N; i++)
        {
            if(A[i] == MaxA && count > 1)
            {
                Console.WriteLine(MaxA);
            }
            else if(A[i] == MaxA && count <= 1)
            {
                Console.WriteLine(secondMax);
            }
            else
            {
                Console.WriteLine(MaxA);
            }
        }
    }
}