import java.util.*;
class Main {
    public static void main (String[] args) {
        List<Marker> l = new ArrayList<Marker>();
        
        l.add(new Marker(0, true));
        l.add(new Marker(10, false));
        
        l.add(new Marker(5, true));
        l.add(new Marker(20, false));
        
        l.add(new Marker(2, true));
        l.add(new Marker(30, false));
        
        Collections.sort(l);
        int total = -1, overlaps = 0;
        for(int i = 0; i < l.size(); i++) {
            if(l.get(i).green) {
                total++;
                if(total > 0) overlaps += total;
            }
            else {
                total--;
            }
        }
        System.out.println(overlaps);
    }
}
class Marker implements Comparable<Marker> {
    int n;
    boolean green;
    public Marker(int a, boolean b) {
        n = a;
        green = b;
    }
    public int compareTo(Marker other) {
        return n < other.n ? - 1 : (n > other.n ? 1 : (green ? -1 : 1));
    }
}