JOI-kun took a picture of the night view. The picture consists of
Each pixel of the picture shows building, night sky, or star. Its color is white, black, or yellow, respectively.
For each
We say a rectangular region in the picture shows a constellation if the following two conditions are satisfied.
- There is no white pixel in the rectangular region.
- There are two or more yellow pixels in the rectangular region.
JOI-kun is tired with watching constellations. By painting some yellow pixels into black, he wants to make
a picture such that no rectangular region shows a constellation. However, the picture becomes unnatural if he
paints many yellow pixels. More precisely, if he paints the
Write a program which, given the information of the picture and the integer for each yellow pixel which describes how much the unnatural level is increased if the pixel is painted into black, calculates the minimum unnatural level of the picture after painting some yellow pixels such that no rectangular region shows a constellation.
Input Specification
Output Specification
Output the minimum unnatural level of the picture after painting some yellow pixels such that no rectangular region shows a constellation.
Constraints
Subtasks
- (14 points)
, . - (21 points)
, . - (65 points) No additional constraints.
Sample Input 1
5
1 3 4 2 3
3
1 5 3
4 3 2
2 4 2
Sample Output 1
2
Explanation for Sample 1
In this sample input, the rectangular region whose left-top vertex is the pixel

Sample Input 2
7
5 6 2 3 6 7 6
5
7 7 5
3 3 7
3 7 10
1 7 6
4 7 8
Sample Output 2
16
Explanation for Sample 2
In this sample input, it is optimal to paint the third yellow pixel and the fourth one.
Sample Input 3
8
6 8 5 7 3 4 2 1
10
8 2 9
6 6 7
8 3 18
5 8 17
8 5 3
5 5 3
5 4 8
1 8 13
1 7 5
7 4 13
Sample Output 3
44
Comments