PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000004. Biến đổi mảng thành thứ hạng (Rank Transform of an Array)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Biến đổi mảng thành thứ hạng (Rank Transform of an Array)

Rank Transform of an Array

Source: LeetCode Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer array, replace every element with its rank among its distinct values. The smallest value has rank 11; equal values share a rank; ranks increase consecutively; the original element order is preserved.

Input

The first line contains NN. If N>0N>0, the next line contains NN integers a1,…,aNa_1,\ldots,a_N.

Output

Print the NN ranks on one line separated by spaces. For N=0N=0, print no values.

Subtasks

  • Subtask 1 (20 points): 0≤N≤350\le N\le 35; −109≤ai≤109-10^9\le a_i\le 10^9 (when N>0N>0).
  • Subtask 2 (30 points): 0≤N≤25000\le N\le 2500; −109≤ai≤109-10^9\le a_i\le 10^9 (when N>0N>0).
  • Subtask 3 (50 points): 0≤N≤1050\le N\le 10^5; −109≤ai≤109-10^9\le a_i\le 10^9 (when N>0N>0).

Examples

Input

5
-4 10 -4 7 0

Output

1 4 1 3 2

Explanation

The sorted unique values are −4,0,7,10-4,0,7,10. Both occurrences of −4-4 receive rank 11.