Aakriti, Avantika and Mehak are playing Hopscotch (Stapu). The arena is in the form of 2d Array with little modification as shown below:
So, in this game the person who is playing need to collect stones present on the tiles that are adjacent to the tile on which the player stands. Mehak is playing and if Avantika asks her to collect stones then she will move only one step in any direction to collect all the stones from the tiles that are touching the edge with the tile on which she is standing. But if Aakriti ask her, she will move two steps in any direction and then collect stones. Help Mehak to count the total number of stones she collected.
The first line of input contains integer T denoting the number of test cases. Each test case has subsequent two lines of input. The first line contains 2 integer inputs i.e N and M the size of the matrix W.Next line contains the N X M space separated elements of the matrix W i.e. stones. Next line takes a boolean and 2 integers input i.e. a , i, j. If a is 0 means Avantika asks her to collect and 1 means Aakriti asks her and (i,j) denotes the index of tile where she is standing.
For each test case, output is the total number of stones she will collect.
5 9 7
6 4 5
8 1 2
0 1 1
5 9 7
6 4 5
8 1 2
1 1 1
1. 0 1 1 means Avantika asks her to collect so she will move one step and collect stones from the tiles that have common edge. Here (0,1), (1,0), (1,2), (2,1), (2,2), (2,0) have common edge with the tile (1,1). So adding all 9+6+5+8+1+2=31.
2. 1 1 1 means Aakriti asks her to collect so she will move two steps. Here (0,0) and (0,2) are the tiles , hence adding them 5+7 =12.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.