/*raghav0307 - Raghav Gupta*/

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

#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
#define int ll

/* Min cost max flow (Edmonds-Karp relabelling + fast heap Dijkstra)
 * Based on code by Frank Chu and Igor Naverniouk
 * (http://shygypsy.com/tools/mcmf4.cpp)
 *
 * COMPLEXITY:
 *      - Worst case: O(min(m*log(m)*flow, n*m*log(m)*fcost))
 * FIELD TESTING:
 *      - Valladolid 10594: Data Flow
 * REFERENCE:
 *      Edmonds, J., Karp, R.  "Theoretical Improvements in Algorithmic
 *          Efficieincy for Network Flow Problems".
 *      This is a slight improvement of Frank Chu's implementation.
 **/

#define Inf (LLONG_MAX/2)
#define BUBL { \
    t = q[i]; q[i] = q[j]; q[j] = t; \
    t = inq[q[i]]; inq[q[i]] = inq[q[j]]; inq[q[j]] = t; }
#define Pot(u,v) (d[u] + pi[u] - pi[v])
struct MinCostMaxFlow {
	typedef long long LL;
	int n, qs;
	vector<vector<LL> > cap, cost, fnet;
	vector<vector<int> > adj;
	vector<LL> d, pi;
	vector<int> deg, par, q, inq;
	
	// n = number of vertices
	MinCostMaxFlow(int n): n(n), qs(0), deg(n+1), par(n+1), d(n+1), q(n+1), inq(n+1), pi(n+1), cap(n+1, vector<LL>(n+1)), cost(cap), fnet(cap), adj(n+1, vector<int>(n+1)) {}
	
	// call to add a directed edge. vertices are 0-based
	// ALL COSTS MUST BE NON-NEGATIVE
	void AddEdge(int from, int to, LL cap_, LL cost_) {
		cap[from][to] = cap_; cost[from][to] = cost_;// < 0 ? Inf : cost_;
	}
	
	bool dijkstra( int s, int t ) {
		fill(d.begin(), d.end(), 0x3f3f3f3f3f3f3f3fLL);
		fill(par.begin(), par.end(), -1);
		fill(inq.begin(), inq.end(), -1);
		d[s] = qs = 0;
		inq[q[qs++] = s] = 0;
		par[s] = n;
		while( qs )	{
			int u = q[0]; inq[u] = -1;
			q[0] = q[--qs];
			if( qs ) inq[q[0]] = 0;
			for( int i = 0, j = 2*i + 1, t; j < qs; i = j, j = 2*i + 1 ) {
				if( j + 1 < qs && d[q[j + 1]] < d[q[j]] ) j++;
				if( d[q[j]] >= d[q[i]] ) break;
				BUBL;
			}
			for( int k = 0, v = adj[u][k]; k < deg[u]; v = adj[u][++k] ) {
				if( fnet[v][u] && d[v] > Pot(u,v) - cost[v][u] ) 
					d[v] = Pot(u,v) - cost[v][par[v] = u];			
				if( fnet[u][v] < cap[u][v] && d[v] > Pot(u,v) + cost[u][v] ) 
					d[v] = Pot(u,v) + cost[par[v] = u][v];
				if( par[v] == u ) {
					if( inq[v] < 0 ) { inq[q[qs] = v] = qs; qs++; }
					for( int i = inq[v], j = ( i - 1 )/2, t;
						 d[q[i]] < d[q[j]]; i = j, j = ( i - 1 )/2 )
						 BUBL;
				}
			}
		}
		for( int i = 0; i < n; i++ ) if( pi[i] < Inf ) pi[i] += d[i];
		return par[t] >= 0;
	}

	// Returns: (flow, total cost) between source s and sink t
	// Call this once only. fnet[i][j] contains the flow from i to j. Careful, fnet[i][j] and fnet[j][i] could both be positive.
	pair<LL, LL> mcmf4(int s, int t) {
		for( int i = 0; i < n; i++ )
			for( int j = 0; j < n; j++ )
				if( cap[i][j] || cap[j][i] ) adj[i][deg[i]++] = j;
		LL flow = 0; LL fcost = 0;
		while( dijkstra( s, t ) ) {
			LL bot = LLONG_MAX;
			for( int v = t, u = par[v]; v != s; u = par[v = u] )
				bot = min(bot, fnet[v][u] ? fnet[v][u] : ( cap[u][v] - fnet[u][v] ));
			for( int v = t, u = par[v]; v != s; u = par[v = u] )
				if( fnet[v][u] ) { fnet[v][u] -= bot; fcost -= bot * cost[v][u]; }
				else { fnet[u][v] += bot; fcost += bot * cost[u][v]; }
			flow += bot;
		}
		return make_pair(flow, fcost);
	}
};

signed main(){
	fast_io();
	int n;	cin >> n;
	MinCostMaxFlow mcmf = MinCostMaxFlow(2*n + 6);

	// 0 - source
	// 1 - sink
	// 2 to n+1 red
	// n+2 to 2*n + 1 blue
	// 2n+2 to 2n + 5 type

	vector<pair<pii, int> > red, blue;
	for(int i = 0; i < n; i++){
		int x, y, c;
		cin >> x >> y >> c;
		red.pb({{x,y}, c});
	}
	for(int i = 0; i < n; i++){
		int x, y, c;
		cin >> x >> y >> c;
		blue.pb({{x,y}, c});
	}

	for(int i = 0; i < n; i++){
		mcmf.AddEdge(0, 2 + i, red[i].ss, 0);
		mcmf.AddEdge(2+i, 2*n+2, Inf, red[i].ff.ff + red[i].ff.ss);
		mcmf.AddEdge(2+i, 2*n+3, Inf, red[i].ff.ff - red[i].ff.ss);
		mcmf.AddEdge(2+i, 2*n+4, Inf, -red[i].ff.ff + red[i].ff.ss);
		mcmf.AddEdge(2+i, 2*n+5, Inf, -red[i].ff.ff - red[i].ff.ss);
	}
	for(int i = 0; i < n; i++){
		mcmf.AddEdge(n+2 + i, 1, blue[i].ss, 0);
		mcmf.AddEdge(2*n+2, n+2+i, Inf, -blue[i].ff.ff - blue[i].ff.ss);
		mcmf.AddEdge(2*n+3, n+2+i, Inf, -blue[i].ff.ff + blue[i].ff.ss);
		mcmf.AddEdge(2*n+4, n+2+i, Inf, blue[i].ff.ff - blue[i].ff.ss);
		mcmf.AddEdge(2*n+5, n+2+i, Inf, blue[i].ff.ff + blue[i].ff.ss);
	}

	auto x = mcmf.mcmf4(0, 1);
	cout << -x.ss << "\n";

	return 0;
}

Measured memory_bytes: 128640