#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]; if(Y[i] - X[i] > 0) G[C[i]].push_back(Y[i] - X[i]); } priority_queue que; for(int i = N; i >= 1; i--) { for(ll x : G[i]) que.push(x); if(!que.empty()) ans += que.top(), que.pop(); } cout << ans << endl; }