constint maxn=1000005; int n,l[maxn],r[maxn],que[maxn]; intmain(){ scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d%d",&l[i],&r[i]); int ans=0,hed=1,til=0; for (int i=1;i<=n;i++){ while (hed<=til&&l[que[hed]]>r[i]) hed++; ans=max(ans,i-que[hed-1]); while (hed<=til&&l[que[til]]<=l[i]) til--; que[++til]=i; } printf("%d",ans); return0; }