#include <bits/stdc++.h>
#define fi first
#define se second
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)
template<typename T>
void __prine_one(const char *&s, const T &x)
{
while (*s == ' ') ++s;
const char *p = s;
int bal = 0;
while (*s)
{
if (*s == '(') ++bal;
else if (*s == ')') --bal;
else if (*s == ',' && bal == 0) break;
++s;
}
cerr.write(p, s - p) << " = " << x;
if (*s == ',')
{
cerr << " , ";
++s;
}
}
template<typename... Args>
void debug(const char *s, Args... args)
{
cerr << "[ ";
int dummy[] = {0, (__prine_one(s, args), 0)...};
(void)dummy;
cerr << " ]\n\n";
}
template<class X>
bool maximize(X &a, const X &b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template<class X>
bool minimize(X &a, const X &b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
// --------------------------------------------------------------------------------------------
const int maxn = 1e5 + 3;
int n;
ll X[maxn], G[maxn], D[maxn], preX[maxn], preG[maxn], preD[maxn];
vector<ll> ids;
// --------------------------------------------------------------------------------------------
int lower(ll x) {return lower_bound(all(ids), x) - ids.begin() + 1;}
int upper(ll x) {return upper_bound(all(ids), x) - ids.begin() + 1;}
struct FenTree
{
vector<int> fw;
void init(int n)
{
fw.assign(n + 3, 1e9);
}
void upd(int pos, int val)
{
for (; pos < (int)fw.size(); pos += pos & -pos)
fw[pos] = min(fw[pos], val);
}
int get(int pos)
{
int res = 1e9;
for (; pos; pos &= pos - 1)
res = min(res, fw[pos]);
return res;
}
} fw;
void solve()
{
cin >> n;
FOR(i, 1, n)
{
cin >> X[i] >> G[i] >> D[i];
preX[i] = preX[i - 1] + X[i];
preG[i] = preG[i - 1] + G[i];
preD[i] = preD[i - 1] + D[i];
ids.push_back(preD[i] - X[i]);
ids.push_back(preD[i - 1] - X[i]);
}
uni(ids);
fw.init((int)ids.size());
ll res = -1e18;
FOR(i, 1, n)
{
fw.upd(lower(preD[i - 1] - X[i]), i);
int x = fw.get(lower(preD[i] - X[i]));
if (x != 1e9) res = max(res, preG[i] - preG[x - 1]);
}
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define TASK "TEST"
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
solve();
return 0;
}