You are playing a marble game. You place some marbles in some of the cells of a square board such that each occupied cell contains only 1 marble.
A cell x is considered a dominated cell if it meets either of the following criteria:
Two cells are considered adjacent if they have a common side. Each cell can have four adjacent cells. The cells in the corners and along the sides will have fewer adjacent cells.
Each cell has a separate value for the following parameters:
At the end of the game, the number of points that you score is equal to the difference between the total cost of placing the marbles into the cells and the total benefits that you receive from the dominated cells.
Write a program to calculate the total points that you score based on the following information:
Input format
Output format
For each test case, print the total number of points scored in the game.
Constraints
0≤T≤100
2≤N≤20
0≤cost[i][j],benefit[i][j]≤9
0≤i,j≤N
For the first case, all the cells are dominated (they either have a marble or have a marble in all adjacent cells). Hence total score is 6 - 2 = 4.
For the second case, again all the cells are dominated. Hence total score = 4 - 18 = -14