#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e3+5,_N=N<<1,_M=_N*5<<1,inf=2e9;
const ll INF=1e18;
struct flow{
	int S,T,tot=1,cur[_N],head[_N],nxt[_M],adj[_M],cap[_M],val[_M],q[_M<<5],vis[_N],flow;
	ll cost,dis[_N];
	inline void addedge(ri x,ri y,ri c,ri w){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		cap[tot]=c;
		val[tot]=w;
	}
	inline void add(ri x,ri y,ri c,ri w){
		addedge(x,y,c,w);
		addedge(y,x,0,-w);
	}
	inline bool spfa(){
		ri l,r,i,x,y;
		for(i=S;i<=T;++i) cur[i]=head[i],dis[i]=-INF,vis[i]=0;
		q[l=r=1]=S;dis[S]=0;
		for(l=1;l<=r;++l){
			x=q[l];vis[x]=0;
			for(i=head[x];i;i=nxt[i])
				if(cap[i]&&dis[y=adj[i]]<dis[x]+val[i]){
					dis[y]=dis[x]+val[i];
					if(!vis[y]) q[++r]=y,vis[y]=1;
				}
		}
		return dis[T]>-INF;
	}
	inline int dfs(ri x,ri now){
		if(x==T) return now;
		vis[x]=1;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(!vis[y=adj[i]]&&cap[i]&&dis[y]==dis[x]+val[i]){
				tmp=dfs(y,min(now-res,cap[i]));
				cap[i]-=tmp;
				cap[i^1]+=tmp;
				res+=tmp;
				if(res==now){
					vis[x]=0;
					break;
				}
			}
		return res;
	}
	inline ll costflow(){
		flow=0;
		cost=0;
		ri tmp;
		while(spfa())
			tmp=dfs(S,inf),
			flow+=tmp,
			cost+=tmp*dis[T];
		return cost;
	}
}flow;
int main(){
	ri n,i,x,y,c,p1,p2,p3,p4;
	gi(n);
	flow.S=0;
	p1=n<<1|1;
	p2=p1+1;
	p3=p2+1;
	p4=p3+1;
	flow.T=p4+1;
	for(i=1;i<=n;++i)
		gi(x),gi(y),gi(c), 
		flow.add(flow.S,i,c,0),
		flow.add(i,p1,c,x+y),
		flow.add(i,p2,c,x-y),
		flow.add(i,p3,c,-x+y),
		flow.add(i,p4,c,-x-y);
	for(i=1;i<=n;++i)
		gi(x),gi(y),gi(c), 
		flow.add(i+n,flow.T,c,0),
		flow.add(p1,i+n,c,-x-y),
		flow.add(p2,i+n,c,-x+y),
		flow.add(p3,i+n,c,x-y),
		flow.add(p4,i+n,c,x+y);
	print(flow.costflow());putc('\n');
	return 0;
}

Measured memory_bytes: 4864