using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {

            string input = Console.ReadLine();
            int N = int.Parse(input);
            int[] ary = new int[N];

            for(int i = 0; i < N; i ++ )
            {
                input = Console.ReadLine();
                int tmp = int.Parse(input);

                if (i == 0)
                {
                    ary[i] = tmp;
                }
                else if (i == 1)
                {
                    ary[i] = ary[0];
                } else
                {
                    ary[i] = ary[i - 1] < ary[i - 2] ? ary[i - 2] : ary[i - 1];
                }

                for(int j = 0; j < i; j++ )
                {
                    if(ary[j] < tmp)
                    {
                        ary[j] = tmp;
                    }
                }
            }


            for(int i = 0; i < N; i++ )
            {
                Console.WriteLine(ary[i]);
            }


            return;
        }



    }
}
