cswork / OAOpen practice workspace

AmazonOA #271

Maximize Sum of Array Multiplication

Estimated EasyJudge-ready

Topics (AI-labelled)GreedyIn-place Arrays

Return a permutation p of the original indices 1..n that maximizes Σ(i×data[p[i]]), where i runs from 1 to n. If several permutations give the same maximum sum, return the lexicographically smallest index permutation. You return the sequence of original indices, not the sum or the new position of each original element.

Input

The first line contains n and the second line contains data. On this site 1≤n≤200000 and −10^9≤data[i]≤10^9.

Output

Output n one-based original indices in the order of the optimal permutation, separated by spaces.

Example 1

Input:

5
3 6 1 4 2

Output:

3 5 1 4 2

Example 2

Input:

4
2 1 2 1

Output:

2 4 1 3

Example 3

Input:

3
-1 -2 -3

Output:

3 2 1

Example notes

The answers are 3 5 1 4 2, 2 4 1 3 and 3 2 1 respectively. Equal values appear with the smaller original index first.

Editorial

Loading solution…