#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
struct edge{
    int to, cap, rev; ll cost;
    edge(int to, int cap, ll cost, int rev):to(to), cap(cap), cost(cost), rev(rev){}
};

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

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

ll min_cost_flow(int s, int t, int f){
    using P=pair<ll, int>;
    const ll INF=1e18;
    ll res=0;
    fill(h, h+V, 0);
    while(f>0){
        priority_queue<P, vector<P>, greater<P>> que;
        fill(dist, dist+V, INF);
        dist[s]=0;
        que.push({0, s});
        while(!que.empty()){
            P p=que.top(); que.pop();
            int v=p.second;
            if(dist[v]<p.first) continue;
            for(int i=0; i<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({dist[e.to], e.to});
                }
            }
        }
        for(int v=0; v<V; v++) h[v]+=dist[v];
        if(dist[t]==INF) return -1;
        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 main()
{
	int n;
    cin>>n;
    ll rx[1010], ry[1010]; int rc[1010];
    ll bx[1010], by[1010]; int bc[1010];
    int f=0;
    vector<ll> vx, vy;
    for(int i=0; i<n; i++){
        cin>>rx[i]>>ry[i]>>rc[i];
        f+=rc[i];
        ll x1=rx[i]+ry[i], y1=rx[i]-ry[i];
        rx[i]=x1, ry[i]=y1;
        vx.push_back(x1), vy.push_back(y1);
    }
    for(int i=0; i<n; i++){
        cin>>bx[i]>>by[i]>>bc[i];
        ll x1=bx[i]+by[i], y1=bx[i]-by[i];
        bx[i]=x1, by[i]=y1;
        vx.push_back(x1), vy.push_back(y1);
    }
    sort(vx.begin(), vx.end());
    vx.erase(unique(vx.begin(), vx.end()), vx.end());
    sort(vy.begin(), vy.end());
    vy.erase(unique(vy.begin(), vy.end()), vy.end());
    int mx=vx.size(), my=vy.size();
    V=2*n+2*mx+2*my+2;
    int s=V-1, t=V-2;
    const int INF=1e5;
    for(int i=0; i<n; i++){
        add_edge(s, i, rc[i], 0);
        add_edge(i+n, t, bc[i], 0);
        int k=lower_bound(vx.begin(), vx.end(), rx[i])-vx.begin();
        add_edge(i, 2*n+k, INF, 0);
        add_edge(i, 2*n+mx+k, INF, 0);
        k=lower_bound(vy.begin(), vy.end(), ry[i])-vy.begin();
        add_edge(i, 2*n+2*mx+k, INF, 0);
        add_edge(i, 2*n+2*mx+my+k, INF, 0);
        k=lower_bound(vx.begin(), vx.end(), bx[i])-vx.begin();
        add_edge(2*n+k, i+n, INF, 0);
        add_edge(2*n+mx+k, i+n, INF, 0);
        k=lower_bound(vy.begin(), vy.end(), by[i])-vy.begin();
        add_edge(2*n+2*mx+k, i+n, INF, 0);
        add_edge(2*n+2*mx+my+k, i+n, INF, 0);
    }
    for(int i=0; i<mx-1; i++){
        add_edge(2*n+i, 2*n+i+1, INF, -vx[i+1]+vx[i]);
        add_edge(2*n+mx+i+1, 2*n+mx+i, INF, -vx[i+1]+vx[i]);
    }
    for(int i=0; i<my-1; i++){
        add_edge(2*n+2*mx+i, 2*n+2*mx+i+1, INF, -vy[i+1]+vy[i]);
        add_edge(2*n+2*mx+my+i+1, 2*n+2*mx+my+i, INF, -vy[i+1]+vy[i]);
    }
    cout<<-min_cost_flow(s, t, f)<<endl;
    return 0;
}


Measured memory_bytes: 2504