Skip to main content
Back to problems
Codeforces
Easy
Arrays
Math
Simulation
Rook, Bishop and King

Count how many squares a rook, bishop, and king can attack from their starting positions on an 8×88 \times 8 chessboard.

Acceptance 0%
Problem Statement

You are given the coordinates of three chess pieces on a standard 8×88 \times 8 board: a rook, a bishop, and a king. For each piece, determine how many legal squares it can move to in one move, assuming the board is otherwise empty and pieces do not block one another.

  • A rook attacks all squares in the same row or column, except its current square.
  • A bishop attacks all squares on the same diagonal, except its current square.
  • A king can move to any adjacent square in one move, including diagonals, as long as it stays on the board.

Return the number of possible destination squares for each piece.

Input Format

Input

Three pairs of integers describing the positions of the rook, bishop, and king on an 8×88 \times 8 board.

Each coordinate is 1-indexed and lies in the range $1 to \8$.

Output Format

Output

Print three integers: the number of squares reachable in one move by the rook, bishop, and king, in that order.

Constraints

  • The board is 8×88 \times 8.
  • Coordinates are integers from $1 to \8$.
  • Pieces are considered independently on an otherwise empty board.
  • No piece blocking needs to be considered.
Examples
Sample cases returned by the problem API.

Example 1

Input

1 1 4 4 8 8

Output

14 13 3

Explanation

  • Rook at (1,1): 7 squares in its row and 7 in its column, total 14.
  • Bishop at (4,4): it can move along both diagonals to 13 squares total.
  • King at (8,8): only three adjacent squares remain on the board.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.