func_code_string: #include <bits/stdc++.h>   using namespace std;   long long read() {     char c = getchar();     if (c <  0  && c >  9  && c !=  - ) c = getchar();     long long f = 1, cnt = 0;     if (c ==  - ) f = -1, c = getchar();     while (c >=  0  && c <=  9 ) {       cnt = cnt * 10 + int(c -  0 );       c = getchar();     }     return cnt * f;   }   const int MOD = 1e9 + 9;   struct Loc {     Loc(int a, int b) {       x = a;       y = b;     }     int x;     int y;     bool operator<(const Loc &a) const {       if (y == a.y) {         return x < a.x;       }       return y < a.y;     }   };   map<Loc, int> table;   bool vis[100005];   priority_queue<int> q1;   priority_queue<int, vector<int>, greater<int> > q2;   long long result = 0;   void add(int a, int m) { result = (result * m + a) % MOD; }   int xPos[100005];   int yPos[100005];   bool judge(int x, int y) {     if (table.find(Loc(x, y + 1)) != table.end()) {       if (table.find(Loc(x - 1, y)) == table.end() &&           table.find(Loc(x + 1, y)) == table.end()) {         return false;       }     }     if (table.find(Loc(x - 1, y + 1)) != table.end()) {       if (table.find(Loc(x - 1, y)) == table.end() &&           table.find(Loc(x - 2, y)) == table.end()) {         return false;       }     }     if (table.find(Loc(x + 1, y + 1)) != table.end()) {       if (table.find(Loc(x + 1, y)) == table.end() &&           table.find(Loc(x + 2, y)) == table.end()) {         return false;       }     }     return true;   }   int main() {     int m;     int x, y;     m = read();     for (int i = 0; i < m; i++) {       cin >> x >> y;       xPos[i] = x;       yPos[i] = y;       table[Loc(x, y)] = i;     }     for (int i = 0; i < m; i++) {       if (judge(xPos[i], yPos[i])) {         q1.push(i);         q2.push(i);       }     }     memset(vis, false, sizeof(vis));     int top = 0;     int count = 0;     while (count < m) {       if ((count & 1) == 0) {         top = q1.top();       } else {         top = q2.top();       }       x = xPos[top];       y = yPos[top];       bool found = false;       if (!vis[top] && judge(x, y)) {         add(top, m);         table.erase(Loc(x, y));         vis[top] = true;         found = true;       }       if ((count & 1) == 0) {         q1.pop();       } else {         q2.pop();       }       if (found) {         count++;         if (table.find(Loc(x, y - 1)) != table.end() && judge(x, y - 1)) {           q1.push(table[Loc(x, y - 1)]);           q2.push(table[Loc(x, y - 1)]);         }         if (table.find(Loc(x - 1, y - 1)) != table.end() && judge(x - 1, y - 1)) {           q1.push(table[Loc(x - 1, y - 1)]);           q2.push(table[Loc(x - 1, y - 1)]);         }         if (table.find(Loc(x + 1, y - 1)) != table.end() && judge(x + 1, y - 1)) {           q1.push(table[Loc(x + 1, y - 1)]);           q2.push(table[Loc(x + 1, y - 1)]);         }       }     }     printf( %d , result);     return 0;   }   