#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 2019;

struct mcmf{
struct edg{ int pos, cap, rev, cost; };
vector<edg> gph[MAXN];
void clear(){
	for(int i=0; i<MAXN; i++) gph[i].clear();
}
void add_edge(int s, int e, int x, int c){
	gph[s].push_back({e, x, (int)gph[e].size(), -c});
	gph[e].push_back({s, 0, (int)gph[s].size()-1, c});
}
lint dist[MAXN];
int pa[MAXN], pe[MAXN];
bool inque[MAXN];
bool spfa(int src, int sink){
	memset(dist, 0x3f, sizeof(dist));
	memset(inque, 0, sizeof(inque));
	queue<int> que;
	dist[src] = 0;
	inque[src] = 1;
	que.push(src);
	bool ok = 0;
	while(!que.empty()){
		int x = que.front();
		que.pop();
		if(x == sink) ok = 1;
		inque[x] = 0;
		for(int i=0; i<gph[x].size(); i++){
			edg e = gph[x][i];
			if(e.cap > 0 && dist[e.pos] > dist[x] + e.cost){
				dist[e.pos] = dist[x] + e.cost;
				pa[e.pos] = x;
				pe[e.pos] = i;
				if(!inque[e.pos]){
					inque[e.pos] = 1;
					que.push(e.pos);
				}
			}
		}
	}
	return ok;
}
lint match(int src, int sink){
	lint ret = 0;
	while(spfa(src, sink)){
		int cap = 1e9;
		for(int pos = sink; pos != src; pos = pa[pos]){
			cap = min(cap, gph[pa[pos]][pe[pos]].cap);
		}
		ret += dist[sink] * cap;
		for(int pos = sink; pos != src; pos = pa[pos]){
			int rev = gph[pa[pos]][pe[pos]].rev;
			gph[pa[pos]][pe[pos]].cap -= cap;
			gph[pos][rev].cap += cap;
		}
	}
	return ret;
}
}mcmf;

int n;

struct foo{
	int x, y, z, t;
}a[MAXN];

int main(){
	cin >> n;
	for(int i=1; i<=n+n; i++) cin >> a[i].x >> a[i].y >> a[i].z, a[i].t = (i >= n);
	for(int i=1; i<=n; i++){
		mcmf.add_edge(i, 2*n+1, a[i].z, a[i].x + a[i].y);
		mcmf.add_edge(i, 2*n+2, a[i].z, a[i].x - a[i].y);
		mcmf.add_edge(i, 2*n+3, a[i].z, -a[i].x + a[i].y);
		mcmf.add_edge(i, 2*n+4, a[i].z, -a[i].x - a[i].y);
		mcmf.add_edge(2*n+5, i+n, a[i+n].z, -a[i+n].x - a[i+n].y);
		mcmf.add_edge(2*n+6, i+n, a[i+n].z, -a[i+n].x + a[i+n].y);
		mcmf.add_edge(2*n+7, i+n, a[i+n].z, a[i+n].x - a[i+n].y);
		mcmf.add_edge(2*n+8, i+n, a[i+n].z, a[i+n].x + a[i+n].y);
		mcmf.add_edge(0, i, a[i].z, 0);
		mcmf.add_edge(i + n, 2*n+9, a[i+n].z, 0);
	}
	for(int i=1; i<=4; i++) mcmf.add_edge(2*n+i, 2*n+i+4, 10000, 0);
	cout << -mcmf.match(0, 2*n+9) << endl;
}
