#K75492. Knight's Moves

    ID: 34431 Type: Default 1000ms 256MiB

Knight's Moves

Knight's Moves

On an 8x8 chessboard, a knight moves in an 'L' shape. Given the knight's starting position and a set of obstacles on the board, determine the number of distinct squares the knight can move to in one move without landing on an obstacle or moving off the board.

The knight's move is defined as moving two squares in one direction and then one square perpendicular to that direction. Note that obstacles can appear more than once in the input; however, they should be considered as a single blocked position.

The valid moves from a position \( (k_x, k_y) \) are those positions \( (x,y) \) which satisfy:

  • \( 1 \leq x \leq 8 \) and \( 1 \leq y \leq 8 \)
  • \( (x,y) \) is one of the knight's moves from \( (k_x, k_y) \)
  • \( (x,y) \) is not an obstacle

Your task is to implement the logic to count the number of valid moves.

inputFormat

The input is given via standard input in the following format:

 k_x k_y
 n
 x1 y1
 x2 y2
 ...
 xn yn

The first line contains two integers \(k_x\) and \(k_y\), representing the knight's current position. The second line contains a single integer \(n\) which is the number of obstacles. The following \(n\) lines each contain two integers \(x_i\) and \(y_i\) representing the coordinates of an obstacle.

outputFormat

Output a single integer to standard output representing the number of valid moves the knight can make.

## sample
4 4
4
5 6
3 2
5 2
3 6
4