Renowned scientist Dr. Henri has just returned from an expedition to Algonquin Park to document the sizes of various animal populations. Unfortunately, he has forgotten to study the most important animal of all: the Canada goose!
As Dr. Henri does not have time to go back to the park, he decides to take a satellite image of it and count the geese in the image instead. Algonquin Park can be represented as a grid of
Of course, it would be too time-consuming to count every single goose in the image. So, Dr. Henri will use a method called quadrat sampling. He will choose
However, the geese have gotten wind of Dr. Henri's plan! They know that Dr. Henri will take the satellite image in exactly
In an attempt to make their population seem larger and even more terrifying, each goose may choose to fly to a new position. A goose can fly at the speed of one cell per minute, and in order to save time, each goose will fly along only one of the four cardinal directions, without turning. The geese want to maximize the raw total obtained by Dr. Henri.
What is the largest raw total obtainable?
Constraints
Subtask 1 [20%]
Subtask 2 [40%]
Subtask 3 [40%]
No additional constraints.
Input Specification
The first line will contain five space-separated integers,
The next
The next
Output Specification
Output one integer, the raw total that Dr. Henri will obtain if the geese choose their positions optimally.
Sample Input 1
5 5 3 2 2
1 3
4 1
3 4
1 3 3 5
3 2 4 4
Sample Output 1
5
Explanation for Sample 1
If goose 1 flies downward to
Sample Input 2
5 5 3 2 0
1 3
4 1
3 4
1 3 3 5
3 2 4 4
Sample Output 2
3
Explanation for Sample 2
The geese do not have time to move at all, so Dr. Henri will count 2 geese in quadrat 1 and 1 goose in quadrat 2 for a raw total of 3 geese.
Comments