// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<iostream>



#define nn 2110

#define ll long long

using namespace std;



ll as,d[nn];

struct Edge{int to,old,w,c;}e[nn*10];

int tot,n,fm[nn],q[nn*100],S,T,l[nn],v[nn];



inline void Lnk(int x,int y,int w,int c){

    e[++tot].to=y,e[tot].old=l[x],l[x]=tot,e[tot].w=w,e[tot].c=c;

    e[++tot].to=x,e[tot].old=l[y],l[y]=tot,e[tot].w=-w,e[tot].c=0;

}

inline int Spfa(){

    //memset(d,-1,8*(T+1));

    for (int i=1;i<=T;i++) d[i]=-1e18;

    memset(v,0,4*(T+1));

    memset(fm,0,4*(T+1));

    int h=1,t=1;

    q[1]=S,d[S]=0,v[S]=1;

    while (h<=t){

        int nw=q[h];

        for (int i=l[nw];i;i=e[i].old)if(d[e[i].to]<d[nw]+e[i].w&&e[i].c){

            fm[e[i].to]=i;

            d[e[i].to]=d[nw]+e[i].w;

            if (!v[e[i].to]) q[++t]=e[i].to,v[e[i].to]=1;

        }

        h++,v[nw]=0;

    }

    return(fm[T]);

}

int flow=0;

inline ll Get(){

    int a=110;ll rs=0;

    for (int i=T;i!=S;i=e[fm[i]^1].to) 

        a=min(a,e[fm[i]].c);

    for (int i=T;i!=S;i=e[fm[i]^1].to)

        rs+=a*1ll*e[fm[i]].w,e[fm[i]].c-=a,e[fm[i]^1].c+=a;

    flow+=a;

    return(rs);

}



int main()

{

    scanf("%d",&n);

    S=n*2+6,T=n*2+7,tot=1;

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

        int x,y,z;scanf("%d%d%d",&x,&y,&z);

        Lnk(S,i,0,z);

        Lnk(i,n*2+1,x+y,z);

        Lnk(i,n*2+2,x-y,z);

        Lnk(i,n*2+3,-x+y,z);

        Lnk(i,n*2+4,-x-y,z);

    }

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

        int x,y,z;scanf("%d%d%d",&x,&y,&z);

        Lnk(i+n,T,0,z);

        Lnk(n*2+1,i+n,-x-y,z);

        Lnk(n*2+2,i+n,-x+y,z);

        Lnk(n*2+3,i+n,x-y,z);

        Lnk(n*2+4,i+n,x+y,z);

    }



    while (Spfa())

        as+=Get();

    printf("%lld\n",as);

}

// Optimized solution to the same problem (faster):
#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));

}

// Fastest known solution for this problem: