Demining
After the fighting, it became necessary to demine the area. It is known that the terrain is represented by a rectangular area measuring n by m, which may contain mines. The number of mines located in the corresponding terrain sector is represented by an integer x[ij]
(0 ≤ x[ij]
≤ 10^9
).
The military using a quadrocopter takes pictures of the area. Help them count the number of mines that are captured by the quadcopter if the quadcopter took k rectangular pictures of the area.
Input data
The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) - the number of rows and columns respectively.
The next n lines contain m integers x[ij]
(0 ≤ x[ij]
≤ 10^9
) - the number of mines in the corresponding sector.
The next line contains the number k (1 ≤ k ≤ 1000) - the number of shots taken from the quadcopter.
Next k lines contain the coordinates of rectangular images (four numbers each): y[1]
, y[2]
, x[1]
, x[2],
where
y[1]
is the line number where the snapshot starts,
y[2]
is the line number where the snapshot ends,
x[1]
is the column number where the snapshot starts,
x[2]
is the column number where the snapshot ends.
Output
Print a single number - the total number of mines that will be included in the pictures. Mines present on several pictures are counted once.