#include<bits/stdc++.h>
using namespace std;
int ans(int a[],int b[],int n,int j){
if(n==0&&j==0)
return b[0];
if(n==0&&j==1)
return a[0];
int x=ans(a,b,n-1,0)+b[n]+abs(a[n-1]-a[n]);
int y=ans(a,b,n-1,1)+b[n]+abs(b[n-1]-a[n]);
int s=ans(a,b,n-1,0)+a[n]+abs(a[n-1]-b[n]);
int t=ans(a,b,n-1,1)+a[n]+abs(b[n-1]-b[n]);
return max(max(x,y),max(s,t));
}
int main(){
int n;
cin>>n;
int a[n]={0};
int b[n]={0};
for(int i=0;i<n;i++){
cin>>a[i]>>b[i];
}
if(a[0]>b[0])
cout<<ans(a,b,n-1,0);
else cout<<ans(a,b,n-1,1);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBhbnMoaW50IGFbXSxpbnQgYltdLGludCBuLGludCBqKXsKICAgIGlmKG49PTAmJmo9PTApCiAgICAgICAgcmV0dXJuIGJbMF07CiAgICBpZihuPT0wJiZqPT0xKQogICAgICAgIHJldHVybiBhWzBdOwogICAgaW50IHg9YW5zKGEsYixuLTEsMCkrYltuXSthYnMoYVtuLTFdLWFbbl0pOwogICAgaW50IHk9YW5zKGEsYixuLTEsMSkrYltuXSthYnMoYltuLTFdLWFbbl0pOwogICAgaW50IHM9YW5zKGEsYixuLTEsMCkrYVtuXSthYnMoYVtuLTFdLWJbbl0pOwogICAgaW50IHQ9YW5zKGEsYixuLTEsMSkrYVtuXSthYnMoYltuLTFdLWJbbl0pOwogICAgcmV0dXJuIG1heChtYXgoeCx5KSxtYXgocyx0KSk7Cn0KCmludCBtYWluKCl7CiAgICBpbnQgbjsKICAgIGNpbj4+bjsKICAgIGludCBhW25dPXswfTsKICAgIGludCBiW25dPXswfTsKICAgIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgICAgIGNpbj4+YVtpXT4+YltpXTsKICAgIH0KICAgIGlmKGFbMF0+YlswXSkKICAgIAljb3V0PDxhbnMoYSxiLG4tMSwwKTsKICAgIGVsc2UgY291dDw8YW5zKGEsYixuLTEsMSk7CiAgICByZXR1cm4gMDsKfQ==