cswork / OAOpen practice workspace

AmazonOA #227

Get Minimum Changes

Estimated MediumJudge-ready

Topics (AI-labelled)Hashing

Any element may be changed to a positive integer, and each changed position counts once. Every contiguous subarray of length k must have the same sum; find the minimum number of changes. Original elements may be non-positive; unchanged positions do not need to become positive. When k≥n, no change is needed.

Input

The first line contains n k; the second line contains the integer array. The original text had no numeric bounds; this site uses 1≤n,k≤200000, −10^9≤element≤10^9.

Output

Output a single integer, the answer.

Example 1

Input:

4 2
1 2 1 3

Output:

1

Example 2

Input:

2 1
-1 -1

Output:

0

Example 3

Input:

3 1
-1 -1 2

Output:

2

Example notes

The answers are 1, 0 and 2. In the last example 2 cannot be changed to −1; the only option is to change the two −1s to 2.

Editorial

Loading solution…