#include<bits/stdc++.h>
using namespace std;
vector<long long> start,finish;
int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        start.push_back(a);
        finish.push_back(b);
    }
    sort(start.begin(),start.end());
    sort(finish.begin(),finish.end());
    int brlines=0,j=0,maxbrlines,ans=0;
    for(int i=0;i<n;i++){
        while(finish[j]<=start[i]){
            j++;
        }
        brlines=i-j+1;
        //cout<<i<<" "<<j<<" "<<brlines<<endl;
        if(brlines>maxbrlines){
            maxbrlines=brlines;
            ans=0;

        }
        if(brlines==maxbrlines){
            ans+=finish[j]-start[i];
            //cout<<finish[j]<<" "<<start[i]<<endl;
        }
    }
    cout<<maxbrlines<<endl<<ans;
}
