#include using namespace std; using ll = long long; int main() { int N; cin >> N; ll ans = 0; vector C(N), X(N), Y(N); vector> G(N + 1); for(int i = 0; i < N; i++) { cin >> C[i] >> X[i] >> Y[i]; ans += X[i]; G[C[i]].push_back(Y[i] - X[i]); } int k = 0; priority_queue que; for(int i = N; i >= 1; i--) { for(ll x : G[i]) que.push(x); if(que.empty()) { k++; }else { ll x = que.top(); if(x < 0 && k > 0) { k--; }else { ans += x, que.pop(); } } } cout << ans << endl; }