#B3818. Escape Routes of the Pink Rabbits
Escape Routes of the Pink Rabbits
Escape Routes of the Pink Rabbits
In this problem, the computer screen is divided into rows and columns forming a grid. The cell in the -th row and -th column is represented by .
Suddenly, F's computer is infected with the "Full Screen Pink Rabbit" virus, which causes male pink rabbits and female pink rabbits to appear on the screen.
A pink rabbit located at is said to have an escape channel in one of the four cardinal directions (up, down, left, or right) if it can move continuously in that direction and exit the grid without passing through any cell containing a pink rabbit of the opposite gender (i.e. if the rabbit is male, cells with a female pink rabbit block the path, and vice versa). Rabbits of the same gender do not block the path.
A pink rabbit is considered a "qualified pink rabbit" if it has at least three escape channels. Your task is to determine the number of qualified pink rabbits on the screen given their positions.
inputFormat
The input consists of multiple lines:
The first line contains four integers , , , , where and () represent the number of rows and columns of the grid, and and denote the number of male and female pink rabbits respectively.
Each of the next lines contains two integers and (, ), representing the position of a male pink rabbit.
Each of the following lines contains two integers and , representing the position of a female pink rabbit.
You can assume that no cell will contain more than one rabbit.
outputFormat
Output a single integer representing the total number of qualified pink rabbits.
sample
5 5 1 1
3 3
2 2
2