Problem:
Score : 300 points

Problem Statement

You are given a sequence of length N: A_1, A_2, ..., A_N.
For each integer i between 1 and N (inclusive), answer the following question:

Find the maximum value among the N-1 elements other than A_i in the sequence.

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 200000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.

Sample Input 1

3
1
4
3

Sample Output 1

4
3
4

The maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.

The maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.

The maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.

Sample Input 2

2
5
5

Sample Output 2

5
5

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

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

namespace codeTester.contest190720
{
    class ProblemC
    {
        static int n = 0;
        static List<long> values = new List<long>();
        static List<long> answer = new List<long>();

        public static void Main(string[] args)
        {
            Input();
            Logic();
            Output();
        }

        static void Input()
        {
            n = int.Parse(Console.ReadLine());
            values = ReadIndentationSeparatedValues(n);
        }

        public static List<long> ReadSpaceSeparatedValues()
        {
            List<long> values = new List<long>();
            string[] inputs = Console.ReadLine().Split(' ');
            foreach (string input in inputs)
            {
                values.Add(long.Parse(input));
            }

            return values;
        }

        public static List<long> ReadIndentationSeparatedValues(int num)
        {
            List<long> values = new List<long>();
            for (int i = 0; i < num; i++)
            {
                string input = Console.ReadLine();
                values.Add(long.Parse(input));
            }

            return values;
        }

        static void Logic()
        {
            // 最大値を除外したものを考えれば良い。
            List<long> sortedA = values.OrderByDescending(v => v).ToList();
            long max = sortedA[0];
            long semimax = sortedA[1];
            foreach(long v in values)
            {
                answer.Add(v == max ? semimax : max);
            }
        }

        static void Output()
        {
            foreach(long a in answer)
            {
                Console.WriteLine(a.ToString());

            }
        }

        static void DebugPrint(string msg)
        {
            // 提出時に消す
            // Console.WriteLine(msg);
        }
    }
}