func_code_string: #include <bits/stdc++.h>   using namespace std;   const int mod = 1000000009;   map<pair<int, int>, int> in, id;   set<int> S;   int X[100010], Y[100010];   bool check(pair<int, int> P) {     int x = P.first, y = P.second + 1;     for (int dx = x - 1; dx <= x + 1; dx++) {       if (in.count(make_pair(dx, y)) && in[make_pair(dx, y)] == 1) return 0;     }     return 1;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       X[i] = x, Y[i] = y;       in[make_pair(x, y)] = 0, id[make_pair(x, y)] = i;     }     for (map<pair<int, int>, int>::iterator it = in.begin(); it != in.end();          it++) {       int x = it->first.first, y = it->first.second - 1;       for (int dx = x - 1; dx <= x + 1; dx++) {         if (in.count(make_pair(dx, y))) {           in[it->first]++;         }       }     }     for (map<pair<int, int>, int>::iterator it = in.begin(); it != in.end();          it++) {       if (check(it->first)) S.insert(id[it->first]);     }     long long ans = 0;     for (int it = 0; it < n; it++) {       if (it & 1) {         int v = *S.begin();         S.erase(S.begin());         int y = Y[v] + 1;         id.erase(make_pair(X[v], Y[v]));         in[make_pair(X[v], Y[v])] = 0;         for (int x = X[v] - 1; x <= X[v] + 1; x++) {           if (!id.count(make_pair(x, y))) continue;           in[make_pair(x, y)]--;         }         y--;         for (int x = X[v] - 2; x <= X[v] + 2; x++) {           if (!id.count(make_pair(x, y))) continue;           if (check(make_pair(x, y)))             S.insert(id[make_pair(x, y)]);           else             S.erase(id[make_pair(x, y)]);         }         y--;         for (int x = X[v] - 2; x <= X[v] + 2; x++) {           if (!id.count(make_pair(x, y))) continue;           if (check(make_pair(x, y)))             S.insert(id[make_pair(x, y)]);           else             S.erase(id[make_pair(x, y)]);         }         ans = (ans * n + v) % mod;       } else {         int v = *(--S.end());         S.erase(--S.end());         int y = Y[v] + 1;         id.erase(make_pair(X[v], Y[v]));         in[make_pair(X[v], Y[v])] = 0;         for (int x = X[v] - 1; x <= X[v] + 1; x++) {           if (!id.count(make_pair(x, y))) continue;           in[make_pair(x, y)]--;         }         y--;         for (int x = X[v] - 2; x <= X[v] + 2; x++) {           if (!id.count(make_pair(x, y))) continue;           if (check(make_pair(x, y)))             S.insert(id[make_pair(x, y)]);           else             S.erase(id[make_pair(x, y)]);         }         y--;         for (int x = X[v] - 2; x <= X[v] + 2; x++) {           if (!id.count(make_pair(x, y))) continue;           if (check(make_pair(x, y)))             S.insert(id[make_pair(x, y)]);           else             S.erase(id[make_pair(x, y)]);         }         ans = (ans * n + v) % mod;       }     }     cout << ans << endl;     return 0;   }   