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

#define endl '\n'

using namespace std;

void budi_burz(){

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

}

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

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

    pair<int, int> 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(int i = 0; i < n; i++){

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

    }
    int level = 1;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int tek = 0;
        pair<int, int> sega = a[i];
        for(int j = i; j < n; j++){
            pair<int, int> 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;
}