// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int N = 3010;



typedef long long LL;



struct edge {

    int to, next, w, c;

} e[N * 10];



int head[N], ecnt = 1;



inline void adde(int from, int to, int w, int c) {

    e[++ecnt] = (edge){to, head[from], w, -c}, head[from] = ecnt;

    e[++ecnt] = (edge){from, head[to], 0, c}, head[to] = ecnt;

}



int vis[N], cur[N]; LL dis[N];



inline bool SPFA(int s, int t) {

    memset(dis, 0x3f, sizeof(dis)), memset(vis, 0, sizeof(vis));

    queue<int> q; q.push(t), vis[t] = 1, dis[t] = 0;

    while (!q.empty()) {

        int u = q.front(); q.pop(), vis[u] = 0;

        for (int i = head[u]; i; i = e[i].next)

            if (e[i ^ 1].w && dis[e[i].to] > dis[u] - e[i].c) {

                dis[e[i].to] = dis[u] - e[i].c;

                if (!vis[e[i].to]) q.push(e[i].to), vis[e[i].to] = 1;

            }

    }

    return dis[s] < 1e17;

}



LL ans;



int DFS(int u, int t, int f) {

    if (u == t || !f) return f;

    int res = 0; vis[u] = 1;

    for (int &i = cur[u], tmp; i; i = e[i].next)

        if (!vis[e[i].to] && e[i].w && dis[u] - e[i].c == dis[e[i].to] && 

            (tmp = DFS(e[i].to, t, min(f, e[i].w)))) {

                res += tmp, f -= tmp, e[i].w -= tmp, e[i ^ 1].w += tmp, ans += (LL)tmp * e[i].c;

                if (!f) break;

            }

    return res;

}



inline LL dinic(int s, int t) {

    while (SPFA(s, t)) memcpy(cur, head, sizeof(head)), DFS(s, t, 1e9);

    return ans;

}



int main() {

    int n, s, t; scanf("%d", &n), s = n * 2 + 5, t = s + 1;

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

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

        adde(s, i, c, 0);

        adde(i, 2 * n + 1, 1e9, -x - y), adde(i, 2 * n + 2, 1e9, x + y);

        adde(i, 2 * n + 3, 1e9, y - x), adde(i, 2 * n + 4, 1e9, x - y);

    }

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

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

        adde(i + n, t, c, 0);

        adde(2 * n + 1, i + n, 1e9, x + y), adde(2 * n + 2, i + n, 1e9, -x - y);

        adde(2 * n + 3, i + n, 1e9, x - y), adde(2 * n + 4, i + n, 1e9, y - x);

    }

    printf("%lld\n", -dinic(s, t));

    return 0;

}//

// Faster C++ solution for the same problem (measured speedup: 5.034326060532428x):
#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;

}