#icpc2013summerwarmingUpc. [icpc2013summer_warmingUp_c]Containers
[icpc2013summer_warmingUp_c]Containers
Description
Some containers are piled up in land of .
The land is separated into cells. Each of the containers is on one of the cells.
Figure 1
Figure 2: from The Sky
Figure 3: from The Front
Figure 4: from The Side
Given the photograph from the sky, front, and side respectively, calculate how many containers are piled up in the minimum.
Input
The first line of the input file contains the integers and (), the number of height and width of the land.
Each of the following lines gives the photograph from the sky.
The value of means,
0
: no containers are piled up in ,
1
: some containers are piled up in .
The next line gives the photograph from the front.
The integer is the number of the containers seen in -th row.()
The next line gives the photograph from the side.
The integer is the number of the containers seen in -th column.()
Output
Output the minimum number of the containers.
If the photographs are inconsistent, just output -1
, instead.
Sample Input
2 3
0 1 0
1 1 1
2 3 2
2 3
Sample Output
9
Sample Input
4 6
1 1 0 1 0 0
0 0 1 0 0 1
0 1 0 0 0 1
0 0 1 0 1 0
1 2 1 2 1 1
2 1 2 1
Sample Output
11