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

#PS0000282. Tổng chênh lệch tuyệt đối trong dãy đã sắp xếp (Sum of Absolute Differences in a Sorted Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tổng chênh lệch tuyệt đối trong dãy đã sắp xếp (Sum of Absolute Differences in a Sorted Array)

Sum of Absolute Differences in a Sorted Array

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer array a1,…,ana_1,\ldots,a_n in nondecreasing order, compute bi=∑j=1n∣ai−aj∣b_i=\sum_{j=1}^n |a_i-a_j| for every index ii. Equal elements still represent distinct positions. Output b1,…,bnb_1,\ldots,b_n in the original order.

Input

First line: nn. Second line: nn integers aia_i in nondecreasing order.

Output

Print nn integers bib_i on one line, separated by spaces.

Subtasks

  • Subtask 1 (20 points): 2≤n≤302\le n\le30; 1≤a1≤⋯≤an≤100001\le a_1\le\cdots\le a_n\le10000.
  • Subtask 2 (30 points): 2≤n≤1000002\le n\le100000; 1≤a1≤⋯≤an≤100001\le a_1\le\cdots\le a_n\le10000; a1=ana_1=a_n.
  • Subtask 3 (50 points): 2≤n≤1000002\le n\le100000; 1≤a1≤⋯≤an≤100001\le a_1\le\cdots\le a_n\le10000.

Example 1

Input

3
2 3 5

Output

4 3 5

Explanation

At 2: 0+1+3=4; at 3: 1+0+2=3; at 5: 3+2+0=5.

Example 2

Input

5
1 4 6 8 10

Output

24 15 13 15 21

Explanation

At 1: 0+3+5+7+9=24; at 6: 5+2+0+2+4=13; other positions are analogous.