#include<iostream>
#include<algorithm>
//#include<>
//#include<>

#define endl '\n'

using namespace std;

void budi_burz(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

}

long long n;
pair<long long, long long> a[50024];

pair<long long, long long> sravni(pair<long long, long long> a, pair<long long, long long> b){

    pair<long long, long long> ans;
    if(a.first > b.first) swap(a, b);
    ans = {max(a.first, b.first), min(a.second, b.second)};
    if(ans.second <= ans.first) ans = {-1, -1};

    return ans;
}

int main(){

    budi_burz();

    cin >> n;
    for(long long i = 0; i < n; i++){

        cin >> a[i].first >> a[i].second;

    }
    sort(a, a + n);
    long long level = 1;
    long long ans = 1;
    for(long long i = 0; i < n; i++){
        long long tek = 0;
        pair<long long, long long> sega = a[i];
        for(long long j = i; j < n; j++){
            pair<long long, long long> t = sravni(sega, a[j]);
            if(t.first == -1) continue;
            sega = t;
            tek++;
        }
        if(tek == level) ans += sega.second - sega.first;
        if(tek > level){
            ans = sega.second - sega.first;
            level = tek;
        } 
       //cout << i << " " << a[i].first << " " << a[i].second << " " << tek << " " << sega.first << " " << sega.second << endl << endl;
    }
    cout << level << endl << ans;

    return 0;
}