You are given a sequence $$$a_1, a_2, \ldots, a_n$$$ of length $$$n$$$, consisting of ones and zeros.
Define the blockchain of a binary sequence as the list of lengths of blocks of equal elements in $$$a$$$. For example, $$$\text{blockchain}([1,0,0,1,1,1,0]) = [1,2,3,1]$$$, since the sequence consists of a single $$$1$$$, followed by two $$$0$$$s, followed by three $$$1$$$s, followed by a single $$$0$$$.
You are also given an integer sequence $$$b_1, b_2, \ldots, b_m$$$ of length $$$m$$$. Your goal is to make $$$\text{blockchain}(a)$$$ into a permutation of $$$b$$$, using the following operation:
What's the minimum number of operations you need?
The first line contains $$$n$$$ and $$$m$$$ ($$$1 \le m \le n \le 100$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$).
The third line contains $$$m$$$ integers $$$b_1, b_2, \ldots, b_m$$$ ($$$1 \le b_i \le n$$$).
It is guaranteed that $$$b_1 + b_2 + \ldots + b_m = n$$$.
Print the answer. We can show the goal is always achievable under the constraints of this problem.
7 41 0 0 1 0 1 01 3 1 2
1
4 10 1 0 14
2
In the first test, initially, $$$\text{blockchain}(a) = [1,2,1,1,1,1]$$$. But if we flip the value at index $$$5$$$, we get $$$a = [1,0,0,1,1,1,0]$$$, and so $$$\text{blockchain}(a)=[1,2,3,1]$$$. Since $$$[1,2,3,1]$$$ is a permutation of $$$[1,3,1,2]$$$, we have achieved our goal.
In the second test, initially $$$\text{blockchain}([0,1,0,1]) = [1,1,1,1]$$$. We have two options, both of which take two operations — we can either turn $$$a$$$ into $$$[0,0,0,0]$$$ or into $$$[1,1,1,1]$$$. Note that these two sequences are equivalent to the $$$\text{blockchain}$$$ function.