#include <bits/stdc++.h>

using namespace std;


// separate points into two sets
// left and right sets
vector<pair<long long, long long>> points;
long long countDominantPairs(int l, int r) {
   if (l >= r) {
      return 0;
   }

   int mid = (l + r)/2;
   long long count = countDominantPairs(l, mid) + countDominantPairs(mid + 1, r);

   if (points[mid].first == points[mid + 1].first) {}
   
   vector<pair<long long, long long>> temp(r - l + 1);
   int i = l, j = mid + 1, k = 0;
   while (i <= mid && j <= r) {
      auto [x_a, y_a] = points[i];
      auto [x_b, y_b] = points[j];

      if (y_a <= y_b) {
         temp[k++] = points[i++];
      } else { // y_a > y_b -> point B is dominated by all placed points from left side
         if (points[j].first > points[i].first) count += (i - l);
         temp[k++] = points[j++];
      }
   }
   
   while (i <= mid) {
      temp[k++] = points[i++];
   }
   
   while (j <= r) {
      if (points[j].first > points[mid].first && points[j].second > points[mid].second) { // this point is dominated by all placed points from left side
         count += (mid + 1 - l);
      }
      temp[k++] = points[j++];
   }
   

   for (int index = l; index <= r; index++) {
      points[index] = temp[index - l];
   }

   return count;
}

int main(){
   // x_a < x_b
   // y_a < y_b

   int n; cin >> n;
   points.resize(n);
   for (int i = 0; i < n; i++) {
      cin >> points[i].first >> points[i].second;
   }

   sort(points.begin(), points.end());

   cout << countDominantPairs(0, n - 1) << endl;
   
   return 0;
}