#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template void __print(const pair &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifdef LOCAL #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) typedef long long ll; const string DIGITS = "0123456789"; const string ALPH = "abcdefghijklmnopqrstuvwxyz"; ll a[100005]; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N; cin >> N; ios::sync_with_stdio(0); cin.tie(0); ll x, y; FOR(i, 1, N + 1) { cin >> x >> y; a[i] = x - y; } ll sum = 0; FOR(i, 1, N + 1) sum += a[i]; ll ans = sum; for (ll i = N; i >= 1; i--) { sum -= 2 * a[i]; ans = max(ans, sum); } cout << ans << endl; return 0; }