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

#CC0000014. Đếm phần tử nhỏ hơn ở phía sau (Count of Smaller Numbers After Self)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Đếm phần tử nhỏ hơn ở phía sau (Count of Smaller Numbers After Self)

Count of Smaller Numbers After Self

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

For each element of an integer array, count the elements strictly smaller than it to its right. Equal elements are not counted. Report these counts in the original position order.

Input

The first line contains nn. The next line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n; negative values and duplicates are allowed.

Output

Print exactly nn space-separated integers c1,c2,…,cnc_1,c_2,\ldots,c_n in one line. Here cic_i counts indices j>ij>i with aj<aia_j<a_i.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; −104≤ai≤104-10^4\le a_i\le 10^4 for every ii.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le 1500; −104≤ai≤104-10^4\le a_i\le 10^4 for every ii.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; −104≤ai≤104-10^4\le a_i\le 10^4 for every ii.

Examples

Input

4
5 2 6 1

Output

2 1 1 0

Explanation

To the right of 55, the values 22 and 11 are smaller, giving 22. To the right of 22, only 11 is smaller, giving 11. To the right of 66, only 11 is smaller, giving 11. The last element has no elements to its right, giving 00.