#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000000LL
long long get(vector<long long> c,vector<long long> x){
	vector<pair<long long,long long>> t;
	set<long long> S;
	rep(i,c.size()){
		t.push_back({x[i],c[i]});
		S.insert(i+1);
	}
	long long res = 0;
	sort(t.rbegin(),t.rend());
	rep(i,t.size()){
		auto it = S.upper_bound(t[i].second);
		if(it == S.begin())continue;
		it--;
		res += t[i].first;
		S.erase(it);
	}
	return res;
}

int main(){
	
	int n;
	cin>>n;
	vector<int> c(n),x(n),y(n);
	long long ans = 0;
	vector<vector<long long>> cc(2),xx(2),yy(2);
	rep(i,n){
		long long c,x,y;
		cin>>c>>x>>y;
		swap(x,y);
		if(x==y)ans += x;
		else if(x<y){
			cc[0].push_back(n-c);
			xx[0].push_back(y-x);
			ans += x;
		}
		else{
			cc[1].push_back(c);
			xx[1].push_back(x-y);
			ans += y;
		}
	}
	rep(i,2){
		ans += get(cc[i],xx[i]);
	}
	cout<<ans<<endl;
	
	
	return 0;
}