#abc182e. [abc182_e]Akari
[abc182_e]Akari
Problem Statement
We have a grid with rows and columns. Let square be the square at the -th row and -th column in this grid.
There are bulbs and blocks on this grid. The -th bulb is at square , and the -th block is at square . There is at most one object - a bulb or a block - at each square.
Every bulb emits beams of light in four directions - up, down, left, and right - that extend until reaching a square with a block, illuminating the squares on the way. A square with a bulb is also considered to be illuminated. Among the squares without a block, find the number of squares illuminated by the bulbs.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of squares illuminated by the bulbs among the squares without a block.
Sample Input 1
3 3 2 1
1 1
2 3
2 2
Sample Output 1
7
Among the squares without a block, all but square are illuminated.
Sample Input 2
4 4 3 3
1 2
1 3
3 4
2 3
2 4
3 2
Sample Output 2
8
Among the squares without a block, the following eight are illuminated:
- Square
- Square
- Square
- Square
- Square
- Square
- Square
- Square
Sample Input 3
5 5 5 1
1 1
2 2
3 3
4 4
5 5
4 2
Sample Output 3
24
In this case, all the squares without a block are illuminated.