Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

This is a typical chess game where your opponent first places a random number of Knights, Rooks, Bishop, and Queens on an ‘N*N’ chessboard, and then you have to place your king safely on the chessboard such that it should not be under attack by any piece.

Given an ‘N*N’ chessboard with ‘K’ number of Knights, ‘R’ number of Rooks, ‘B’ number of Bishops, and ‘Q’ number of queens. Your task is to find out the number of squares on the chessboard such that your King is not checked by any of your opponent's pieces.

NOTE: If you don't know how to play chess and how chess pieces move, please refer to the below link (you can concentrate only on how the above-mentioned pieces move).

```
Refer to the explanation of Sample Input 1 for better understanding.
```

Detailed explanation

```
1 <= 'T' <= 10
2 <= 'N' <= 100
0 <= 'K' + ‘R’ + ‘B’ + ‘Q’ <= ‘N * N’
0 <= ‘i’, ‘j’ <= ‘N - 1’
It is guaranteed that sum of ‘N’ over all test cases is <= 1000
Time Limit: 1 sec
```

```
2
4
2
0 0
1 1
1
2 2
0
1
3 3
8
4
2 6
3 2
5 6
7 7
4
2 2
4 6
6 4
7 5
4
0 4
1 1
1 6
5 1
2
3 5
6 0
```

```
2
5
```

```
For the first test case,
```

```
The safe places are (0, 1) and (1, 0)
Hence, the output will be: 2
For the second test case,
```

```
The safe places are (0, 1), (0, 3), (1, 7), (3, 1), and (5, 7).
Hence, the output will be: 5
```

```
2
4
2
0 0
1 1
3
2 2
3 0
0 3
0
1
3 3
8
5
2 6
3 2
5 6
7 7
4 0
4
2 2
4 6
6 4
7 5
4
0 4
1 1
1 6
5 1
3
3 5
6 0
4 2
```

```
0
6
```