#include<cstdio>
#include<cstring>
using namespace std;
#define fo(i,a,b) for(i=a;i<=b;i++)
#define ll long long
struct op{
	int go,ne,use;
	ll va;
};
const int N=1005;
int i,j,n,s,t,fa,fb,fc,fd,x,y,z,so,zja;
ll ans,ch;
int h[N*4],fr[N*4],dl[N*100],mp[N*4],f[N*4];
bool bz[N*4];
op lk[N*300];
int read()
{
	int x=0;char s=getchar();
	while ((s<'0')||(s>'9')) s=getchar();
	while ((s>='0')&&(s<='9')) x=x*10+(s-'0'),s=getchar();
	return x;
}
int min(int x,int y)
{
	if (x<y) return x;
	return y;
}
void ad(int x,int y,int us,int va)
{
	so++;lk[so].go=y;lk[so].ne=h[x];
	h[x]=so;lk[so].use=us;lk[so].va=va;
	so++;lk[so].go=x;lk[so].ne=h[y];
	h[y]=so;lk[so].use=0;lk[so].va=0-va;
}
bool bfs(int x)
{
	fo(i,1,fd) f[i]=-2000000000,fr[i]=0;
	mp[x]=10000;
	f[x]=0;int l,r,i;l=r=1;dl[l]=x;
	while (l<=r)
	{
		i=h[dl[l]];
		while (i)
		{
			if ((lk[i].use)&&(f[dl[l]]+lk[i].va>f[lk[i].go]))
			{
				f[lk[i].go]=lk[i].va+f[dl[l]];fr[lk[i].go]=i;
				mp[lk[i].go]=min(mp[dl[l]],lk[i].use);
				if (!bz[lk[i].go]){bz[lk[i].go]=true;r++;dl[r]=lk[i].go;}
			}
			i=lk[i].ne;
		}
		bz[dl[l]]=false;
		l++;
	}
	if (fr[t]) return true;
	return false;
}
int main()
{
	n=read();so=1;
	s=n*2+1;t=s+1;fa=t+1;fb=fa+1;fc=fb+1;fd=fc+1;
	fo(i,1,n)
	{
		x=read();y=read();z=read();
		ad(s,i,z,0);
		ad(i,fa,z,x+y);
		ad(i,fb,z,x-y);
		ad(i,fc,z,y-x);
		ad(i,fd,z,-x-y);
	}
	fo(i,n+1,n*2)
	{
		x=read();y=read();z=read();
		ad(i,t,z,0);
		ad(fa,i,z,-x-y);
		ad(fb,i,z,y-x);
		ad(fc,i,z,x-y);
		ad(fd,i,z,x+y);
	}
	while (bfs(s))
	{
		i=t;ch=mp[t];ans+=ch*f[t];
		while (i!=s)
		{
			lk[fr[i]].use-=mp[t];
			zja=fr[i]^1;
			lk[zja].use+=mp[t];
			i=lk[zja].go;
		}
	}
	printf("%lld\n",ans);
}
