IOI '05 - Nowy Sacz, Poland
Byteman owns the most beautiful garden in Bytetown. He planted
Byteman wants to make a fence surrounding the rectangular areas, but he is short of money, so he wants to use as little fence as possible. Your task is to help Byteman select the two rectangular areas.
The garden forms a rectangle
The rectangular areas, which must be selected, should have their sides parallel to the sides of the garden and the squares in their corners should have integer coordinates. For
- contains all the squares with coordinates
satisfying and , and - has perimeter
.
The two rectangular areas must be disjoint, that is they cannot contain a common square. Even if they have a common side, or part of it, they must be surrounded by separate fences.
Write a program, that:
- reads from the standard input the dimensions of the garden, the number of roses in the garden, the number of roses that should be in each of the rectangular areas, and the positions of the roses,
- finds the corners of two such rectangular areas with minimum sum of perimeters that satisfy the given conditions,
- writes to the standard output the minimum sum of perimeters of two non-overlapping rectangular areas, each containing exactly the given number of roses (or a single word
NO
, if no such pair of areas exists).
Input Specification
The first line of standard input contains two integers:
In
Output Specification
The standard output should contain only one line with exactly one integer — the minimum sum of perimeters of two non-overlapping rectangular areas, each containing exactly NO
, if no such pair of areas exists.
Sample Input
6 5
7 3
3 4
3 3
6 1
1 1
5 5
5 5
3 1
Sample Output
22
Comments