import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.TreeSet;
import java.lang.Integer;
public class waterfall_kp {
static int nextInt() {
try {
st.nextToken();
return (int) st.nval;
return 0;
}
}
static class Segment implements Comparable
<Segment
> {
int l, r, h;
int max = 0;
public Segment(int l,
int r,
int h
) { this.l = l;
this.r = r;
this.h = h;
}
@Override
return cmp
== 0 ? Integer.
valueOf(l
).
compareTo(Integer.
valueOf(o.
l)) : cmp
; }
return l < o.r && o.l < r;
}
}
static class Part implements Comparable<Part> {
int l, r;
public Part
(int l,
int r,
Segment s
) { this.l = l;
this.r = r;
this.s = s;
}
this.l = s.l;
this.r = s.r;
this.s = s;
}
@Override
public int compareTo(Part o) {
return cmp
== 0 ? Integer.
valueOf(r
).
compareTo(Integer.
valueOf(o.
r)) : cmp
; }
int overlap(Part o) {
}
private int length() {
return r-l;
}
}
public static void main
(String[] args
) { int n = nextInt();
ArrayList<Segment> segments = new ArrayList<Segment>();
segments.add(top);
segments.add(bottom);
for (int i = 0; i < n; i++) {
int h = nextInt();
segments.
add(new Segment(nextInt
(), nextInt
(), h
)); }
TreeSet<Part> parts = new TreeSet<Part>();
parts.add(new Part(top));
for (int i = 1; i < segments.size(); i++) {
Part p = new Part(s);
Part first = parts.lower(new Part(s.l, s.l, null));
if(first.r==p.l) {
first=parts.higher(first);
}
Part last = parts.lower(new Part(s.r, s.r, null));
TreeSet<Part> oParts = (TreeSet<Part>) parts.subSet(first, true, last, true);
Iterator<Part> it = oParts.iterator();
Part l = null;
Part m = null;
Part r = null;
while (m == null) {
m = r;
if(it.hasNext()) {
r=it.next();
it.remove();
} else {
r=null;
}
}
while (m != null) {
boolean use = true;
if (l != null) {
if (l.s.overlaps(m.s)&&l.s.h<m.s.h) {
use = false;
}
}
if (r != null) {
if (r.s.overlaps(m.s)&&r.s.h<m.s.h) {
use = false;
}
}
if(use) {
s.
max=Math.
max(s.
max,
Math.
min(m.
s.
max, p.
overlap(m
))); }
l=m;
m=r;
if(it.hasNext()) {
r=it.next();
it.remove();
} else {
r=null;
}
}
parts.add(p);
if(p.l>first.l) {
parts.add(new Part(first.l,p.l,first.s));
}
if(p.r<last.r){
parts.add(new Part(p.r,last.r,last.s));
}
}
System.
out.
println(bottom.
max); }
}
CmltcG9ydCBqYXZhLmlvLkJ1ZmZlcmVkUmVhZGVyOwppbXBvcnQgamF2YS5pby5JT0V4Y2VwdGlvbjsKaW1wb3J0IGphdmEuaW8uSW5wdXRTdHJlYW1SZWFkZXI7CmltcG9ydCBqYXZhLmlvLlN0cmVhbVRva2VuaXplcjsKaW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7CmltcG9ydCBqYXZhLnV0aWwuQ29sbGVjdGlvbnM7CmltcG9ydCBqYXZhLnV0aWwuSXRlcmF0b3I7CmltcG9ydCBqYXZhLnV0aWwuVHJlZVNldDsKaW1wb3J0IGphdmEubGFuZy5JbnRlZ2VyOwoKcHVibGljIGNsYXNzIHdhdGVyZmFsbF9rcCB7CgogICAgc3RhdGljIFN0cmVhbVRva2VuaXplciBzdCA9IG5ldyBTdHJlYW1Ub2tlbml6ZXIobmV3IEJ1ZmZlcmVkUmVhZGVyKG5ldyBJbnB1dFN0cmVhbVJlYWRlcihTeXN0ZW0uaW4pKSk7CgogICAgc3RhdGljIGludCBuZXh0SW50KCkgewogICAgICAgIHRyeSB7CiAgICAgICAgICAgIHN0Lm5leHRUb2tlbigpOwogICAgICAgICAgICByZXR1cm4gKGludCkgc3QubnZhbDsKICAgICAgICB9IGNhdGNoIChJT0V4Y2VwdGlvbiBleCkgewogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICB9CgogICAgc3RhdGljIGNsYXNzIFNlZ21lbnQgaW1wbGVtZW50cyBDb21wYXJhYmxlPFNlZ21lbnQ+IHsKCiAgICAgICAgaW50IGwsIHIsIGg7CiAgICAgICAgaW50IG1heCA9IDA7CgogICAgICAgIHB1YmxpYyBTZWdtZW50KGludCBsLCBpbnQgciwgaW50IGgpIHsKICAgICAgICAgICAgdGhpcy5sID0gbDsKICAgICAgICAgICAgdGhpcy5yID0gcjsKICAgICAgICAgICAgdGhpcy5oID0gaDsKCiAgICAgICAgfQoKICAgICAgICBAT3ZlcnJpZGUKICAgICAgICBwdWJsaWMgaW50IGNvbXBhcmVUbyhTZWdtZW50IG8pIHsKICAgICAgICAgICAgaW50IGNtcCA9IC1JbnRlZ2VyLnZhbHVlT2YoaCkuY29tcGFyZVRvKEludGVnZXIudmFsdWVPZihvLmgpKTsKICAgICAgICAgICAgcmV0dXJuIGNtcCA9PSAwID8gSW50ZWdlci52YWx1ZU9mKGwpLmNvbXBhcmVUbyhJbnRlZ2VyLnZhbHVlT2Yoby5sKSkgOiBjbXA7CiAgICAgICAgfQoKICAgICAgICBib29sZWFuIG92ZXJsYXBzKFNlZ21lbnQgbykgewogICAgICAgICAgICByZXR1cm4gbCA8IG8uciAmJiBvLmwgPCByOwogICAgICAgIH0KICAgIH0KCiAgICBzdGF0aWMgY2xhc3MgUGFydCBpbXBsZW1lbnRzIENvbXBhcmFibGU8UGFydD4gewoKICAgICAgICBpbnQgbCwgcjsKICAgICAgICBTZWdtZW50IHM7CgogICAgICAgIHB1YmxpYyBQYXJ0KGludCBsLCBpbnQgciwgU2VnbWVudCBzKSB7CiAgICAgICAgICAgIHRoaXMubCA9IGw7CiAgICAgICAgICAgIHRoaXMuciA9IHI7CiAgICAgICAgICAgIHRoaXMucyA9IHM7CiAgICAgICAgfQoKICAgICAgICBwdWJsaWMgUGFydChTZWdtZW50IHMpIHsKICAgICAgICAgICAgdGhpcy5sID0gcy5sOwogICAgICAgICAgICB0aGlzLnIgPSBzLnI7CiAgICAgICAgICAgIHRoaXMucyA9IHM7CiAgICAgICAgfQoKICAgICAgICBAT3ZlcnJpZGUKICAgICAgICBwdWJsaWMgaW50IGNvbXBhcmVUbyhQYXJ0IG8pIHsKICAgICAgICAgICAgaW50IGNtcCA9IEludGVnZXIudmFsdWVPZihsKS5jb21wYXJlVG8oSW50ZWdlci52YWx1ZU9mKG8ubCkpOwogICAgICAgICAgICByZXR1cm4gY21wID09IDAgPyBJbnRlZ2VyLnZhbHVlT2YocikuY29tcGFyZVRvKEludGVnZXIudmFsdWVPZihvLnIpKSA6IGNtcDsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgaW50IG92ZXJsYXAoUGFydCBvKSB7CiAgICAgICAgICAgIHJldHVybiBNYXRoLm1pbihyLG8uciktTWF0aC5tYXgobCxvLmwpOwogICAgICAgIH0KCiAgICAgICAgcHJpdmF0ZSBpbnQgbGVuZ3RoKCkgewogICAgICAgICAgICByZXR1cm4gci1sOwogICAgICAgIH0KICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgaW50IG4gPSBuZXh0SW50KCk7CiAgICAgICAgQXJyYXlMaXN0PFNlZ21lbnQ+IHNlZ21lbnRzID0gbmV3IEFycmF5TGlzdDxTZWdtZW50PigpOwogICAgICAgIFNlZ21lbnQgdG9wID0gbmV3IFNlZ21lbnQoSW50ZWdlci5NSU5fVkFMVUUsIEludGVnZXIuTUFYX1ZBTFVFLCBuZXh0SW50KCkpOwogICAgICAgIHRvcC5tYXggPSBJbnRlZ2VyLk1BWF9WQUxVRTsKICAgICAgICBTZWdtZW50IGJvdHRvbSA9IG5ldyBTZWdtZW50KEludGVnZXIuTUlOX1ZBTFVFKzEsIEludGVnZXIuTUFYX1ZBTFVFLTEsIDApOwogICAgICAgIHNlZ21lbnRzLmFkZCh0b3ApOwogICAgICAgIHNlZ21lbnRzLmFkZChib3R0b20pOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICAgIGludCBoID0gbmV4dEludCgpOwogICAgICAgICAgICBzZWdtZW50cy5hZGQobmV3IFNlZ21lbnQobmV4dEludCgpLCBuZXh0SW50KCksIGgpKTsKICAgICAgICB9CiAgICAgICAgQ29sbGVjdGlvbnMuc29ydChzZWdtZW50cyk7CgogICAgICAgIFRyZWVTZXQ8UGFydD4gcGFydHMgPSBuZXcgVHJlZVNldDxQYXJ0PigpOwogICAgICAgIHBhcnRzLmFkZChuZXcgUGFydCh0b3ApKTsKICAgICAgICBmb3IgKGludCBpID0gMTsgaSA8IHNlZ21lbnRzLnNpemUoKTsgaSsrKSB7CiAgICAgICAgICAgIFNlZ21lbnQgcyA9IHNlZ21lbnRzLmdldChpKTsKICAgICAgICAgICAgUGFydCBwID0gbmV3IFBhcnQocyk7CiAgICAgICAgICAgIFBhcnQgZmlyc3QgPSBwYXJ0cy5sb3dlcihuZXcgUGFydChzLmwsIHMubCwgbnVsbCkpOwogICAgICAgICAgICBpZihmaXJzdC5yPT1wLmwpIHsKICAgICAgICAgICAgICAgIGZpcnN0PXBhcnRzLmhpZ2hlcihmaXJzdCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgUGFydCBsYXN0ID0gcGFydHMubG93ZXIobmV3IFBhcnQocy5yLCBzLnIsIG51bGwpKTsKICAgICAgICAgICAgVHJlZVNldDxQYXJ0PiBvUGFydHMgPSAoVHJlZVNldDxQYXJ0PikgcGFydHMuc3ViU2V0KGZpcnN0LCB0cnVlLCBsYXN0LCB0cnVlKTsKICAgICAgICAgICAgSXRlcmF0b3I8UGFydD4gaXQgPSBvUGFydHMuaXRlcmF0b3IoKTsKCiAgICAgICAgICAgIFBhcnQgbCA9IG51bGw7CiAgICAgICAgICAgIFBhcnQgbSA9IG51bGw7CiAgICAgICAgICAgIFBhcnQgciA9IG51bGw7CgogICAgICAgICAgICB3aGlsZSAobSA9PSBudWxsKSB7CiAgICAgICAgICAgICAgICBtID0gcjsKICAgICAgICAgICAgICAgIGlmKGl0Lmhhc05leHQoKSkgewogICAgICAgICAgICAgICAgICAgIHI9aXQubmV4dCgpOwogICAgICAgICAgICAgICAgICAgIGl0LnJlbW92ZSgpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICByPW51bGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgd2hpbGUgKG0gIT0gbnVsbCkgewogICAgICAgICAgICAgICAgYm9vbGVhbiB1c2UgPSB0cnVlOwogICAgICAgICAgICAgICAgaWYgKGwgIT0gbnVsbCkgewogICAgICAgICAgICAgICAgICAgIGlmIChsLnMub3ZlcmxhcHMobS5zKSYmbC5zLmg8bS5zLmgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgdXNlID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHIgIT0gbnVsbCkgewogICAgICAgICAgICAgICAgICAgIGlmIChyLnMub3ZlcmxhcHMobS5zKSYmci5zLmg8bS5zLmgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgdXNlID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYodXNlKSB7CiAgICAgICAgICAgICAgICAgICAgcy5tYXg9TWF0aC5tYXgocy5tYXgsTWF0aC5taW4obS5zLm1heCwgcC5vdmVybGFwKG0pKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsPW07CiAgICAgICAgICAgICAgICBtPXI7CiAgICAgICAgICAgICAgICBpZihpdC5oYXNOZXh0KCkpIHsKICAgICAgICAgICAgICAgICAgICByPWl0Lm5leHQoKTsKICAgICAgICAgICAgICAgICAgICBpdC5yZW1vdmUoKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcj1udWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgICAgICBwYXJ0cy5hZGQocCk7CiAgICAgICAgICAgIGlmKHAubD5maXJzdC5sKSB7CiAgICAgICAgICAgICAgICBwYXJ0cy5hZGQobmV3IFBhcnQoZmlyc3QubCxwLmwsZmlyc3QucykpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKHAucjxsYXN0LnIpewogICAgICAgICAgICAgICAgcGFydHMuYWRkKG5ldyBQYXJ0KHAucixsYXN0LnIsbGFzdC5zKSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKGJvdHRvbS5tYXgpOwogICAgfQp9Cg==