// Slower C++ solution:
#include <cstdio>

#include <iostream>

#include <queue>

#include <cstring>

using namespace std;

typedef long long ll;

const int maxn = 2000,maxm = 20005;

const ll inf = 1e11;



struct Edge{

    Edge() {}

    Edge(int a,int b,ll c,int d){v = a;f = b;w = c;nxt = d;}

    int v,f,w,nxt;

};



int n,lmt;

int g[maxn + 10];

Edge e[maxm + 10];

int nume = 1;

int src,sink;



void addedge(int u,int v,int c,ll w){

    e[++nume] = Edge(v,c,w,g[u]);

    g[u] = nume;

    e[++nume] = Edge(u,0,-w,g[v]);

    g[v] = nume;

}



queue<int> que;

bool inq[maxn + 10];

ll dist[maxn + 10];

int prv[maxn + 10],pree[maxn + 10];



bool findpath(){

    while(!que.empty()) que.pop();

    que.push(src);

    memset(dist,63,sizeof dist);

    //for(int i = 0;i < maxn; ++i) dist[i] = inf;

    dist[src] = 0;

    inq[src] = true;

    while(!que.empty()){

        int u = que.front();que.pop();

        for(int i = g[u];i;i = e[i].nxt){

            if(e[i].f > 0 && dist[u] + e[i].w < dist[e[i].v]){

                dist[e[i].v] = dist[u] + e[i].w;

                prv[e[i].v] = u;

                pree[e[i].v] = i;

                if(!inq[e[i].v]){

                    inq[e[i].v] = true;

                    que.push(e[i].v);

                }

            }

        }

        inq[u] = false;

    }

    if(dist[sink] < inf) return true;

    else return false;

}



ll augment(){

    int u = sink;

    ll delta = inf;

    while(u != src){

        if(e[pree[u]].f < delta) delta = e[pree[u]].f;

        u = prv[u];

    }

    u = sink;

    while(u != src){

        e[pree[u]].f -= delta;

        e[pree[u] ^ 1].f += delta;

        u = prv[u];

    }

    return dist[sink] * delta;

}



ll mincostflow(){

    ll cur = 0,ans = 0;

    while(findpath()){

        cur += augment();

        if(cur < ans) ans = cur;

    }

    return ans;

}



int main(){

    scanf("%d",&n);

    src = 2 * n + 1,sink = 2 * n + 2;

    for(int i = 1;i <= n; ++i){

        int x,y,c;scanf("%d%d%d",&x,&y,&c);

        addedge(2 * n + 1,i,c,0);

        addedge(i,2 * n + 3,c,x + y);

        addedge(i,2 * n + 4,c,x - y);

        addedge(i,2 * n + 5,c,-x + y);

        addedge(i,2 * n + 6,c,-x - y);

    }

    for(int i = 1;i <= n; ++i){

        int x,y,c;scanf("%d%d%d",&x,&y,&c);

        addedge(n + i,2 * n + 2,c,0);

        addedge(2 * n + 3,n + i,c,-x - y);

        addedge(2 * n + 4,n + i,c,-x + y);

        addedge(2 * n + 5,n + i,c,x - y);

        addedge(2 * n + 6,n + i,c,x + y);

    }



    ll res = mincostflow();

    printf("%lld",-res);

    return 0;

}






// Faster C++ solution for the same problem (measured speedup: 4.180583511220299x):
#include <cstdio>

#include <cstring>



#define N 1001

#define V 2020

#define E 20386

#define F 0x7fffffff



#define MIN(A, B) ((A) < (B) ? (A) : (B))



struct edge {

    int u, v;

    long long w;

    int c, x;

} e[E];



const long long y[2][4] = {{-1, 1, -1, 1}, {-1, -1, 1, 1}};



long long p[2][2][N], d[V];

int h[V], m[2][N], f[V], q[V], l, t, z, n, g;

bool v[V];



inline void adde(int u, int v, long long w, int c) {

    e[z] = edge{u, v, -w, c, h[u]}; h[u] = z++;

    e[z] = edge{v, u, w, 0, h[v]}; h[v] = z++;

}



inline void push(int x) {

    q[t++] = x;

    if (t == V) t = 0;

}



inline int pop() {

    int x = q[l++];

    if (l == V) l = 0;

    return x;

}



bool spfa() {

    memset(d, 0x3f, sizeof d);

    d[0] = 0; push(0); v[0] = true;



    while (l != t) {

        int x = pop();

        v[x] = false;



        for (int i = h[x]; ~i; i = e[i].x) {

            if (e[i].c && d[e[i].v] > d[x] + e[i].w) {

                d[e[i].v] = d[x] + e[i].w; f[e[i].v] = i;

                if (!v[e[i].v]) { push(e[i].v); v[e[i].v] = true; }

            }

        }

    }



    return d[g] != 0x3f3f3f3f3f3f3f3fLL;

}



long long solve() {

    long long c = 0;



    while (spfa()) {

        int w = F;

        for (int u = g; u; u = e[f[u]].u) w = MIN(w, e[f[u]].c);



        for (int u = g; u; u = e[f[u]].u) {

            c += e[f[u]].w * w; e[f[u]].c -= w; e[f[u] ^ 1].c += w;

        }

    }



    return -c;

}



int main() {

    memset(h, -1, sizeof h);

    scanf("%d", &n); g = (n << 1) + 9;

    for (int i = 1; i <= 4; i++) adde((n << 1) + i, (n << 1) + i + 4, 0, F);



    for (int s = 0; s <= 1; s++)

        for (int i = 1; i <= n; i++)

            scanf("%lld%lld%d", &p[s][0][i], &p[s][1][i], &m[s][i]);



    for (int i = 1; i <= n; i++) {

        adde(0, i, 0, m[0][i]); adde(n + i, g, 0, m[1][i]);



        for (int j = 0; j < 4; j++) {

            adde(i, (n << 1) + j + 1, p[0][0][i] * y[0][j] + p[0][1][i] * y[1][j], F);

            adde((n << 1) + 8 - j, n + i, p[1][0][i] * y[0][j] + p[1][1][i] * y[1][j], F);

        }

    }



    printf("%lld\n", solve()); return 0;

}