//https://atcoder.jp/contests/aising2020/submissions/59445625 #include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, static_modint& a) {long long x; is >> x; a = x; return is;} template istream& operator>>(istream& is, dynamic_modint& a) {long long x; is >> x; a = x; return is;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template ostream& operator<<(ostream& os, const set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const unordered_set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const atcoder::segtree& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const atcoder::lazy_segtree& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} int solve(){ int n; cin >> n; vector> x_great(n + 1); vector> y_great(n + 1); long long ans = 0; rep(i, n){ int k, x, y; cin >> k >> x >> y; int c = n - k; int guarantee = min(x, y); ans += guarantee; x -= guarantee; y -= guarantee; if(x > 0){ x_great[c].push_back(x); } if(y > 0){ y_great[n - c].push_back(y); } } auto solve = [&](vector> schedule){ long long res = 0; priority_queue pq; rep(i, n){ for(long long val : schedule[i]) pq.push(val); if(pq.size()){ long long val = pq.top(); pq.pop(); res += val; } } return res; }; ans += solve(x_great); ans += solve(y_great); cout << ans << "\n"; return 0; } int main(){ solve(); return 0; }