#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); } } } 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}]++; } } } vii todo; for (auto i : g) { if (con[i] == 1) { todo.PB(i); } } while (!todo.empty()) { ii cur = todo.back(); todo.pop_back(); 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}]--; if (con[{nx + sh2.aa, ny + sh2.bb}] == 1) { todo.PB({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]); } printf("%lld\n", res); } }