#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
long long n,m,i,j,s=0,t=2005,vis[2018],inq[2018],x,y,c,cnt;
long long cst,dis[2018];
struct ii
{
	long long y,z,d;
}e[1000005];
vector<long long> bi[2018];
void add(long long x,long long y,long long z,long long d)
{
	cnt++;
	bi[x].push_back(cnt+cnt-2);
	bi[y].push_back(cnt+cnt-1);
	e[cnt+cnt-2]=(ii){y,z,d};
	e[cnt+cnt-1]=(ii){x,0,-d}; 
}
bool bfs(long long s,long long t)
{
	queue<long long> qx;
	qx.push(s);
	memset(dis,0x3f,sizeof(dis));
	dis[s]=0;qx.push(s);
	while(!qx.empty()){
		long long x=qx.front();qx.pop();inq[x]=0;
		ff(bi[x],it){
			if(e[*it].z){
				long long y=e[*it].y,z=e[*it].d+dis[x];
				if(dis[y]>z){
					dis[y]=z;
					if(!inq[y]){
						inq[y]=1;
						qx.push(y);
					}
				}
			}
		}
	}
	return dis[t]<dis[t+1];
}
long long dfs(long long x,long long tt,long long flw)
{
	if(!flw)return 0;
	if(x==tt){
		vis[x]=1;
		return flw;
	}
	if(vis[x])return 0;
	vis[x]=1;
	long long ans=0;
	ff(bi[x],it){
		if(dis[x]+e[*it].d==dis[e[*it].y]&&e[*it].z){
			long long t=dfs(e[*it].y,tt,min(flw,e[*it].z));
			ans+=t;flw-=t;e[*it].z-=t;e[(*it)^1].z+=t;
			cst+=e[*it].d*t;
		}
		if(!flw)break;
	}
	return ans;
}
void dinic(long long s,long long t)
{
	while(bfs(s,t)){
		do{
			memset(vis,0,sizeof(vis));
			dfs(s,t,0x3f3f3f3f);
		}while(vis[t]);
	}
}
int main()
{
	scanf("%lld",&n);
	fz1(i,n){
		scanf("%lld%lld%lld",&x,&y,&c);
		add(s,i,c,0);
		add(i,2001,0x3f3f3f3f,x+y);
		add(i,2002,0x3f3f3f3f,-x+y);
		add(i,2003,0x3f3f3f3f,x-y);
		add(i,2004,0x3f3f3f3f,-x-y);
	}
	fz1(i,n){
		scanf("%lld%lld%lld",&x,&y,&c);
		add(i+n,t,c,0);
		add(2001,i+n,0x3f3f3f3f,-x-y);
		add(2002,i+n,0x3f3f3f3f,x-y);
		add(2003,i+n,0x3f3f3f3f,-x+y);
		add(2004,i+n,0x3f3f3f3f,x+y);
	}
	dinic(s,t);
	cout<<-cst<<endl;
	return 0;
}