// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=2111;
const int maxm=100111;

struct mincost_flow
{
	struct edge{int to,cap,cost;};
	int head[maxn],nxt[maxm<<1],iter[maxn],tot=1;
	edge e[maxm<<1];
	void addedge(int u,int v,int cap,int cost)
	{
		nxt[++tot]=head[u];
		head[u]=tot;
		e[tot]=edge{v,cap,cost};
		nxt[++tot]=head[v];
		head[v]=tot;
		e[tot]=edge{u,0,-cost};
	}
	bool inq[maxn];int q[maxn],pre[maxn];
	LL dist[maxn];
	void spfa(int s)
	{
		memset(dist,63,sizeof(dist));
		dist[s]=0;int fr=0,rr=0;q[rr++]=s;
		while(fr!=rr)
		{
			int x=q[fr++];if(fr==maxn)fr=0;
			inq[x]=0;
			for(int i=head[x];i;i=nxt[i])if(e[i].cap&&dist[e[i].to]>dist[x]+e[i].cost)
			{
				dist[e[i].to]=dist[x]+e[i].cost;
				pre[e[i].to]=i;
				if(!inq[e[i].to])
				{
					inq[e[i].to]=1;
					if(fr==rr||dist[q[fr]]<=dist[e[i].to])
					{
						q[rr++]=e[i].to;
						if(rr==maxn)rr=0;
					}
					else
					{
						if(fr==0)fr=maxn;
						q[--fr]=e[i].to;
					}
				}
			}
		}
	}
	LL augment(int t,int s,int&f)
	{
		int d=f,cur;
		for(cur=t;cur!=s;cur=e[pre[cur]^1].to)d=min(d,e[pre[cur]].cap);
		f-=d;
		for(cur=t;cur!=s;cur=e[pre[cur]^1].to)
		{
			e[pre[cur]].cap-=d;
			e[pre[cur]^1].cap+=d;
		}
		return dist[t]*d;
	}
	LL mincostflow(int s,int t,int f)
	{
		LL ret=0;
		while(f)
		{
			spfa(s);
			ret+=augment(t,s,f);
		}
		return ret;
	}
}thor;

int n,rx[maxn],ry[maxn],bx[maxn],by[maxn],rc[maxn],bc[maxn];
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)get3(rx[i],ry[i],rc[i]);
	for(int i=1;i<=n;i++)get3(bx[i],by[i],bc[i]);
	
	int S=n+n+1,T=n+n+2,V0=T+1,V1=V0+1,V2=V1+1,V3=V2+1,sum=0;
	
	for(int i=1;i<=n;i++)
	{
		thor.addedge(S,i,rc[i],0);
		thor.addedge(i+n,T,bc[i],0);
		thor.addedge(i,V0,inf,rx[i]+ry[i]);
		thor.addedge(i,V1,inf,rx[i]-ry[i]);
		thor.addedge(i,V2,inf,-rx[i]+ry[i]);
		thor.addedge(i,V3,inf,-rx[i]-ry[i]);
		thor.addedge(V0,i+n,inf,-bx[i]-by[i]);
		thor.addedge(V1,i+n,inf,-bx[i]+by[i]);
		thor.addedge(V2,i+n,inf,bx[i]-by[i]);
		thor.addedge(V3,i+n,inf,bx[i]+by[i]);
		sum+=rc[i];
	}
	printf("%lld\n",-thor.mincostflow(S,T,sum));
	return 0;
}

Measured memory_bytes: 640