#include #include #include #include using namespace std; bool comp(const pair a, const pair b) { return 2 * a.first - a.second > 2 * b.first - b.second; } int main() { int ans = 0; size_t N; cin >> N; vector> AB(N); for (size_t i = 0; i < N; ++i) cin >> AB[i].first >> AB[i].second; sort(AB.begin(), AB.end(), comp); for (size_t i = 1; i < N; ++i) ans = max(ans, AB[i - 1].second - AB[i - 1].first + AB[i].first); cout << ans; }