#C8816. Valid Knight Path Checker

    ID: 52840 Type: Default 1000ms 256MiB

Valid Knight Path Checker

Valid Knight Path Checker

You are given the initial position of a knight on a standard 8x8 chessboard and a sequence of moves. The initial position is provided in standard chess notation (e.g., a1 to h8). Each move is represented by two integers indicating the relative change in the x (column) and y (row) directions. The knight moves in an "L" shape, meaning its move must be one of the following: \( (\pm2, \pm1) \) or \( (\pm1, \pm2) \).

Your task is to determine if the entire sequence of moves constitutes a valid knight path, i.e., each move is a legal knight move and the knight always remains within the board's boundaries.

Chessboard Coordinates:
Columns are associated with letters from a to h and rows with numbers from 1 to 8. The conversion to 0-indexed coordinates is given by:

[ x = \text{ord}(\text{position}[0]) - \text{ord}('a'), \quad y = \text{int}(\text{position}[1]) - 1 ]

If any move does not correspond to a legal knight move or if the knight moves off the board, output NO; otherwise, output YES.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains a string representing the initial chess position (e.g., e2).
  • The second line contains an integer n indicating the number of moves.
  • The next n lines each contain two space-separated integers representing the move offsets \(dx\) and \(dy\).

outputFormat

Output a single line to stdout with either YES if all moves are legal knight moves and remain within the boundaries of the chessboard, or NO otherwise.

## sample
e2
3
1 2
-2 1
2 1
YES