#include <bits/stdc++.h>
using namespace std;
int n;
map<pair<long long, long long>, long long> m;
set<long long> maximum;
pair<long long, long long> dizi[999999];
long long us[999999];
inline int cocuksayisi(pair<long long, long long> a) {
  if (m[a] == 0) return 9;
  if (a.second == 0) return 0;
  a.second--;
  pair<int, int> a1 = a;
  pair<int, int> a3 = a;
  a1.first--;
  a3.first++;
  return (m[a1] > 0 ? 1 : 0) + (m[a] > 0 ? 1 : 0) + (m[a3] > 0 ? 1 : 0);
}
inline int bos(pair<long long, long long> a) {
  if (m[a] <= 0) return 0;
  a.second++;
  pair<long long, long long> b = a;
  pair<long long, long long> c = a;
  b.first--;
  c.first++;
  if (cocuksayisi(a) > 1 && cocuksayisi(b) > 1 && cocuksayisi(c) > 1) return 1;
  return 0;
}
inline void ekle(pair<long long, long long> a) {
  m[a] = 0;
  if (a.second == 0) return;
  a.second--;
  pair<long long, long long> a1 = a;
  pair<long long, long long> a3 = a;
  a1.first--;
  a3.first++;
  if (bos(a1)) maximum.insert(m[a1]);
  if (bos(a)) maximum.insert(m[a]);
  if (bos(a3)) maximum.insert(m[a3]);
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    pair<long long, long long> a;
    cin >> a.first >> a.second;
    dizi[i] = a;
    m[a] = i;
  }
  for (map<pair<long long, long long>, long long>::iterator it = m.begin();
       it != m.end(); it++) {
    if (it->second > 0) {
      pair<long long, long long> a = it->first;
      a.second++;
      pair<long long, long long> b = a;
      pair<long long, long long> c = a;
      b.first--;
      c.first++;
      if (cocuksayisi(a) > 1 && cocuksayisi(b) > 1 && cocuksayisi(c) > 1) {
        maximum.insert(it->second);
      }
    }
  }
  vector<long long> res;
  int sira = 1;
  while (!maximum.empty()) {
    set<long long>::iterator it;
    if (sira == 1)
      it = --maximum.end();
    else
      it = maximum.begin();
    long long d = *it;
    pair<long long, long long> a = dizi[d];
    if (!bos(a)) {
      maximum.erase(it);
      continue;
    }
    res.push_back(d - 1);
    maximum.erase(it);
    ekle(a);
    sira = !sira;
  }
  us[0] = 1;
  for (int i = 1; i <= n; i++) us[i] = (n * us[i - 1]) % 1000000009;
  long long cvp = 0;
  for (int i = 1; i <= n; i++)
    cvp = (cvp + ((res[i - 1] * us[n - i]) % 1000000009)) % 1000000009;
  cout << cvp % 1000000009 << "\n";
  return 0;
}
