#arc085d. [arc085_d]NRE
[arc085_d]NRE
Problem Statement
You are given a sequence with all zeros, and a sequence consisting of and . The length of both is .
You can perform kinds of operations. The -th operation is as follows:
- Replace each of with .
Minimize the hamming distance between and , that is, the number of such that , by performing some of the operations.
Constraints
- consists of and .
- If , either or .
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible hamming distance.
Sample Input 1
3
1 0 1
1
1 3
Sample Output 1
1
If you choose to perform the operation, will become , for a hamming distance of .
Sample Input 2
3
1 0 1
2
1 1
3 3
Sample Output 2
0
If both operations are performed, will become , for a hamming distance of .
Sample Input 3
3
1 0 1
2
1 1
2 3
Sample Output 3
1
Sample Input 4
5
0 1 0 1 0
1
1 5
Sample Output 4
2
It may be optimal to perform no operation.
Sample Input 5
9
0 1 0 1 1 1 0 1 0
3
1 4
5 8
6 7
Sample Output 5
3
Sample Input 6
15
1 1 0 0 0 0 0 0 1 0 1 1 1 0 0
9
4 10
13 14
1 7
4 14
9 11
2 6
7 8
3 12
7 13
Sample Output 6
5
Sample Input 7
10
0 0 0 1 0 0 1 1 1 0
7
1 4
2 5
1 3
6 7
9 9
1 5
7 9
Sample Output 7
1