eolymp
bolt
Try our new interface for solving problems
Problems

Lisa’s Sequences

Lisa’s Sequences

Lisa loves playing with the sequences of integers. When she gets a new integer sequence ai of length n, she starts looking for all monotone subsequences. A monotone subsequence [l, r] is defined by two indices l and r (1l < rn) such that ∀i = l, l + 1, ..., r - 1: aiai+1 or ∀i = l, l + 1, ..., r - 1: aiai+1.

Lisa considers a sequence ai to be boring if there is a monotone subsequence [l, r] that is as long as her boredom threshold k, that is when r - l + 1 = k.

Lucas has a sequence bi that he wants to present to Lisa, but the sequence might be boring for Lisa. So, he wants to change some elements of his sequence bi, so that Lisa does not get bored playing with it. However, Lucas is lazy and wants to change as few elements of the sequence bi as possible. Your task is to help Lucas find the required changes.

Input

The first line contains two integers n and k (3kn106) - the length of the sequence and Lisa’s boredom threshold. The second line contains n integers bi (1bi99999) - the original sequence that Lucas has.

Output

On the first line output an integer m - the minimal number of elements in bi that needs to be changed to make the sequence not boring for Lisa. On the second line output n integers ai (0ai105), so that the sequence of integers ai is not boring for Lisa and is different from the original sequence bi in exactly m positions.

Time limit 3 seconds
Memory limit 512 MiB
Input example #1
5 3
1 2 3 4 5
Output example #1
2
1 0 3 0 5
Input example #2
6 3
1 1 1 1 1 1
Output example #2
3
1 100000 0 1 0 1
Input example #3
6 4
1 1 4 4 1 1
Output example #3
1
1 1 4 0 1 1
Input example #4
6 4
4 4 4 2 2 2
Output example #4
2
4 4 0 2 0 2
Input example #5
6 4
4 4 4 3 4 4
Output example #5
1
4 4 100000 3 4 4
Input example #6
8 4
2 1 1 3 3 1 1 2
Output example #6
2
2 1 1 3 0 1 0 2
Input example #7
10 4
1 1 1 2 2 1 1 2 2 1
Output example #7
2
1 1 100000 2 2 100000 1 2 2 1
Input example #8
7 5
5 4 4 3 4 4 4
Output example #8
0
5 4 4 3 4 4 4
Input example #9
10 10
1 1 1 1 1 1 1 1 1 1
Output example #9
1
1 1 1 1 1 1 1 1 0 1
Source 2022 ICPC, NERC, December 7