#include<bits/stdc++.h>
using namespace std;
long long dp[5100]; //storing solution for each addition of 2 new pilots.(2*i) & (2*i)+1.
long long capt[10200],asis[10200]; //salary for captain and assistant for each i.
int parr[10200]; //storing partners for each i.
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,f,f1;
cin>>n;
long long x,y;
for(int i=0;i<n;i++)
cin>>capt[i]>>asis[i];
dp[0]=capt[1]+asis[0]; //solution for first pair
parr[0]=1; //1st pilot paired with 2nd and vice versa.
parr[1]=0;
for(int i=1;i<(n/2);i++){
x=dp[i-1]+asis[2*i]+capt[(2*i)+1]; //if the 2 new added pilots are paired with each other
f=2*i; //f stores the partner of (2*i)+1
f1=(2*i)+1; //f1 stores the partner of (2*i)
for(int j=0;j<(2*i);j++){
if(parr[j]<j){ //if j's partner is less than j
y=dp[i-1]-capt[j]+capt[2*i]+capt[(2*i)+1]+asis[j];
if(y<x){
f=j;
f1=parr[j];
x=y;
}
}
else if(parr[j]>j){ //if j's partner is greater than j
y=dp[i-1]-capt[parr[j]]+capt[2*i]+capt[(2*i)+1]+asis[parr[j]];
if(y<x){
f=parr[j];
f1=j;
x=y;
}
}
}
parr[(2*i)+1]=f;
parr[2*i]=f1;
dp[i]=x;
}
cout<<dp[(n/2)-1]<<"\n";
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbG9uZyBsb25nIGRwWzUxMDBdOwkJCQkJCS8vc3RvcmluZyBzb2x1dGlvbiBmb3IgZWFjaCBhZGRpdGlvbiBvZiAyIG5ldyBwaWxvdHMuKDIqaSkgJiAoMippKSsxLiAKbG9uZyBsb25nIGNhcHRbMTAyMDBdLGFzaXNbMTAyMDBdOwkJLy9zYWxhcnkgZm9yIGNhcHRhaW4gYW5kIGFzc2lzdGFudCBmb3IgZWFjaCBpLgppbnQgcGFyclsxMDIwMF07CQkJCQkJLy9zdG9yaW5nIHBhcnRuZXJzIGZvciBlYWNoIGkuCmludCBtYWluKCl7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKDApOwogICAgY291dC50aWUoMCk7CiAgICBpbnQgbixmLGYxOwogICAgY2luPj5uOwogICAgbG9uZyBsb25nIHgseTsKICAgIGZvcihpbnQgaT0wO2k8bjtpKyspCiAgICAgICAgY2luPj5jYXB0W2ldPj5hc2lzW2ldOwogICAgZHBbMF09Y2FwdFsxXSthc2lzWzBdOwkJCQkvL3NvbHV0aW9uIGZvciBmaXJzdCBwYWlyCiAgICBwYXJyWzBdPTE7CQkJCQkJCS8vMXN0IHBpbG90IHBhaXJlZCB3aXRoIDJuZCBhbmQgdmljZSB2ZXJzYS4KICAgIHBhcnJbMV09MDsKICAgIGZvcihpbnQgaT0xO2k8KG4vMik7aSsrKXsKICAgICAgICB4PWRwW2ktMV0rYXNpc1syKmldK2NhcHRbKDIqaSkrMV07CQkvL2lmIHRoZSAyIG5ldyBhZGRlZCBwaWxvdHMgYXJlIHBhaXJlZCB3aXRoIGVhY2ggb3RoZXIKICAgICAgICBmPTIqaTsJCQkJCQkJCQkvL2Ygc3RvcmVzIHRoZSBwYXJ0bmVyIG9mICgyKmkpKzEKICAgICAgICBmMT0oMippKSsxOwkJCQkJCQkJLy9mMSBzdG9yZXMgdGhlIHBhcnRuZXIgb2YgKDIqaSkKICAgICAgICBmb3IoaW50IGo9MDtqPCgyKmkpO2orKyl7CiAgICAgICAgICAgIGlmKHBhcnJbal08ail7CQkJCQkJLy9pZiBqJ3MgcGFydG5lciBpcyBsZXNzIHRoYW4gagogICAgICAgICAgICAgICAgeT1kcFtpLTFdLWNhcHRbal0rY2FwdFsyKmldK2NhcHRbKDIqaSkrMV0rYXNpc1tqXTsJCiAgICAgICAgICAgICAgICBpZih5PHgpewkJCQkKICAgICAgICAgICAgICAgICAgICBmPWo7CiAgICAgICAgICAgICAgICAgICAgZjE9cGFycltqXTsKICAgICAgICAgICAgICAgICAgICB4PXk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZihwYXJyW2pdPmopewkJCQkJLy9pZiBqJ3MgcGFydG5lciBpcyBncmVhdGVyIHRoYW4gagogICAgICAgICAgICAgICAgeT1kcFtpLTFdLWNhcHRbcGFycltqXV0rY2FwdFsyKmldK2NhcHRbKDIqaSkrMV0rYXNpc1twYXJyW2pdXTsKICAgICAgICAgICAgICAgIGlmKHk8eCl7CiAgICAgICAgICAgICAgICAgICAgZj1wYXJyW2pdOwogICAgICAgICAgICAgICAgICAgIGYxPWo7CiAgICAgICAgICAgICAgICAgICAgeD15OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHBhcnJbKDIqaSkrMV09ZjsKICAgICAgICBwYXJyWzIqaV09ZjE7CiAgICAgICAgZHBbaV09eDsKICAgIH0KICAgIGNvdXQ8PGRwWyhuLzIpLTFdPDwiXG4iOwogICAgcmV0dXJuIDA7Cn0K