#include<bits/stdc++.h>
using namespace std;
const int maxn = 20005;
typedef long long ll;
int en[maxn],nt[maxn],la[maxn],len[maxn],v[maxn],owo=1;
void adg(int x,int y,int z,int vv) {
	en[++owo]=y; nt[owo]=la[x]; la[x]=owo; len[owo]=z; v[owo]=vv;
	en[++owo]=x; nt[owo]=la[y]; la[y]=owo; len[owo]=-z; v[owo]=0;
}
int S,T,z1,z2,z3,z4;

int n;
queue<int>q;
bool rd[maxn];
int path[maxn],epath[maxn];
ll ans,dis[maxn];
bool spfa() {
	for(int i=1;i<=T;i++) dis[i] = -1e16,rd[i] = 0;
	q.push(S); dis[S] = 0;
	while(q.size()) {
		int x = q.front(); q.pop(); rd[x] = 0;
		for(int it=la[x];it;it=nt[it]) {
			int y = en[it];
			if(v[it]&&dis[y]<dis[x]+len[it]) {
				dis[y] = dis[x] + len[it];
				path[y] = x;
				epath[y] = it;
				if(!rd[y]) q.push(y),rd[y] = 1;
			}
		}
	}
	if(dis[T]==(ll)-1e16) return 0;
	int mi = 0x3f3f3f3f;
	for(int p=T;p!=S;p=path[p]) mi = min(mi,v[epath[p]]);
	ans += 1ll * mi * dis[T];
	for(int p=T;p!=S;p=path[p]) {
		v[epath[p]] -= mi;
		v[epath[p]^1] += mi;
	}
	return 1;
}

int main() {
	scanf("%d",&n);
	z1 = n+n+1; z2 = n+n+2; z3 = n+n+3; z4 = n+n+4;
	S = n+n+5; T = n+n+6;
	for(int i=1;i<=n;i++) {
		int x,y,c; scanf("%d%d%d",&x,&y,&c);
		adg(i,z1,x+y,0x3f3f3f3f);
		adg(i,z2,-x+y,0x3f3f3f3f);
		adg(i,z3,x-y,0x3f3f3f3f);
		adg(i,z4,-x-y,0x3f3f3f3f);
		adg(S,i,0,c);
	}
	for(int i=1;i<=n;i++) {
		int x,y,c; scanf("%d%d%d",&x,&y,&c);
		adg(z1,i+n,-x-y,0x3f3f3f3f);
		adg(z2,i+n,x-y,0x3f3f3f3f);
		adg(z3,i+n,-x+y,0x3f3f3f3f);
		adg(z4,i+n,x+y,0x3f3f3f3f);
		adg(i+n,T,0,c);
	}
	while(spfa());
	printf("%lld",ans);
}