#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long  ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;

int max_n;
const int mn = 100000;
struct edge {
	int to, cap; ll cost; int rev;
};
vector<edge> G[mn];
P par[mn];
ll dist[mn];
void add_edge(int from, int to, int cap, ll cost) {
	G[from].push_back({ to,cap,cost,(int)G[to].size() });
	G[to].push_back({ from,0,-cost,(int)G[from].size() - 1 });
	max_n = max({ max_n, from + 1, to + 1 });
}
void add_edge2(int from, int to, int cap, ll cost) {
	G[from].push_back({ to,cap,cost,-1 });
	//G[to].push_back({ from,0,-cost,(int)G[from].size() - 1 });
	max_n = max({ max_n, from + 1, to + 1 });
}
ll minimum_road(int s, int t) {
	fill(par, par + max_n, P{ -1,-1 });
	fill(dist, dist + max_n, INF);
	dist[s] = 0;
	priority_queue<LP, vector<LP>, greater<LP>> q; q.push({ 0,s });
	while (!q.empty()) {
		LP p = q.top(); q.pop();
		int id = p.second;
		if (id == t)continue;
		if (p.first > dist[id])continue;
		rep(j, G[id].size()) {
			if (G[id][j].cap > 0) {
				int to = G[id][j].to;
				ll nd = p.first + G[id][j].cost;
				if (nd < dist[to]) {
					dist[to] = nd;
					par[to] = { id,j };
					q.push({ dist[to],to });
				}
			}
		}
	}
	int cur = t;
	int f = mod;
	while (cur != s) {
		int p = par[cur].first, j = par[cur].second;
		if (p < 0)return -1;
		f = min(f, G[p][j].cap);
		cur = p;
	}
	cur = t;
	while (cur != s) {
		int p = par[cur].first,j=par[cur].second;
		if (p < 0)return -1;
		G[p][j].cap-=f;
		if (G[p][j].rev >= 0) {
			G[cur][G[p][j].rev].cap+=f;
		}
		cur = p;
	}
	//cout << "hello " << f << endl;

	return dist[t]*f;
}
ll minimum_cost_flow(int s, int t, int k) {
	ll ret = 0;
	rep(i, k) {
		ll z = minimum_road(s, t);
		if (z < 0)break;
		ret += z;
	}
	return ret;
}

ll sup = 2 * mod;
vector<LP> vr, vb;
vector<ll> cr, cb;

int dx[4] = { -1,-1,1,1 };
int dy[4] = { -1,1,-1,1 };
void solve() {
	int n; cin >> n;
	int sum = 0;
	rep(i, n) {
		ll x, y, c; cin >> x >> y >> c;
		vr.push_back({ x,y });
		cr.push_back(c);
		sum += c;
	}
	rep(i, n) {
		ll x, y, c; cin >> x >> y >> c;
		vb.push_back({ x,y });
		cb.push_back(c);
	}
	int s = 2 * n, t = 2 * n + 1;
	int mid = 2 * n + 2;
	rep(i, n) {
		add_edge2(s, i, cr[i], 0);
		add_edge2(n + i, t, cb[i], 0);
		rep(j, 4) {
			ll costr = dx[j] * vr[i].first + dy[j] * vr[i].second;
			ll costb = dx[j] * vb[i].first + dy[j] * vb[i].second;
			add_edge(i, mid + j, mod, sup - costr);
			add_edge(mid + 3 - j, i + n, mod, sup - costb);
		}
	}
	ll ans = minimum_cost_flow(s, t, sum);
	ans = 2 * sup * sum - ans;
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n)solve();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 3496