#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;

int n, c[N], x[N], y[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(int i = 1; i <= n; i ++)
        cin >> c[i] >> x[i] >> y[i];

    vector<int> l, r;
    long long ans = 0;
    for(int i = 1; i <= n; i ++) {
        ans += min(x[i], y[i]);
        if (x[i] > y[i]) r.push_back(i);
        else if(x[i] < y[i]) l.push_back(i);
    }

    sort(l.begin(), l.end(), [](int a, int b) {return c[a] < c[b];});
    sort(r.begin(), r.end(), [](int a, int b) {return c[a] > c[b];});

    {
        priority_queue<int> q;
        for(int i = 1; i <= n; i ++) {
            while(r.size() && i > c[r.back()]) {
                q.push(x[r.back()] - y[r.back()]);
                r.pop_back();
            }
            if(q.size()) {
                ans += q.top();
                q.pop();
            }
        }
    }

    {
        priority_queue<int> q;
        for(int i = n; i >= 1; i --) {
            while(l.size() && i <= c[l.back()]) {
                q.push(y[l.back()] - x[l.back()]);
                l.pop_back();
            }
            if(q.size()) {
                ans += q.top();
                q.pop();
            }
        }
    }
    cout << ans << "\n";
}