// Author -- Frame

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<iostream>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;
const double eps=1e-10;

template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline bool _cmp(const _Tp &a,const _Tp &b){return abs(a-b)<=eps;}
template <typename _Tp>Finline void read(_Tp &x)
{
	register char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	register char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	register char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=2015;
template<typename _Tp1,typename _Tp2>
class MCMF
{
public:
	struct edge{
		int v,nxt;
		_Tp1 w;
		_Tp2 cost;
	}c[N<<5];
	int front[N],edge_cnt;
	Finline void add(int u,int v,_Tp1 w,_Tp2 cost)
	{
		c[++edge_cnt]=(edge){v,front[u],w,cost};
		front[u]=edge_cnt;
		
		c[++edge_cnt]=(edge){u,front[v],0,-cost};
		front[v]=edge_cnt;
	}
	Finline MCMF()
	{
		memset(front,255,sizeof(front));
		edge_cnt=-1;
	}
	_Tp2 dep[N];
	int cur[N],S,T;
	bool inq[N];
	int _q[N*N],_l,_r;
	int node_cnt;
	Finline void init(int _node_cnt)
	{
		node_cnt=_node_cnt;
		memset(front,255,(_node_cnt)<<2);
		edge_cnt=-1;
	}
	bool bfs()
	{
		memset(dep,63,(node_cnt+2)*sizeof(_Tp2));
		memcpy(cur,front,(node_cnt+2)<<2);
		memset(inq,0,node_cnt+2);
		_q[_l=_r=1]=S;
		dep[S]=0;
		while(_l!=_r+1)
		{
			int x=_q[_l++];
			inq[x]=false;
			for(int i=front[x];~i;i=c[i].nxt)
			{
				if(c[i].w&&dep[c[i].v]>dep[x]+c[i].cost)
				{
					dep[c[i].v]=dep[x]+c[i].cost;
					if(!inq[c[i].v])
					{
						inq[c[i].v]=true;
						_q[++_r]=c[i].v;
					}
				}
			}
		}
		return dep[T]<1e15;
	}
	_Tp1 dfs(int x,int flow)
	{
		if(x==T||!flow) return flow;
		inq[x]=true;
		_Tp1 f=0,rf;
		for(int &i=cur[x];~i;i=c[i].nxt)
		{
			if(!inq[c[i].v]&&dep[c[i].v]==dep[x]+c[i].cost&&(rf=dfs(c[i].v,min(flow,c[i].w))))
			{
				flow-=rf,f+=rf;
				c[i].w-=rf,c[i^1].w+=rf;
				if(!flow) return f;
			}
		}
		return f;
	}
	std::pair<_Tp1,_Tp2> dinic()
	{
		_Tp1 ans=0;
		_Tp2 res=0;
		while(bfs())
		{
			_Tp1 tmp=dfs(S,inf);
			// inf changes when _Tp1 != int
			ans+=tmp;
			res+=dep[T]*tmp;
		}
		return std::make_pair(ans,res);
	}
};
MCMF<int,ll> F;
int main()
{
	int n;
	read(n);
	F.S=n+n+4+1;
	F.T=n+n+4+1+1;
	F.node_cnt=n+n+4+2;
	int x,y,c;
	for(int i=1;i<=n;++i)
	{
		read(x,y,c);
		F.add(F.S,i,c,0);
		F.add(i,n+n+1,inf,-(x+y));
		F.add(i,n+n+2,inf,-(x-y));
		F.add(i,n+n+3,inf,-(-x+y));
		F.add(i,n+n+4,inf,-(-x-y));
	}
	for(int i=1;i<=n;++i)
	{
		read(x,y,c);
		F.add(i+n,F.T,c,0);
		F.add(n+n+4,i+n,inf,-(x+y));
		F.add(n+n+3,i+n,inf,-(x-y));
		F.add(n+n+2,i+n,inf,-(-x+y));
		F.add(n+n+1,i+n,inf,-(-x-y));
	}
	printf("%lld\n",-F.dinic().second);
	return 0;
}


Measured memory_bytes: 896