atcoder#ABC134C. [ABC134C] Exception Handling

[ABC134C] Exception Handling

Score : 300300 points

Problem Statement

You are given a sequence of length NN: A1,A2,...,ANA_1, A_2, ..., A_N. For each integer ii between 11 and NN (inclusive), answer the following question:

  • Find the maximum value among the N1N-1 elements other than AiA_i in the sequence.

Constraints

  • 2N2000002 \leq N \leq 200000
  • 1Ai2000001 \leq A_i \leq 200000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1

::

ANA_N

Output

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

3
1
4
3
4
3
4
  • The maximum value among the two elements other than A1A_1, that is, A2=4A_2 = 4 and A3=3A_3 = 3, is 44.
  • The maximum value among the two elements other than A2A_2, that is, A1=1A_1 = 1 and A3=3A_3 = 3, is 33.
  • The maximum value among the two elements other than A3A_3, that is, A1=1A_1 = 1 and A2=4A_2 = 4, is 44.
2
5
5
5
5