1. Abridged Problem Statement  
Given N intervals [Ai, Bi] with all Ai distinct and all Bi distinct, an interval i is called redundant if there exists another interval j such that Aj < Ai and Bi < Bj. Count how many intervals are redundant.

2. Detailed Editorial  
Problem Restatement  
- We have N defense outposts along a border, each covering a segment [Ai, Bi].  
- We want to abandon every “redundant” outpost, where an outpost i is redundant if it is strictly contained in some earlier-starting, later-ending segment j (i.e., Aj < Ai and Bi < Bj).  
- Output the total number of redundant outposts.

Key Observations  
- Since all Ai are distinct, sorting intervals by Ai gives a strict increasing order of starts.  
- While scanning in increasing order of Ai, any candidate interval i can only be contained in some interval j with a smaller start—i.e., one of the intervals we have already seen.  
- Among all previously seen intervals, the one with the largest end Bmax is the “widest” and thus most likely to contain the current interval.  
- If current Bi < Bmax, then there exists some earlier interval j with Bj = Bmax > Bi, so i is redundant. Otherwise, update Bmax to Bi.

Algorithm  
1. Read N and the list of (Ai, Bi).  
2. Sort the list by Ai in ascending order.  
3. Initialize Bmax = −∞ and answer = 0.  
4. For each interval in sorted order:  
   a. If Bi < Bmax, increment answer (interval is redundant).  
   b. Else, set Bmax = Bi (this interval extends the maximum coverage).  
5. Print answer.

Correctness  
- Sorting ensures that when processing interval i, all j with Aj < Ai have been considered.  
- Keeping only Bmax is sufficient: if any previous interval j had Bj > Bi, then Bmax ≥ Bj > Bi; so checking Bi < Bmax detects redundancy.  
- Distinctness of Ai and Bi avoids edge cases of ties.

Complexity  
- Sorting: O(N log N)  
- Linear scan: O(N)  
- Total: O(N log N), which is efficient for N up to 16 000.

3. Provided C++ Solution with Detailed Comments  
#include <bits/stdc++.h>        // includes all standard headers  
#define endl '\n'               // shorthand for newline  

using namespace std;

// Utility to update x = max(x, y)
template<class T, class T2>
inline void chkmax(T& x, const T2& y) {
    if (x < y) {
        x = y;
    }
}

int n;                             // number of outposts
vector<pair<int,int>> a;           // stores (start, end) of each outpost

// Read input values
void read() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
}

// Solve the problem using the Bmax scan method
void solve() {
    // Sort intervals by their start coordinate ascending
    sort(a.begin(), a.end());

    int answer = 0;                // count of redundant outposts
    int Bmax = INT_MIN;            // maximum end seen so far

    // Sweep through sorted intervals
    for (int i = 0; i < n; i++) {
        int Bi = a[i].second;
        // If this interval ends before the maximum end seen,
        // it's contained in some earlier interval
        if (Bi < Bmax) {
            answer++;
        } else {
            // Otherwise, update the maximum end
            chkmax(Bmax, Bi);
        }
    }

    // Output the result
    cout << answer << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    read();
    solve();
    return 0;
}

4. Python Solution with Detailed Comments  
```python
import sys

def main():
    data = sys.stdin.read().split()
    it = iter(data)
    n = int(next(it))
    intervals = []

    # Read all intervals
    for _ in range(n):
        A = int(next(it))
        B = int(next(it))
        intervals.append((A, B))

    # Sort by start A ascending
    intervals.sort(key=lambda x: x[0])

    Bmax = -10**18   # track the maximum end seen so far
    answer = 0       # count of redundant intervals

    # Sweep through intervals
    for A, B in intervals:
        # If this interval ends before Bmax, it's redundant
        if B < Bmax:
            answer += 1
        else:
            # Otherwise update Bmax
            Bmax = B

    # Print final count
    print(answer)

if __name__ == "__main__":
    main()
```

5. Compressed Editorial  
1. Sort intervals by start.  
2. Maintain the maximum end Bmax of processed intervals.  
3. For each interval, if its end < Bmax, it is redundant; otherwise update Bmax.  
4. Count and output redundancies.