#include<bits/stdc++.h>
using namespace std;
void *wmem;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
template <class T> struct LHeap{
  T *val;
  int *hp, *place, size;
  void malloc(int N){
    hp = (int*)std::malloc(N*sizeof(int));
    place=(int*)std::malloc(N*sizeof(int));
    val=(T*)std::malloc(N*sizeof(T));
  }
  void walloc(int N, void **mem=&wmem){
    hp = (int*)(*mem);
    place = hp+N;
    val = (T*)(place+N);
    *mem = val+N;
  }
  void free(){
    std::free(hp);
    std::free(place);
    std::free(val);
  }
  void init(int N){
    int i;
    size=0;
    for(i=0;i<N;i++){
      place[i]=-1;
    }
  }
  void up(int n){
    int m;
    while(n){
      m=(n-1)/2;
      if(val[hp[m]]<=val[hp[n]]){
        break;
      }
      swap(hp[m],hp[n]);
      swap(place[hp[m]],place[hp[n]]);
      n=m;
    }
  }
  void down(int n){
    int m;
    for(;;){
      m=2*n+1;
      if(m>=size){
        break;
      }
      if(m+1<size&&val[hp[m]]>val[hp[m+1]]){
        m++;
      }
      if(val[hp[m]]>=val[hp[n]]){
        break;
      }
      swap(hp[m],hp[n]);
      swap(place[hp[m]],place[hp[n]]);
      n=m;
    }
  }
  void change(int n, T v){
    T f=val[n];
    val[n] = v;
    if(place[n]==-1){
      place[n] = size;
      hp[size++] = n;
      up(place[n]);
    }
    else{
      if(f < v){
        down(place[n]);
      }
      else if(f > v){
        up(place[n]);
      }
    }
  }
  int pop(void){
    int res=hp[0];
    place[res] = -1;
    size--;
    if(size){
      hp[0]=hp[size];
      place[hp[0]]=0;
      down(0);
    }
    return res;
  }
}
;
template<class FT, class CT> struct minCostFlow{
  CT **cost, *cur_cost;
  FT *cur_flow, eps, **flow;
  LHeap<CT> hp;
  char *reached;
  int *back_edge, **edge, *emem, *es, node, **rev;
  void malloc(int N){
    int i;
    es = (int*)std::malloc(N*sizeof(int));
    emem = (int*)std::malloc(N*sizeof(int));
    edge = (int**)std::malloc(N*sizeof(int*));
    rev = (int**)std::malloc(N*sizeof(int*));
    flow = (FT**)std::malloc(N*sizeof(FT*));
    cost = (CT**)std::malloc(N*sizeof(CT*));
    for(i=0;i<N;i++){
      emem[i] = 0;
      edge[i] = rev[i] = NULL;
      flow[i] = NULL;
      cost[i] = NULL;
    }
    hp.malloc(N);
    reached = (char*)std::malloc(N*sizeof(char));
    cur_flow = (FT*)std::malloc(N*sizeof(FT));
    cur_cost = (CT*)std::malloc(N*sizeof(CT));
    back_edge = (int*)std::malloc(N*sizeof(int));
    node = N;
    for(i=0;i<N;i++){
      es[i] = 0;
    }
    eps = (FT)1e-9;
  }
  void init(int N){
    int i;
    node = N;
    for(i=0;i<N;i++){
      es[i] = 0;
    }
    eps = (FT)1e-9;
  }
  void memoryExpand(int i, int sz){
    if(sz <= emem[i]){
      return;
    }
    sz =max_L(max_L(sz, 3), 2*emem[i]);
    emem[i] = sz;
    edge[i] = (int*)realloc(edge[i], sz*sizeof(int));
    rev[i] = (int*)realloc(rev[i], sz*sizeof(int));
    flow[i] = (FT*)realloc(flow[i], sz*sizeof(FT));
    cost[i] = (CT*)realloc(cost[i], sz*sizeof(CT));
  }
  void addEdge(int n1, int n2, FT f, CT c){
    int s1=es[n1]++, s2=es[n2]++;
    if(s1 >= emem[n1]){
      memoryExpand(n1, es[n1]);
    }
    if(s2 >= emem[n2]){
      memoryExpand(n2, es[n2]);
    }
    edge[n1][s1] = n2;
    edge[n2][s2] = n1;
    rev[n1][s1]  = s2;
    rev[n2][s2]  = s1;
    flow[n1][s1] = f;
    flow[n2][s2] = 0;
    cost[n1][s1] = c;
    cost[n2][s2] = -c;
  }
  template<class FTS, class CTS> void solve(int st, int ed, FTS &fres, CTS &cres, FT flim = -1){
    FT f;
    int i, j, k;
    fres = 0;
    cres = 0;
    for(;;){
      hp.init(node);
      for(i=0;i<node;i++){
        reached[i] = 0;
      }
      reached[st] = 1;
      cur_cost[st] = 0;
      hp.change(st, cur_cost[st]);
      while(hp.size){
        i = hp.pop();
        for(j=0;j<es[i];j++){
          if(flow[i][j] <= eps){
            continue;
          }
          k = edge[i][j];
          if(reached[k]==0 || cur_cost[k] > cur_cost[i]+cost[i][j]+eps){
            reached[k] = 1;
            cur_cost[k] = cur_cost[i] + cost[i][j];
            cur_flow[k] = flow[i][j];
            if(i!=st){
              chmin(cur_flow[k], cur_flow[i]);
            }
            back_edge[k] = rev[i][j];
            hp.change(k, cur_cost[k]);
          }
        }
      }
      if(reached[ed]==0){
        break;
      }
      if(flim==-2 && cur_cost[ed] < 0){
        break;
      }
      f = cur_flow[ed];
      if(flim != -1 && flim != -2){
        chmin(f, flim);
      }
      if(f < eps){
        break;
      }
      fres += f;
      cres += f * cur_cost[ed];
      i = ed;
      while(i != st){
        j = back_edge[i];
        k = edge[i][j];
        flow[i][j] += f;
        flow[k][rev[i][j]] -= f;
        i = k;
      }
    }
  }
}
;
char memarr[96000000];
int N;
int RC[1000];
int BC[1000];
long long RX[1000];
long long RY[1000];
long long BX[1000];
long long BY[1000];
int main(){
  int ed, flow, i, j, k, node, st;
  long long cost;
  minCostFlow<int, long long> f;
  wmem = memarr;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(RX[Lj4PdHRW]);
      rd(RY[Lj4PdHRW]);
      rd(RC[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY;
    for(KL2GvlyY=0;KL2GvlyY<N;KL2GvlyY++){
      rd(BX[KL2GvlyY]);
      rd(BY[KL2GvlyY]);
      rd(BC[KL2GvlyY]);
    }
  }
  node = 2*N+4;
  st = node++;
  ed = node++;
  f.malloc(node);
  for(i=0;i<N;i++){
    f.addEdge(st, i, RC[i], 0);
    f.addEdge(N+i, ed, BC[i], 0);
    f.addEdge(i, 2*N+0, RC[i], 2000000000-RX[i]-RY[i]);
    f.addEdge(i, 2*N+1, RC[i], 2000000000-RX[i]+RY[i]);
    f.addEdge(i, 2*N+2, RC[i], 2000000000+RX[i]-RY[i]);
    f.addEdge(i, 2*N+3, RC[i], 2000000000+RX[i]+RY[i]);
    f.addEdge(2*N+0, N+i, BC[i], 2000000000+BX[i]+BY[i]);
    f.addEdge(2*N+1, N+i, BC[i], 2000000000+BX[i]-BY[i]);
    f.addEdge(2*N+2, N+i, BC[i], 2000000000-BX[i]+BY[i]);
    f.addEdge(2*N+3, N+i, BC[i], 2000000000-BX[i]-BY[i]);
  }
  f.solve(st,ed,flow,cost);
  cost = (long long)4000000000LL * flow - cost;
  wt_L(cost);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190608-1

// --- original code ---
// int N, RC[1000], BC[1000];
// ll RX[1000], RY[1000], BX[1000], BY[1000];
// {
//   int i, j, k;
//   int node, st, ed;
//   
//   minCostFlow<int, ll> f;
//   int flow; ll cost;
//   
//   rd(N,(RX,RY,RC)(N),(BX,BY,BC)(N));
// 
//   node = 2N+4;
//   st = node++;
//   ed = node++;
//   f.malloc(node);
// 
//   rep(i,N){
//     f.addEdge(st, i, RC[i], 0);
//     f.addEdge(N+i, ed, BC[i], 0);
//     f.addEdge(i, 2N+0, RC[i], 2d9-RX[i]-RY[i]);
//     f.addEdge(i, 2N+1, RC[i], 2d9-RX[i]+RY[i]);
//     f.addEdge(i, 2N+2, RC[i], 2d9+RX[i]-RY[i]);
//     f.addEdge(i, 2N+3, RC[i], 2d9+RX[i]+RY[i]);
//     f.addEdge(2N+0, N+i, BC[i], 2d9+BX[i]+BY[i]);
//     f.addEdge(2N+1, N+i, BC[i], 2d9+BX[i]-BY[i]);
//     f.addEdge(2N+2, N+i, BC[i], 2d9-BX[i]+BY[i]);
//     f.addEdge(2N+3, N+i, BC[i], 2d9-BX[i]-BY[i]);
//   }
// 
//   f.solve(st,ed,flow,cost);
//   cost = (ll)4d9 * flow - cost;
//   wt(cost);
// }


Measured memory_bytes: 1152