T - Covering
Time limit1sMemory limit512 MB
Place one T-tetromino per special cell, centered on it, without overlap or leaving the grid, to maximize the total covered weight.
Problem
If you have ever played Tetris, you might know that one of the figures looks as follows:

We call this figure a T-tetromino. A tetromino is a connected geometric figure made of four cells. The cell marked with × is the center cell.
Manca draws a rectangular grid with rows and columns and writes a number into each cell. Rows are numbered from 0 to , and columns from 0 to . She also marks some cells as special, for example by painting them red. Then she asks her friend Nika to place T-tetrominoes on the grid under these conditions:
- The number of T-tetrominoes must equal the number of special cells. The center cell of each T-tetromino must lie on a special cell.
- No two T-tetrominoes may overlap.
- Every T-tetromino must lie completely inside the grid.
A T-tetromino has four orientations: ┬, ┴, ├, and ┤.
If the conditions cannot be met, Nika answers No. Otherwise, she finds a placement that maximizes the sum of the numbers in the cells covered by the T-tetrominoes, and tells Manca that maximum sum.
Write a program that helps Nika solve this puzzle.
Input
The first line contains integers and . Each of the following lines contains integers in the interval . The -th integer in the -th line is the number written in the cell at row and column .
The next line contains an integer with . Each of the following lines contains integers and , the row and column of the -th special cell. The list of special cells has no duplicates.
Output
Print the maximum possible sum of the numbers in the cells covered by the T-tetrominoes. If no valid placement exists, print No.