#include using namespace std; #define PB push_back #define CL(A, I) (memset(A, I, sizeof(A))) #define D(X) cout<<" "<<#X": "< vi; typedef pair ii; typedef vector vii; int n; map con; set g; vii nee = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; /* int c[2]; set clos; void dfs(int x, int y, int col) { clos.insert({x, y}); c[col]++; for (auto sh : nee) { if (!clos.count({x+sh.aa, y+sh.bb}) && g.count({x+sh.aa, y+sh.bb})) { dfs(x + sh.aa, y + sh.bb, !col); } } } */ #define MX (2012) #define CLR c=L=0,CL(C,0); vi gg[MX]; int L, O[MX], H[MX], C[MX], c, N; void col(int u=0) { if (N-u+c<=L) return; if (u==N) return L=c, (void)memcpy(O,H,4*c); int X(1); for (auto h : gg[u]) X&=C[h]!=1; if (X) H[c++]=u,C[u]=1, col(u+1),--c,C[u]=0; col(u+1); } int main() { while (scanf("%d", &n) == 1) { ll res = 0; g.clear(); con.clear(); F(n) { int x, y; scanf("%d%d", &x, &y); g.insert({x, y}); for (auto sh : nee) { if (g.count({x+sh.aa, y+sh.bb})) { con[{x+sh.aa, y+sh.bb}]++; con[{x, y}]++; } } } while (!g.empty()) { ii cur = *g.begin(); for (auto i : g) { if (con[i] < con[cur]) cur = i; } g.erase(cur); con[cur] = 0; for (auto sh: nee) { int nx = cur.aa + sh.aa, ny = cur.bb + sh.bb; if (g.count({nx, ny})) { g.erase({nx, ny}); con[{nx, ny}] = 0; for (auto sh2 : nee) { if (g.count({nx + sh2.aa, ny + sh2.bb})) { con[{nx + sh2.aa, ny + sh2.bb}]--; } } } } res++; } /* clos.clear(); for (auto i : g) { c[0] = 0; c[1] = 0; if (!clos.count(i)) dfs(i.aa, i.bb, 0); res += max(c[0], c[1]); } */ /* CLR; map m; int ctr = 0; for (auto i : g) m[i] = ctr++; F((int)g.size()) gg[i].clear(); for (auto i : g) { for (auto sh : nee) { if (g.count({i.aa + sh.aa, i.bb + sh.bb})) { gg[m[i]].PB(m[{i.aa + sh.aa, i.bb + sh.bb}]); } } } N = g.size(); col(0); */ printf("%lld\n", res); } }