cswork / OAOpen practice workspace

AmazonOA #67

Sort Bug Report Frequencies

Estimated EasyJudge-ready

Topics (AI-labelled)HashingIn-place Arrays

Sort all bug IDs in ascending order of frequency; ties in frequency are broken by ID in ascending order, and duplicates are kept.

Input

The first line contains n (1..200000), and the second line contains n IDs (1..1000000).

Output

Output the n sorted IDs.

Example 1

Input:

5
3 1 2 2 4

Output:

1 3 4 2 2

Example 2

Input:

2
2 1

Output:

1 2

Example 3

Input:

4
1 1 2 2

Output:

1 1 2 2

Example notes

Example 1: 1, 3, 4 each appear once and are output first by ID; 2 appears twice and goes last. Example 2: equal frequencies, output 1 2. Example 3: both frequencies are 2, output 1 1 2 2.

Editorial

Loading solution…