#P6814. Circular Roulette Moves
Circular Roulette Moves
Circular Roulette Moves
This problem involves a special board called a circular roulette which has m positions numbered from 1 to m. Position 1 is the center and the remaining positions 2 through m form the rim arranged in a circle. Initially, there are a white pieces and b black pieces placed on distinct positions. Note that the pieces are placed arbitrarily – they may be on the rim and possibly even on the center.
White moves first. In one move a white piece can be moved to an adjacent position provided that the destination cell is empty. The adjacencies are defined as follows:
- If the white piece is on the rim (i.e. its position is between 2 and m):
- It can move to its two rim neighbors. The rim positions are arranged in a cycle. That is, if the piece is at position 2 then its left neighbor is position m and if it is at position m then its right neighbor is position 2.
- It can also move to the center (position 1) if that position is empty.
- If the white piece is on the center (position 1):
- It can move to any rim position (positions 2 through m) that is empty.
Your task is to calculate the total number of legal moves available for white given the initial board configuration.
Example: Suppose m = 9, a = 1, b = 0 and the only white piece is on position 8. Since the piece is on the rim its two adjacent rim neighbors are positions 7 and 9, and if the center (position 1) is empty, that move is also legal. Hence, there are 3 legal moves: moving to 7, 9, or 1.
inputFormat
The input is given in three lines:
- The first line contains three integers m, a and b where m (m ≥ 3) is the total number of positions, a is the number of white pieces, and b is the number of black pieces. Note that pieces may be on any position (including the center).
- The second line contains a distinct integers representing the positions of the white pieces.
- The third line contains b distinct integers representing the positions of the black pieces.
It is guaranteed that all given positions are between 1 and m (inclusive).
outputFormat
Output a single integer – the total number of legal moves available for white.
sample
9 1 0
8
3