func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   const long long M = 1e9 + 9;   int n, x, y;   pair<int, int> pos[N];   map<pair<int, int>, int> mp;   set<int> q;   long long ans;   int children(int x, int y) {     int ret = 0;     for (int dx = -1; dx <= 1; dx++) {       map<pair<int, int>, int>::iterator c = mp.find(make_pair(x + dx, y - 1));       if (c != mp.end()) ret++;     }     return ret;   }   void update(int x, int y) {     map<pair<int, int>, int>::iterator p = mp.find(make_pair(x, y));     if (p == mp.end()) return;     for (int dx = -1; dx <= 1; dx++) {       map<pair<int, int>, int>::iterator c = mp.find(make_pair(x + dx, y + 1));       if (c != mp.end() && children(x + dx, y + 1) == 1) {         q.erase(p->second);         return;       }     }     q.insert(p->second);   }   void insert(int x, int y, int z) {     pos[z].first = x;     pos[z].second = y;     mp[make_pair(x, y)] = z;   }   void remove(int x, int y) {     mp.erase(make_pair(x, y));     for (int dx = -1; dx <= 1; dx++) {       update(x + dx, y + 1);       update(x + dx, y - 1);     }     for (int dx = -2; dx <= 2; dx++) {       update(x + dx, y);     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       insert(x, y, i);     }     for (int i = 0; i < n; i++) {       update(pos[i].first, pos[i].second);     }     for (int act = 0; !q.empty(); act++) {       set<int>::iterator it;       if ((act & 1) == 0) {         it = --q.end();       } else {         it = q.begin();       }       ans = ans * n + (*it);       ans %= M;       remove(pos[*it].first, pos[*it].second);       q.erase(it);     }     cout << ans;     return 0;   }   