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

#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))

const int maxn = 1e5 + 20;
const int MOD = (int) 1e9 + 7;

const int N=(int) 3e3+20;
struct MCMF
{
    struct Edge
    {
        LL from,to,cap,flow,cost;
        Edge() {}
        Edge(LL _from,LL _to,LL _cap,LL _flow,LL _cost):
            from(_from),to(_to),cap(_cap),flow(_flow),cost(_cost) {}
    };
    int n,m,s,t;
    vector<Edge> edge;
    vector<int> G[N];
    bool inq[N];
    LL d[N],p[N],fc[N];

    void init(int _n,int _s,int _t)
    {
        n=_n; s=_s; t=_t; m=0;
        edge.clear();
        for(int i=0;i<=n;i++) G[i].clear();
    }

    void add_edge(int from,int to,int cap,int cost)
    {
        edge.push_back(Edge(from,to,cap,0,cost));
        edge.push_back(Edge(to,from,0,0,-cost));
        m+=2;
        G[from].push_back(m-2);
        G[to].push_back(m-1);
    }

    bool spfa(LL &flow,LL &cost)
    {
//        cout <<"stick" <<endl;
        for(int i=0;i<=n;i++) d[i]=0x3f3f3f3f3f3f3f3f;
        memset(inq,0,sizeof(inq));
        queue<int> Q;
        d[s]=0; inq[s]=1; p[s]=0; fc[s]=0x3f3f3f3f3f3f3f3f;
        Q.push(s);

        while(!Q.empty())
        {
            int x=Q.front(); Q.pop();
            inq[x]=0;
            for(int i=0;i<G[x].size();i++)
            {
                Edge &e=edge[G[x][i]];
                if(e.cap>e.flow && d[e.to]>d[x]+e.cost)
                {
                    d[e.to]=d[x]+e.cost;
                    p[e.to]=G[x][i];
                    fc[e.to]=min(fc[x],e.cap-e.flow);
                    if(!inq[e.to])
                    {
                        Q.push(e.to);
                        inq[e.to]=1;
                    }
                }
            }
        }
        if(d[t]==0x3f3f3f3f3f3f3f3f) return 0;
        flow+=fc[t];
        cost+=fc[t]*d[t];
        int x=t;
        while(x!=s)
        {
            edge[p[x]].flow+=fc[t];
            edge[p[x]^1].flow-=fc[t];
            x=edge[p[x]].from;
        }

        return 1;
    }

    LL Mincost()
    {
        LL flow=0, cost=0;
        while(spfa(flow,cost)) ;
        return cost;
    }
}mcf;



void work()
{
//    cout <<0x3f3f3f3f3f3f3f3f <<endl;
    int n;
    cin >>n;
    mcf.init(2 * n + 6, 2 * n + 5, 2 * n + 6);
    int S = 2 * n + 5, T = 2 * n + 6;
    int A = 2 * n + 1, B = 2 * n + 2, C = 2 * n + 3, D = 2 * n + 4;
    int inf = 1e9;
    for(int i = 1; i <= n; i++)
    {
        int x, y, c;
        cin >>x >>y >>c;

        mcf.add_edge(S, i, c, 0);
        mcf.add_edge(i, A, inf,  x + y);
        mcf.add_edge(i, B, inf, -x + y);
        mcf.add_edge(i, C, inf,  x - y);
        mcf.add_edge(i, D, inf, -x - y);
    }

    for(int i = 1; i <= n; i++)
    {
        int x, y, c;
        cin >>x >>y >>c;
        mcf.add_edge(i + n, T, c, 0);
        mcf.add_edge(A, i + n, inf, -x - y);
        mcf.add_edge(B, i + n, inf,  x - y);
        mcf.add_edge(C, i + n, inf, -x + y);
        mcf.add_edge(D, i + n, inf,  x + y);
    }

    cout <<-mcf.Mincost() <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
    int tc = 1;
//    cin >>tc;
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 1800