using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Main
{
    public static class Program
    {
        static void Main(string[] arg)
        {
            int n = int.Parse(Console.ReadLine());
            var array = GetIntList(Console.ReadLine());
            int answer = 0;
            var list = new List<int>();
            int max = 0;
            int semimax = 0;
            bool maxes = false;

            for(int i = 0;i<n;i++){
                int num = int.Parse(Console.ReadLine());
                list.Add(num);
                if(num > max){
                    semimax = max;
                    max = num;
                }
                else if(num > semimax){
                    semimax = num;
                }
            }
            if(list.Where(x => x==max).Count() > 1)maxes = true;

            for(int i=0;i<n;i++){
                if(list[i] < max){
                    Console.WriteLine(max);
                }
                else{
                    if(maxes){
                        Console.WriteLine(max);
                    }
                    else{
                        Console.WriteLine(semimax);
                    }
            }

            // Console.WriteLine(answer);
            Console.ReadLine();
 
        }}
        
        #region libraries
        private static int[] GetIntList(string line)
        {
            return line.Split(' ').Select(x => int.Parse(x)).ToArray();
 
        }
        private static double[] GetDoubleList(string line)
        {
            return line.Split(' ').Select(x => double.Parse(x)).ToArray();
 
        }
        private static ulong[] GetUlongList(string line)
        {
            return line.Split(' ').Select(x => ulong.Parse(x)).ToArray();
        }
        private static long[] GetLongList(string line)
        {
            return line.Split(' ').Select(x => long.Parse(x)).ToArray();
        }
        private static int SearchNearest(this IEnumerable<int> list, int target)
        {
            var min = list.Min(c => Math.Abs(c - target));
            return list.First(c => Math.Abs(c - target) == min);
        }
        public static bool IsOdd(int i)
        {
            return i % 2 == 1 ? true : false;
        }
        public static int Gcd(int a,int b)
        {
            if(a < b)
            {
                Gcd(b, a);
            }
            while (b != 0)
            {
                var rm = a % b;
                a = b;
                b = rm;
            }
            return a;
        }
        #endregion
    }
}