#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 50;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

namespace MCF { 
	//init before you use it. O(|V|^2 + |F||E|log|V|), no negative loops allowed
	// linf should be bigger than max(dist) but watch out for overflow. (1ll << 40) often do.

	struct edge { int to; ll cap; ll cost; int rev; };

	int V; //num of vertex
	vector<edge> G[MAX_V];
	ll h[MAX_V];
	ll dist[MAX_V];
	int prevv[MAX_V], preve[MAX_V];

	void init(int v) { //other things don't have to be inited.
		V = v;
		rep(i, 0, v) G[i].clear();
	}

	void add_edge(int from, int to, ll cap, ll cost) {
		cost *= -1;
		// debug(from, to, cap, cost);
		G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
		G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});
	}

	ll get(int s, int t, ll f) {
		ll res = 0;
		memset(h, 0, sizeof(h));
		rep(k, 0, V) {
			rep(i, 0, V) {
				rep(j ,0, (int)G[i].size()) {
					edge &e = G[i][j];
					if(e.cap == 0) continue;
					MIN(h[e.to], h[i] + e.cost);
				}
			}
		}
		while(f > 0) {
			priority_queue<pi, vector<pi>, greater<pi> > que;
			fill(dist, dist + V, linf);
			dist[s] = 0;
			que.push(pi(0, s));
			while(!que.empty()) {
				pi p = que.top(); que.pop();
				int v = p.sec;
				if(dist[v] < p.fst) continue;
				rep(i, 0, (int)G[v].size()) {
					edge &e = G[v][i];
					if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
						dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
						prevv[e.to] = v;
						preve[e.to] = i;
						que.push(pi(dist[e.to], e.to));
					}
				}
			}

			if(dist[t] == linf) return -1;
			rep(v, 0, V) h[v] += dist[v];

			ll d = f;
			for(int v = t; v != s; v = prevv[v]) {
				d = min(d, G[prevv[v]][preve[v]].cap);
			}
			f -= d;
			res += d * h[t];
			for(int v = t; v != s; v = prevv[v]) {
				edge &e = G[prevv[v]][preve[v]];
				e.cap -= d;
				G[v][e.rev].cap += d;
			}
		}
		return res;
	}
}

int N, sum;

ll AX[MAX_N], AY[MAX_N], AS[MAX_N];
ll BX[MAX_N], BY[MAX_N], BS[MAX_N];

void pre(int d) {
	vector<int> vx;
	rep(i, 0, N) vx.pb(AX[i]);
	rep(i, 0, N) vx.pb(BX[i]);
	sort(all(vx)); vx.erase(unique(all(vx)), vx.end());
	// debug(vx);
	rep(i, 0, N) {
		int at = lower_bound(all(vx), AX[i]) - vx.begin();
		MCF::add_edge(i, d + at, AS[i], 0);
		MCF::add_edge(i, d + at + 2 * N, AS[i], 0);
	}
	rep(i, 0, N) {
		int at = lower_bound(all(vx), BX[i]) - vx.begin();
		MCF::add_edge(d + at, i + N, BS[i], 0);
		MCF::add_edge(d + at + 2 * N, i + N, BS[i], 0);
	}
	rep(i, 0, sz(vx) - 1) {
		MCF::add_edge(d + i, d + i + 1, sum, vx[i + 1] - vx[i]);
	}
	rep(i, 0, sz(vx) - 1) {
		MCF::add_edge(d + i + 1 + 2 * N, d + i + 2 * N, sum, vx[i + 1] - vx[i]);
	}
}

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> AX[i] >> AY[i] >> AS[i];
	rep(i, 0, N) cin >> BX[i] >> BY[i] >> BS[i];
	sum = accumulate(AS, AS + N, 0);
	int S = 10 * N, T = 10 * N + 1;
	MCF::init(10 * N + 2);
	rep(i, 0, N) MCF::add_edge(S, i, AS[i], 0);
	rep(i, 0, N) MCF::add_edge(i + N, T, BS[i], 0);

	rep(i, 0, N) {
		ll x = AX[i], y = AY[i];
		AX[i] = x - y;
		AY[i] = x + y;
	}
	rep(i, 0, N) {
		ll x = BX[i], y = BY[i];
		BX[i] = x - y;
		BY[i] = x + y;
	}
	// debug(vi(AX, AX + N));
	// debug(vi(AY, AY + N));
	// debug(vi(BX, BX + N));
	// debug(vi(BY, BY + N));
	pre(2 * N);
	rep(i, 0, N) {
		swap(AX[i], AY[i]);
		swap(BX[i], BY[i]);
	}
	pre(6 * N);
	cout << MCF::get(S, T, sum) * -1 << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 18176