Comfortable Cows
Farmer Nhoj's pasture can be regarded as a large 2D grid of square "cells" (picture a huge chessboard). Initially, the pasture is empty.
Farmer Nhoj will add n cows to the pasture one by one. The i-th cow will occupy a cell (x[i]
, y[i]
) that is distinct from the cells occupied by all other cows.
A cow is said to be "comfortable" if it is horizontally or vertically adjacent to exactly three other cows. Unfortunately, cows that are too comfortable tend to lag in their milk production, so Farmer Nhoj wants to add additional cows until no cow (including the ones that he adds) is comfortable. Note that the added cows do not necessarily need to have x and y coordinates in the range 0..1000.
For each i in the range 1..n, output the minimum number of cows Farmer Nhoj would need to add until no cows are comfortable if initially, the pasture started with only cows 1..i.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5
). Each of the next n lines contains two integers, indicating the (x, y) (0 ≤ x, y ≤ 1000) coordinates of a cow's cell.
Output
Print the minimum number of cows Farmer Nhoj needs to add for each i in 1..n, on n separate lines.
Example
For i = 4, Farmer Nhoj must add an additional cow at (2, 1) to make the cow at (1, 1) uncomfortable.
For i = 9, the best Farmer Nhoj can do is place additional cows at (2, 0), (3, 0), (2, −1) and (2, 3).