// sort in C++
// library (STL) version written Jan 00 by Amit Patel

#include <vector.h>
#include <algo.h>

struct Range {
  int lb, ub;
  Range() {}
  Range(int l, int u): lb(l), ub(u) {}
};

ostream& operator << (ostream& out, const Range& r) {
  return out << '[' << r.lb << ',' << r.ub << ']';
}

struct LBComparator {
  bool operator() (const Range& a, const Range& b) const {
    return a.lb < b.lb;
  }
};

struct UBComparator {
  bool operator() (const Range& a, const Range& b) const {
    return a.ub < b.ub;
  }
};

int main() {
  const int N = 2000000;
  vector<Range> a(N);

  for(int i=0; i<N; i++)
    a[i] = Range(i*7%1000, i*13%1000);

  cout << "sorting...\n";  cout.flush();

  sort(a.begin(), a.end(), LBComparator());
  sort(a.begin(), a.end(), UBComparator());

  cout << "done.\n";  cout.flush();
}

