#include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; ll s = 0; vector a(n); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; s += a[i] = y - x; } ll r = s; for (int i = 0; i < n; i++) { s -= a[i] * 2; r = max(r, s); } cout << r << endl; return 0; }