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));
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--;
}
}
}
}
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));
}
}
aW1wb3J0IGphdmEudXRpbC4qOwpjbGFzcyBNYWluIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgTGlzdDxNYXJrZXI+IGwgPSBuZXcgQXJyYXlMaXN0PE1hcmtlcj4oKTsKICAgICAgICAKICAgICAgICBsLmFkZChuZXcgTWFya2VyKDAsIHRydWUpKTsKICAgICAgICBsLmFkZChuZXcgTWFya2VyKDEwLCBmYWxzZSkpOwogICAgICAgIAogICAgICAgIGwuYWRkKG5ldyBNYXJrZXIoNSwgdHJ1ZSkpOwogICAgICAgIGwuYWRkKG5ldyBNYXJrZXIoMjAsIGZhbHNlKSk7CiAgICAgICAgCiAgICAgICAgbC5hZGQobmV3IE1hcmtlcigyLCB0cnVlKSk7CiAgICAgICAgbC5hZGQobmV3IE1hcmtlcigzMCwgZmFsc2UpKTsKICAgICAgICAKICAgICAgICBDb2xsZWN0aW9ucy5zb3J0KGwpOwogICAgICAgIGludCB0b3RhbCA9IC0xLCBvdmVybGFwcyA9IDA7CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IGwuc2l6ZSgpOyBpKyspIHsKICAgICAgICAgICAgaWYobC5nZXQoaSkuZ3JlZW4pIHsKICAgICAgICAgICAgICAgIHRvdGFsKys7CiAgICAgICAgICAgICAgICBpZih0b3RhbCA+IDApIG92ZXJsYXBzICs9IHRvdGFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgdG90YWwtLTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4ob3ZlcmxhcHMpOwogICAgfQp9CmNsYXNzIE1hcmtlciBpbXBsZW1lbnRzIENvbXBhcmFibGU8TWFya2VyPiB7CiAgICBpbnQgbjsKICAgIGJvb2xlYW4gZ3JlZW47CiAgICBwdWJsaWMgTWFya2VyKGludCBhLCBib29sZWFuIGIpIHsKICAgICAgICBuID0gYTsKICAgICAgICBncmVlbiA9IGI7CiAgICB9CiAgICBwdWJsaWMgaW50IGNvbXBhcmVUbyhNYXJrZXIgb3RoZXIpIHsKICAgICAgICByZXR1cm4gbiA8IG90aGVyLm4gPyAtIDEgOiAobiA+IG90aGVyLm4gPyAxIDogKGdyZWVuID8gLTEgOiAxKSk7CiAgICB9Cn0=