#P17386. [PacNW 2025] Kth King

[PacNW 2025] Kth King

Problem Description

Reyjrland is represented by an integer array aa of length nn, where each element is the value of one city. For any array bb of length at least kk, let f(b,k)f(b,k) be its kkth-largest value.

The cities represent the likeness of the kkth king if f(b,k)f(b,k) is the same for every contiguous subarray bb of aa whose length is at least kk. A subarray is obtained by deleting zero or more elements from the beginning and zero or more elements from the end; an array is a subarray of itself.

Each day, the king may increase or decrease one city value by 11. For every kk from 11 through nn, find the minimum number of days needed to modify the original array so that it represents the likeness of the kkth king. Modifications for one value of kk do not carry over to another: the array is reset to its original values each time.

Input Format

The first line contains an integer nn (1n21051\le n\le2\cdot10^5).

Each of the next nn lines contains one integer aia_i (0ai1090\le a_i\le10^9).

Output Format

Output nn lines. Line kk contains the minimum number of days needed for the kkth king.

3
2
3
1
2
1
0
4
1000000000
1
1000000000
1
1999999998
999999999
0
0