#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define int ll

typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

#define MAX_V 2010

struct edge{
  int to,cap,cost,rev;
};

int V;
vector<edge> g[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void init(int v){
  V=v;
  for(int i=0;i<MAX_V;i++){
    g[i].clear();
  }
}

void add_edge(int from,int to,int cap,int cost){
  g[from].push_back((edge){to,cap,cost,(int)g[to].size()});
  g[to].push_back((edge){from,0,-cost,(int)g[from].size()-1});

  //printf(" %lld -> %lld : %lld \n", from,to,cost);
}

int min_cost_flow(int s,int t,int f){
  int res=0;
  memset(h,0,sizeof(h));
  while(f>0){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(P(0,s));
    while(que.size()){
      P p=que.top(); que.pop();
      int v=p.second;
      if(dist[v]<p.first)continue;
      for(int i=0;i<(int)g[v].size();i++){
        edge e=g[v][i];
        if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
          dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
          prevv[e.to]=v;
          preve[e.to]=i;
          que.push(P(dist[e.to],e.to));
        }
      }
    }
    if(dist[t]==INF)return -1;
    for(int v=0;v<V;v++) h[v]+=dist[v];

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,g[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=g[prevv[v]][preve[v]];
      e.cap-=d;
      g[v][e.rev].cap+=d;
    }
  }
  return res;
}

int sgnx[]={+1,-1,-1,+1};
int sgny[]={+1,+1,-1,-1};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin>>N;

  init(2*N+4+2);
  int typv=2*N;
  int source=2*N+4,sink=2*N+5;
  int sum=0;

  rep(i,N){
    int x,y,c;
    cin>>x>>y>>c;
    sum+=c;
    add_edge(source,i,c,0);

    rep(j,4){
      add_edge(i,typv+j,INF,-(sgnx[j]*x+sgny[j]*y));
    }
  }

  rep(i,N){
    int x,y,c;
    cin>>x>>y>>c;
    add_edge(i+N,sink,c,0);

    rep(j,4){
      int nj=(j+2)%4;
      add_edge(typv+j,i+N,INF,-(sgnx[nj]*x+sgny[nj]*y));
    }
  }

  cout<<-min_cost_flow(source,sink,sum)<<endl;

  return 0;
}
