#ifdef NACHIA #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include #include #include #include using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i void chmin(A& l, const A& r){ if(r < l) l = r; } template void chmax(A& l, const A& r){ if(l < r) l = r; } #include #include using Modint = atcoder::static_modint<998244353>; using namespace std; void testcase(){ i64 N; cin >> N; vector> A, B; i64 ans = 0; rep(i,N){ i64 c,x,y; cin >> c >> x >> y; ans += min(x,y); if(x > y) A.push_back({ N-1-c,x-y }); else B.push_back({ c-1,y-x }); } rep(t,2){ sort(A.begin(), A.end()); i64 n = i64(A.size()); priority_queue que; for(i64 t=n-1; t>=0; t--){ while(A.size() && A.back().first >= t){ que.push(A.back().second); A.pop_back(); } if(!que.empty()){ ans += que.top(); que.pop(); } } swap(A,B); } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }