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

#BS0000130. Tổng các số lớn hơn phần tử hiện tại (Sum of Numbers Greater Than Me)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tổng các số lớn hơn phần tử hiện tại (Sum of Numbers Greater Than Me)

Sum of Numbers Greater Than Me

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn integers A1,…,AnA_1,\ldots,A_n, for each index ii calculate the sum of all array elements strictly greater than AiA_i. Equal-valued elements do not contribute. Count repeated larger values at all their distinct positions. Return results in original array order.

Input

The first line contains nn. The second line contains nn integers A1,…,AnA_1,\ldots,A_n.

Output

Print nn integers; integer ii is the sum of elements strictly greater than AiA_i.

Subtasks

  • Subtask 1 (20 points): 1≤n≤501\le n\le 50; 1≤Ai≤1061\le A_i\le10^6, 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤25001\le n\le 2500; 1≤Ai≤1061\le A_i\le10^6, 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤Ai≤1061\le A_i\le10^6, 1≤i≤n1\le i\le n.

Examples

Input

5
1 4 1 4 2

Output

10 0 10 0 8

Explanation

For value 11 (positions 1 and 3), larger elements are 4,4,24,4,2, summing to 1010. For value 44 (positions 2 and 4), there is no larger value so the sum is 00. For 22 (position 5), the two values 44 sum to 88. Output 10 0 10 0 8.