Codeforces Round 218 (Div. 2)
A
K-Periodic Array
Codeforces
1000
原题
←B →
翻译中…

This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.

翻译中…

Array $*a*$ is $*k*$-period if its length is divisible by $*k*$ and there is such array $*b*$ of length $*k*$, that $*a*$ is represented by array $*b*$ written exactly image times consecutively. In other words, array $*a*$ is $*k*$-periodic, if it has period of length $*k*$.

翻译中…

For example, any array is $*n*$-periodic, where $*n*$ is the array length. Array $[2, 1, 2, 1, 2, 1]$ is at the same time 2-periodic and 6-periodic and array $[1, 2, 1, 1, 2, 1, 1, 2, 1]$ is at the same time 3-periodic and 9-periodic.

翻译中…

For the given array $*a*$, consisting only of numbers one and two, find the minimum number of elements to change to make the array $*k*$-periodic. If the array already is $*k*$-periodic, then the required value equals $0$.

翻译中…

Input

翻译中…

The first line of the input contains a pair of integers $*n*$, $*k*$ ($1 ≤ *k* ≤ *n* ≤ 100)$, where $*n*$ is the length of the array and the value $*n*$ is divisible by $*k*$. The second line contains the sequence of elements of the given array $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($1 ≤ *a*_{*i*} ≤ 2$), $*a*_{*i*}$ is the $*i*$-th element of the array.

翻译中…

Output

翻译中…

Print the minimum number of array elements we need to change to make the array $*k*$-periodic. If the array already is $*k*$-periodic, then print 0.

翻译中…

Note

翻译中…

In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to $[2, 1, 2, 1, 2, 1]$.

翻译中…

In the second sample, the given array already is 4-periodic.

翻译中…

In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as $[1, 1, 1, 1, 1, 1, 1, 1, 1]$ — this array is simultaneously 1-, 3- and 9-periodic.

翻译中…

样例

Input #1
6 2
2 1 2 2 2 1
Output #1
1
InputCopy OutputCopy
Input #2
8 4
1 1 2 1 1 1 2 1
Output #2
0
InputCopy OutputCopy
Input #3
9 3
2 1 1 1 2 1 1 1 2
Output #3
3
InputCopy OutputCopy
题目信息
题号
371A
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。