#include <bits/stdc++.h>
using namespace std;
struct data {
int l, r;
}p[5005];
bool cmp(data a, data b) {
return a.l < b.l;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
for(int i = 0; i < n; i++)
cin >> p[i].l >> p[i].r;
sort(p, p + n, cmp);
int s1 = 0, s2 = 0, ans1 = 0, ans2 = 0;
for(int i = 1; i < n; i++) {
if(p[i].l <= p[i - 1].r) {
ans2 = max(ans2, p[i - 1].l - s2);
s1 = p[i - 1].l;
}
if(p[i].l > p[i - 1].r) {
ans1 = max(ans1, p[i - 1].r - s1);
s2 = p[i - 1].r;
}
}
cout << ans1 << " " << ans2;
return 0;
}
大佬求调!!!