#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>

using namespace std;

#define int long long

const int INF = 1e18;
const int N = 20111;
const int B = 2e9;
int S;

int n, s;
int rx[N], ry[N], rc[N];
int bx[N], by[N], bc[N];

vector<int> graph[N];
int u[N], c[N], cost[N], f[N];
int cnt;

int ans;

int d[N], w[N], fr[N];

void Add(int v0, int u0, int c0, int cost0)
{
    cost0 += B;
    graph[v0].push_back(cnt);
    u[cnt] = u0;
    c[cnt] = c0;
    cost[cnt++] = cost0;
    graph[u0].push_back(cnt);
    u[cnt] = v0;
    c[cnt] = 0;
    cost[cnt++] = -cost0;
}

int Flow()
{
    fill(d, d + S + 1, INF);
    d[0] = 0;
    fill(w, w + S + 1, 3);
    w[0] = 1;
    fr[0] = -1;
    queue<int> q1, q2;
    q1.push(0);
    while (q1.size() + q2.size())
    {
        int v;
        if (q1.size())
        {
            v = q1.front();
            q1.pop();
        }
        else
        {
            v = q2.front();
            q2.pop();
        }
        for (int i = 0; i < graph[v].size(); i++)
        {
            int id = graph[v][i];
            if (f[id] == c[id])
            {
                continue;
            }
            int TO = u[id];
            if (w[TO] == 3)
            {
                w[TO] = 2;
                q2.push(TO);
                if (d[TO] > d[v] + cost[id])
                {
                    d[TO] = d[v] + cost[id];
                    fr[TO] = id;
                }
            }
            else if (w[TO] == 0)
            {
                if (d[TO] > d[v] + cost[id])
                {
                    w[TO] = 1;
                    q1.push(TO);
                    d[TO] = d[v] + cost[id];
                    fr[TO] = id;
                }
            }
            else
            {
                if (d[TO] > d[v] + cost[id])
                {
                    d[TO] = d[v] + cost[id];
                    fr[TO] = id;
                }
            }
        }
        w[v] = 0;
    }
    if (d[S] == INF)
    {
        return 0;
    }
    int Push = INF;
    int en = S;
    int Cost = 0;
    while (en != 0)
    {
        int idforward = fr[en];
        int idbackward = idforward ^ 1;
        Push = min(Push, c[idforward] - f[idforward]);
        Cost += cost[idforward];
        en = u[idbackward];
    }
    en = S;
    ans += Cost * Push;
    while (en != 0)
    {
        int idforward = fr[en];
        int idbackward = idforward ^ 1;
        f[idforward] += Push;
        f[idbackward] -= Push;
        en = u[idbackward];
    }
    return Push;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> rx[i] >> ry[i] >> rc[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> bx[i] >> by[i] >> bc[i];
        s += bc[i];
    }
    for (int i = 0; i < n; i++)
    {
        Add(0, i + 1, rc[i], 0);
        Add(i + 1, n + 1, B, rx[i] + ry[i]);
        Add(i + 1, n + 2, B, rx[i] - ry[i]);
        Add(i + 1, n + 3, B, - rx[i] + ry[i]);
        Add(i + 1, n + 4, B, - rx[i] - ry[i]);
        Add(n + 1, n + 5 + i, B, - bx[i] - by[i]);
        Add(n + 2, n + 5 + i, B, - bx[i] + by[i]);
        Add(n + 3, n + 5 + i, B, bx[i] - by[i]);
        Add(n + 4, n + 5 + i, B, bx[i] + by[i]);
        Add(n + 5 + i, 2 * n + 5, bc[i], 0);
    }
    S = 2 * n + 5;
    while (Flow()) ;
    cout << 4 * B * s - ans;
}


Measured memory_bytes: 1792