Problem D
Buildin' Fences
Old Man Joe recently decided to get into the farming business. He planted a whole field of corn, but soon discovered that some hooligans from in town were stealing from his farm! He thinks his field is being targeted since it’s the only one without a fence, so Joe has hired you to build one.
As Old Man Joe was very careful when designing his field, his corn plants are placed on integer coordinates on a two-dimensional plane. No two corn plants are in the same location. He would like you to build an axis-aligned rectangular fence of minimum perimeter that contains all of the plants. For aesthetic reasons, the corners of the fenced area must lie on integer coordinates. The plants must also be given ample room to grow, so the fence may not overlap with any corn plants.
Input
The first line will contain a single integer $N$ ($1 \leq N \leq 10^5)$ indicating the number of plants. The next $N$ lines each contain two integers $X$ and $Y$ $(1 \leq X, Y \leq 10^8)$, indicating the location of each plant.
Output
Output the smallest possible perimeter out of all ways to fence in the plants.
Sample Input 1 | Sample Output 1 |
---|---|
4 1 1 1 4 4 1 4 4 |
20 |
Sample Input 2 | Sample Output 2 |
---|---|
5 2 1 1 2 3 2 2 3 2 2 |
16 |
Sample Input 3 | Sample Output 3 |
---|---|
3 1 1 2 1 5 1 |
16 |