Hello coders, today we are going to solve Ada King Codechef Solution|Problem Code: ADAKNG.

### Problem

Chef Ada is training to defend her title of World Chess Champion.

To train her calculation skills, Ada placed a king on a chessboard. Remember that a chessboard has 88 rows and 88 columns (for the purposes of this problem, both the rows and the columns are numbered 11 through 88); let’s denote the square in row rr and column cc by (r,c)(r,c). A king on a square (r,c)(r,c) can move to another square (r′,c′)(r′,c′) if and only if (r′−r)2+(c′−c)2≤2(r′−r)2+(c′−c)2≤2.

Ada placed her king on the square (R,C)(R,C). Now, she is counting the number of squares that can be visited (reached) by the king in at most KK moves. Help Ada verify her answers.

### Input

• The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
• The first and only line of each test case contains three space-separated integers RR, CC and KK.

### Output

For each test case, print a single line containing one integer — the number of squares the king can visit.

### Constraints

• 1≤T≤5121≤T≤512
• 1≤R,C,K≤81≤R,C,K≤8

### Explanation

Example case 1: The king can stay on its original square or move to one of the squares circled in the following figure.

### Ada King CodeChef Solution in JAVA

```import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
public class Main {
static final int SIZE = 8;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int tc = 0; tc < T; ++tc) {
int K = sc.nextInt();
System.out.println(solve(K));
}
sc.close();
}
static String solve(int K) {
char[][] board = new char[SIZE][SIZE];
for (int r = 0; r < SIZE; ++r) {
for (int c = 0; c < SIZE; ++c) {
if (r == 0 && c == 0) {
board[r][c] = 'O';
--K;
} else if (K != 0) {
board[r][c] = '.';
--K;
} else {
board[r][c] = 'X';
}
}
}
return Arrays.stream(board).map(String::new).collect(Collectors.joining("\n"));
}
}```

Disclaimer: The above Problem (Ada King) is generated by CodeChef but the solution is provided by Chase2learn. This tutorial is only for Educational and Learning purpose.

Sharing Is Caring