#include #include #include #include #include #include #define Max(a, b) ((a) > (b) ? (a) : (b)) #define Min(a, b) ((a) > (b) ? (b) : (a)) #define abs(x) ((x) > 0 ? (x) : -(x)) #define MOD 1000000007 //10^9 + 7 #define endl printf("\n") typedef long long ll; int main(int argc, char *argv[]) { ll c[100000], d[100000]; int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld %lld", &c[i], &d[i]); ll cost[100000]; cost[0] = 2 * c[0]; for (int i = 1; i < n; i++) cost[i] = cost[i - 1] + Min(Min(2 * c[i], c[i] + d[i]), 2 * c[i] - c[i - 1] + d[i]); printf("%lld\n", cost[n - 1]); return 0; }