// Slower C++ solution:
#include<cstdio>

#include<queue>

#include<cstring>

#include<algorithm>

using namespace std;

#define N 2050

struct edge{int t,next,v,c;}ed[N*30];

int n,a,b,c,head[N],ct,cnt,vis2[N],vis3[N],vis[N];

long long dis[N],as;

void adde(int f,int t,int w,int c){ed[++cnt]=(edge){t,head[f],w,c};head[f]=cnt;ed[++cnt]=(edge){f,head[t],0,-c};head[t]=cnt;}

void bfs2(int t)

{

	memset(vis2,0,sizeof(vis2));

	queue<int> tp;

	tp.push(t);

	vis2[t]=1;

	while(!tp.empty())

	{

		int x=tp.front();tp.pop();

		for(int i=head[x];i;i=ed[i].next)

		if(ed[i^1].v)

		if(!vis2[ed[i].t])vis2[ed[i].t]=1,tp.push(ed[i].t);

	}

}

bool spfa_is_dead(int s,int t)

{

	bfs2(t);

	memset(vis,0,sizeof(vis));

	memset(vis3,0,sizeof(vis3));

	memset(dis,0x3f,sizeof(dis));

	queue<int> tp;

	tp.push(s);

	dis[s]=0;vis[s]=1;

	while(!tp.empty())

	{

		int x=tp.front();tp.pop();

		vis[x]=0;

		for(int i=head[x];i;i=ed[i].next)

		if(ed[i].v&&vis2[ed[i].t])

		if(dis[ed[i].t]>dis[x]+ed[i].c)

		{

			dis[ed[i].t]=dis[x]+ed[i].c;

			if(!vis[ed[i].t])vis[ed[i].t]=1,tp.push(ed[i].t);

		}

	}

	return dis[t]<=1e15;

}

int dfs(int u,int t,int f)

{

	if(u==t||!f)return f;

	vis3[u]=1;

	int as1=0,tp;

	for(int i=head[u];i;i=ed[i].next)

	if(!vis3[ed[i].t]&&vis2[ed[i].t]&&ed[i].v&&dis[ed[i].t]==dis[u]+ed[i].c&&(tp=dfs(ed[i].t,t,min(ed[i].v,f))))

	{

		as1+=tp,f-=tp;

		ed[i].v-=tp,ed[i^1].v+=tp;

		as+=1ll*ed[i].c*tp;

		if(!f)return as1;

	}

	return as1;

}

long long dinic(int s,int t)

{

	while(spfa_is_dead(s,t))

	dfs(s,t,1e8);

	return as;

}

int main()

{

	scanf("%d",&n);

	ct=6;cnt=1;

	for(int i=1;i<=n;i++)

	{

		scanf("%d%d%d",&a,&b,&c);

		++ct;

		adde(1,ct,c,0);

		adde(ct,3,c,a+b);

		adde(ct,4,c,a-b);

		adde(ct,5,c,-a+b);

		adde(ct,6,c,-a-b);

	}

	for(int i=1;i<=n;i++)

	{

		scanf("%d%d%d",&a,&b,&c);

		++ct;

		adde(ct,2,c,0);

		adde(3,ct,c,-a-b);

		adde(4,ct,c,-a+b);

		adde(5,ct,c,a-b);

		adde(6,ct,c,a+b);

	}

	printf("%lld\n",-dinic(1,2));

}//12

// Faster C++ solution for the same problem (measured speedup: 4.20514872892534x):
#include <cstdio>

#include <algorithm>

using namespace std;



typedef long long ll;



const int INF = (1<<30);

const ll inf = 1E15;



struct FlowGraph{

	#define MAXV (2500)

	#define MAXE (20*MAXV)

	struct edge{

		int to, cap, flow; ll cost;

		edge *nxt, *rev;

	}edges[MAXE + 5], *adj[MAXV + 5], *cur[MAXV + 5], *ecnt;

	FlowGraph() {ecnt = edges;}

	void addedge(int u, int v, int c, ll w) {

		edge *p = (++ecnt), *q = (++ecnt);

		p->to = v, p->cap = c, p->flow = 0, p->cost = w;

		p->nxt = adj[u], adj[u] = p;

		q->to = u, q->cap = 0, q->flow = 0, q->cost = -w;

		q->nxt = adj[v], adj[v] = q;

		p->rev = q, q->rev = p;

	}

	int s, t;

	int hp[MAXV + 5]; ll f[MAXV + 5];

	void update(int x, ll k) {

		f[x] = k;

		while( x ) {

			hp[x] = x;

			if( (x<<1) <= t && f[hp[x<<1]] < f[hp[x]] )

				hp[x] = hp[x<<1];

			if( (x<<1|1) <= t && f[hp[x<<1|1]] < f[hp[x]] )

				hp[x] = hp[x<<1|1];

			x >>= 1;

		}

	}

	ll d[MAXV + 5], h[MAXV + 5];

	bool relabel() {

		for(int i=1;i<=t;i++)

			h[i] += d[i], d[i] = f[i] = inf, hp[i] = i, cur[i] = adj[i];

		update(s, d[s] = 0);

		while( f[hp[1]] != inf ) {

			int x = hp[1]; update(x, inf);

			for(edge *p=adj[x];p;p=p->nxt) {

				ll dis = d[x] + p->cost + (h[x] - h[p->to]);

				if( p->cap > p->flow && dis < d[p->to] )

					update(p->to, d[p->to] = dis);

			}

		}

		return !(d[t] == inf);

	}

	bool vis[MAXV + 5];

	int aug(int x, int tot) {

		if( x == t ) return tot;

		int sum = 0; vis[x] = true;

		for(edge *&p=cur[x];p;p=p->nxt) {

			ll dis = d[x] + p->cost + (h[x] - h[p->to]);

			if( !vis[p->to] && p->cap > p->flow && dis == d[p->to] ) {

				int del = aug(p->to, min(tot - sum, p->cap - p->flow));

				p->flow += del, p->rev->flow -= del, sum += del;

				if( sum == tot ) break;

			}

		}

		vis[x] = false;

		return sum;

	}

	ll min_cost_max_flow(int _s, int _t) {

		s = _s, t = _t; ll cost = 0;

		while( relabel() ) {

			int del = aug(s, INF);

			cost += del*(d[t] + h[t]);

		}

		return cost;

	}

}G;



int main() {

	int N; scanf("%d", &N);

	int s = 2*N + 4 + 1, t = 2*N + 4 + 2;

	for(int i=1;i<=N;i++) {

		int X, Y, C; scanf("%d%d%d", &X, &Y, &C);

		G.addedge(s, i, C, 0);

		G.addedge(i, 2*N + 1, INF, + X + Y);

		G.addedge(i, 2*N + 2, INF, - X + Y);

		G.addedge(i, 2*N + 3, INF, + X - Y);

		G.addedge(i, 2*N + 4, INF, - X - Y);

	}

	for(int i=N+1;i<=2*N;i++) {

		int X, Y, C; scanf("%d%d%d", &X, &Y, &C);

		G.addedge(i, t, C, 0);

		G.addedge(2*N + 1, i, INF, - X - Y);

		G.addedge(2*N + 2, i, INF, + X - Y);

		G.addedge(2*N + 3, i, INF, - X + Y);

		G.addedge(2*N + 4, i, INF, + X + Y);

	}

	printf("%lld\n", -G.min_cost_max_flow(s, t));

}