/*
Author: Ritik Patel
*/
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&
// #define _GLIBCXX_DEBUG // Iterator safety; out-of-bounds access for Containers, etc.
// #pragma GCC optimize "trapv" // abort() on (signed) integer overflow.
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
*/
//find_by_order()->returns an iterator to the k-th largest element(0-based indexing)
//order_of_key()->Number of items that are strictly smaller than our item
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&
#define int long long int
// #define ll long long int
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
// #define ld long double
// const ld PI = 3.141592;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
#define XOX
vector<string> vec_splitter(string s) {
for(char& c: s) c = c == ','? ' ': c;
stringstream ss; ss << s;
vector<string> res;
for(string z; ss >> z; res.push_back(z));
return res;
}
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
if(idx > 0) cerr << ", ";
stringstream ss; ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&
struct data{
int p, h;
data() {}
data(int _p, int _h): p(_p), h(_h) {}
};
vector<pair<int, pair<int, pair<int, int>> > > S;
bool vis[800005][2];
set<int> check;
int dfs(int i, int id, int which, int L, int R){
vis[id][which] = true;
int lo = i, hi = sz(S) - 1;
while(lo < hi){
int mid = (lo + hi) / 2;
if(S[mid].first >= R){
hi = mid;
} else {
lo = mid + 1;
}
}
int ans = R - L;
for(int j = lo; j < sz(S); ++j){
auto p = S[j];
int start = p.first;
int end = p.second.first;
int ii = p.second.second.first;
int whichii = p.second.second.second;
if(start != R){
break;
}
if(vis[ii][whichii] or check.count(ii)){
continue;
}
check.insert(ii);
ans = max(ans, dfs(j, ii, whichii, L, end));
check.erase(ii);
}
return ans;
}
void solve(){
int N; cin >> N;
vector<data> A(N);
//Reset
S.clear();
for(int i = 0; i <= N; ++i){
for(int j = 0; j < 2; ++j){
vis[i][j] = false;
}
}
for(int i = 0; i < N; ++i){
int x, y; cin >> x >> y;
A[i] = {x, y};
// debug(A[i].p, A[i].h);
}
for(int i = 0; i < N; ++i){
S.push_back( { A[i].p - A[i].h, {A[i].p , {i, 0} } } );
S.push_back( { A[i].p , {A[i].p + A[i].h, {i, 1} } } );
}
sort(all(S));
int ans = 0;
for(int i = 0; i < sz(S); ++i){
auto p = S[i];
int start = p.first;
int end = p.second.first;
int id = p.second.second.first;
int which = p.second.second.second;
// debug(i, start, end, id, which);
if(vis[id][which]){
continue;
}
check.clear();
check.insert(id);
ans = max(ans, dfs(i, id, which, start, end));
}
cout << ans << '\n';
}
int32_t main(){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ios_base::sync_with_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gdmlzWzgwMDAwNV1bMl07CnNldDxpbnQ+IGNoZWNrOwoKaW50IGRmcyhpbnQgaSwgaW50IGlkLCBpbnQgd2hpY2gsIGludCBMLCBpbnQgUil7CiAgICAKICAgIHZpc1tpZF1bd2hpY2hdID0gdHJ1ZTsKCiAgICBpbnQgbG8gPSBpLCBoaSA9IHN6KFMpIC0gMTsKICAgIHdoaWxlKGxvIDwgaGkpewogICAgICAgIGludCBtaWQgPSAobG8gKyBoaSkgLyAyOwogICAgICAgIGlmKFNbbWlkXS5maXJzdCA+PSBSKXsKICAgICAgICAgICAgaGkgPSBtaWQ7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIH0KICAgIH0KCiAgICBpbnQgYW5zID0gUiAtIEw7IAogICAgZm9yKGludCBqID0gbG87IGogPCBzeihTKTsgKytqKXsKICAgICAgICBhdXRvIHAgPSBTW2pdOwogICAgICAgIGludCBzdGFydCA9IHAuZmlyc3Q7CiAgICAgICAgaW50IGVuZCA9IHAuc2Vjb25kLmZpcnN0OwogICAgICAgIGludCBpaSA9IHAuc2Vjb25kLnNlY29uZC5maXJzdDsKICAgICAgICBpbnQgd2hpY2hpaSA9IHAuc2Vjb25kLnNlY29uZC5zZWNvbmQ7CiAgICAgICAgaWYoc3RhcnQgIT0gUil7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBpZih2aXNbaWldW3doaWNoaWldIG9yIGNoZWNrLmNvdW50KGlpKSl7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBjaGVjay5pbnNlcnQoaWkpOwogICAgICAgIGFucyA9IG1heChhbnMsIGRmcyhqLCBpaSwgd2hpY2hpaSwgTCwgZW5kKSk7CiAgICAgICAgY2hlY2suZXJhc2UoaWkpOwogICAgfQogICAgcmV0dXJuIGFuczsKfQoKdm9pZCBzb2x2ZSgpewoKICAgIGludCBOOyBjaW4gPj4gTjsKICAgIHZlY3RvcjxkYXRhPiBBKE4pOwoKICAgIC8vUmVzZXQKICAgIFMuY2xlYXIoKTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPD0gTjsgKytpKXsKICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgMjsgKytqKXsKICAgICAgICAgICAgdmlzW2ldW2pdID0gZmFsc2U7CgogICAgICAgIH0KICAgIH0KCgogICAgZm9yKGludCBpID0gMDsgaSA8IE47ICsraSl7CiAgICAgICAgaW50IHgsIHk7IGNpbiA+PiB4ID4+IHk7CiAgICAgICAgQVtpXSA9IHt4LCB5fTsKICAgICAgICAvLyBkZWJ1ZyhBW2ldLnAsIEFbaV0uaCk7CiAgICB9CiAgICAKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBOOyArK2kpewogICAgICAgIFMucHVzaF9iYWNrKCB7IEFbaV0ucCAtIEFbaV0uaCwge0FbaV0ucCAsIHtpLCAwfSB9IH0gKTsKICAgICAgICBTLnB1c2hfYmFjayggeyBBW2ldLnAgLCB7QVtpXS5wICsgQVtpXS5oLCB7aSwgMX0gfSB9ICk7CiAgICB9CiAgICBzb3J0KGFsbChTKSk7CgogICAgaW50IGFucyA9IDA7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgc3ooUyk7ICsraSl7CgogICAgICAgIGF1dG8gcCA9IFNbaV07CiAgICAgICAgaW50IHN0YXJ0ID0gcC5maXJzdDsKICAgICAgICBpbnQgZW5kID0gcC5zZWNvbmQuZmlyc3Q7CiAgICAgICAgaW50IGlkID0gcC5zZWNvbmQuc2Vjb25kLmZpcnN0OwogICAgICAgIGludCB3aGljaCA9IHAuc2Vjb25kLnNlY29uZC5zZWNvbmQ7CiAgICAgICAgLy8gZGVidWcoaSwgc3RhcnQsIGVuZCwgaWQsIHdoaWNoKTsKCiAgICAgICAgaWYodmlzW2lkXVt3aGljaF0pewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgY2hlY2suY2xlYXIoKTsKICAgICAgICBjaGVjay5pbnNlcnQoaWQpOwogICAgICAgIGFucyA9IG1heChhbnMsIGRmcyhpLCBpZCwgd2hpY2gsIHN0YXJ0LCBlbmQpKTsKICAgIH0KICAgIGNvdXQgPDwgYW5zIDw8ICdcbic7CiAgICAKfQogCmludDMyX3QgbWFpbigpewogICAgZnJlb3BlbigiaW5wdXQudHh0IiwiciIsc3RkaW4pOwogICAgZnJlb3Blbigib3V0cHV0LnR4dCIsInciLHN0ZG91dCk7IAogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7Y2luLnRpZShudWxscHRyKTtjb3V0LnRpZShudWxscHRyKTsKICAgIGludCBUID0gMTsgCiAgICBjaW4gPj4gVDsKICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gVDsgKytpKXsKICAgICAgICBjb3V0IDw8ICJDYXNlICMiIDw8IGkgPDwgIjogIjsKICAgICAgICBzb2x2ZSgpOwogICAgfQogICAgcmV0dXJuIDA7Cn0KIAovKgpTYW1wbGUgaW5wCiovCg==