#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() int main() { cin.tie(nullptr); int N; cin >> N; vector A(2 * N), sum(N); rep(i, 0, 2 * N) cin >> A[i]; rep(i, 0, N) sum[i] = A[2 * i] - A[2 * i + 1]; rep(i, 1, N) sum[i] += sum[i - 1]; ll ans = LLONG_MIN; rep(i, 0, N) { ll res = 2 * sum[i] - sum[N - 1]; ans = max(res, ans); } cout << ans << '\n'; }