cswork / OAOpen practice workspace

AmazonOA #370

Get Mean Rank Count

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & RangesHashing

The array is a permutation of 1..n. For each x=1..n, find the number of non-empty contiguous subarrays whose average is exactly x. Different index ranges are counted separately.

Input

The first line contains n and the second line contains n distinct ranks. The original bounds are 1≤n≤1000, and the array is exactly a permutation of 1..n, not a general array with duplicate values.

Output

Output n integers; the x-th is the number of ranges whose mean is x.

Example 1

Input:

5
1 2 3 4 5

Output:

1 2 3 2 1

Example 2

Input:

4
4 3 2 1

Output:

1 2 2 1

Example 3

Input:

7
4 7 3 6 5 2 1

Output:

1 1 1 4 4 1 1

Example notes

The outputs of the three public examples are 1 2 3 2 1; 1 2 2 1; and 1 1 1 4 4 1 1, checked by independent enumeration or direct simulation.

Editorial

Loading solution…