#d1306. 树上逆序对

树上逆序对

Inversions on a Tree

Problem Description

For a rooted tree, define an inversion on the tree as an ordered pair (i,fai)(i, fa_i) satisfying ai<afaia_i < a_{fa_i}, where faifa_i denotes the parent of node ii.

For a kk-ary tree, the set of child indices of node ii is exactly all integers in [1,n]∩[k(i−1)+2,ki+1][1, n] \cap [k(i-1)+2, ki+1].

Given the weights a1,a2,…,ana_1, a_2, \dots, a_n of nn nodes, for each k=1,2,…,n−1k = 1, 2, \dots, n-1 compute the number of inversions on the tree when these nn nodes form a kk-ary tree.

Input Format

The first line contains an integer nn, the number of nodes (2≤n≤2×1052 \le n \le 2 \times 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n, the node weights (1≤ai≤1091 \le a_i \le 10^9).

Output Format

Output one line with n−1n-1 integers, the numbers of inversions for k=1,2,…,n−1k = 1, 2, \dots, n-1 respectively.

Sample Input

5
5 4 5 4 3

Sample Output

3 2 3 3