import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int [][] record = new int [n][2];
for(int i = 0;i<n;i++) {
record[i][0] = scanner.nextInt();
record[i][1] = scanner.nextInt();
}
Arrays.sort(record,Comparator.comparingInt(o -> o[0]));
int [][] temp = new int [n][2];
int index = -1;
for(int [] rec:record) {
if(index==-1||rec[0]>temp[index][1]) {
temp[++index] = rec;
}else {
temp[index][1] = Math.max(temp[index][1], rec[1]);
}
}
int [][] res = Arrays.copyOf(temp, index+1);
int maxLength = 0;
int maxLength2 = 0;
for(int i = 0;i<res.length;i++) {
maxLength = Math.max(maxLength, res[i][1]-res[i][0]);
}
for(int i = 1;i<res.length;i++) {
maxLength2 = Math.max(maxLength2, res[i][0]-res[i-1][1]);
}
System.out.println(maxLength+" "+maxLength2);
}
}
1)先以左端点为升序排序
2)合并区间
3)分别取 maxLength 作为最长连续 maxLength2 作为最长间隔