atcoder#ARC133A. [ARC133A] Erase by Value

[ARC133A] Erase by Value

Score : 300300 points

Problem Statement

Given is a sequence of NN integers A=(A1,A2,,AN)A=(A_1,A_2,\cdots,A_N).

Snuke now chooses a value in AA. Let xx be the value chosen. Then, he makes an integer sequence aa by lining up all elements of AA that are not xx without changing the order.

Find the lexicographically smallest sequence that can be obtained as aa.

Constraints

  • 1N2000001 \leq N \leq 200000
  • 1AiN1 \leq A_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the elements of the lexicographically smallest aa, separated by spaces.

5
2 4 4 1 2
2 1 2

For example, when x=2x=2, we will have a=(4,4,1)a=(4,4,1). When x=4x=4, we will have a=(2,1,2)a=(2,1,2), which is the lexicographically smallest.

3
1 1 1

When x=1x=1, aa will be empty, which is obviously the lexicographically smallest. As a side note, the output may contain additional spaces or newlines.

5
1 1 2 3 3
1 1 2