You are given a chessboard, a white piece and a black piece. Each piece can be a king, a queen, a rook, a bishop, or a knight. In how many ways can you place the two pieces so that no piece threatens the other piece? For instance, these are three of the 3612 ways to place two kings on the board:

smallboard,
showmover=false,
label=false,
maxfield=h8,
setpieces=ka1,Kb3
smallboard,
showmover=false,
label=false,
maxfield=h8,
setpieces=Ka1,kb3
smallboard,
showmover=false,
label=false,
maxfield=h8,
setpieces=Kd5,kh7

Input

Input consists of several cases, each one with two chars to indicate the pieces: ‘K’ for a king, ‘Q’ for a queen, ‘R’ for a rook, ‘B’ for a bishop, and ‘N’ for a knight.

Output

For every case, print the number of ways the place the given pieces on the board.

Public test cases

**Input**

K K R B Q N

**Output**

3612 2576 2240

Information

- Author
- Enrique Jiménez
- Language
- English
- Official solutions
- C++
- User solutions
- C++