#include #include #include using lint = long long; constexpr lint INF = 1LL << 50; void solve() { int n; std::cin >> n; std::vector fs(n + 2, 0), bs(n + 2, 0); for (int i = 1; i <= n; ++i) { lint x, y; std::cin >> x >> y; fs[i] = x - y; bs[i] = y - x; } for (int i = 1; i <= n; ++i) fs[i] += fs[i - 1]; for (int i = n; i >= 1; --i) bs[i] += bs[i + 1]; lint ans = -INF; for (int f = 0; f <= n; ++f) { ans = std::max(ans, fs[f] + bs[f + 1]); } std::cout << ans << std::endl; } int main() { std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }