#C5222. Replace Elements with Ranks

    ID: 48848 Type: Default 1000ms 256MiB

Replace Elements with Ranks

Replace Elements with Ranks

Given a list of integers, your task is to replace each element with its rank in the list. The rank of an element is its 1-indexed position in the sorted list of unique values. More formally, for each element (x) in the list, its rank is defined as (\text{rank}(x) = 1 + \text{index}(x, \text{sorted}({a : a \in list}))).

For example, for the list [100, 50, 50, 70, 60], the unique sorted list is [50, 60, 70, 100] and the resulting rank list is [4, 1, 1, 3, 2].

inputFormat

The input is given via stdin and consists of two lines. The first line contains an integer (n) representing the number of elements in the list. The second line contains (n) space-separated integers.

outputFormat

Output via stdout a single line with (n) space-separated integers, where each integer is the rank of the corresponding element from the input list.## sample

5
100 50 50 70 60
4 1 1 3 2

</p>