#include <bits/stdc++.h>

using namespace std;


const int Nmax = 2019;
typedef long long ll;
const ll inf = 1e18;
typedef pair<ll,int> Pair;


class floow
{
    int cost[Nmax][Nmax], cap[Nmax][Nmax], f[Nmax][Nmax], t[Nmax];
    ll p[Nmax], dist[Nmax], new_p[Nmax];
    vector<int> v[Nmax];
    bool InQueue[Nmax];
    priority_queue< Pair, vector< Pair >, greater< Pair > > heap;

    bool dijkstra()
    {
        for(int i=1; i<=n; ++i) dist[i] = inf, t[i] = 0;
        dist[S] = 0;
        heap.push({dist[S], S});

        while(heap.size())
        {
            int node = heap.top().second, nr = heap.top().first;
            heap.pop();
            if(dist[node] != nr) continue;

            for(auto it : v[node])
                if(f[node][it] < cap[node][it])
                {
                    ll cc = dist[node] + cost[node][it] + p[node] - p[it];
                    if(dist[it] > cc)
                    {
                        t[it] = node;
                        dist[it] = cc;
                        heap.push({cc, it});

                        new_p[it] = new_p[node] + cost[node][it];
                    }
                }
        }

        for(int i=1; i<=n; ++i) p[i] = new_p[i];
        return dist[D] != inf;
    }

    public:
    int S, D, n;
    
    void prepare()
    {
        queue<int> q;
        q.push(S); p[S] = 0;

        while(q.size())
        {
            int node = q.front();
            q.pop();
            InQueue[node] = 0;

            for(auto it : v[node])
                if(f[node][it] < cap[node][it]  && p[it] > p[node] + cost[node][it])
                {
                    p[it] = p[node] + cost[node][it];
                    if(InQueue[it]) continue;
                    InQueue[it] = 1;
                    q.push(it);
                }
        }
    }

    ll max_flow_min_cost()
    {
        int node, dad;
        ll ans = 0;
        int fmin;
        
        while(dijkstra())
        {
            node = D;
            fmin = 2e9;
            while(node != S)
            {
                dad = t[node];
                fmin = min(fmin, cap[dad][node] - f[dad][node]);
                node = dad;
            }

            ans += fmin * p[D];

            node = D;
            while(node != S)
            {
                dad = t[node];
                f[dad][node] += fmin;
                f[node][dad] -= fmin;
                node = dad;
            }
        }
        return ans;
    }

    void add_edge(int x, int y, int Cap, int Cost)
    {
        v[x].push_back(y);
        v[y].push_back(x);
        cap[x][y] = Cap, cap[y][x] = 0;
        cost[x][y] = Cost, cost[y][x] = -Cost;
        f[x][y] = f[y][x] = 0;
    }
} graph;

int main()
{
    // freopen("input_agc", "r", stdin);
    cin.sync_with_stdio(); cin.tie(0);

    int n, i;
    int x, y, cnt;

    cin >> n;

    graph.S = 1; graph.D = 2 * n + 6;
    graph.n = 2 * n + 6;

    for(i=1; i<=n; ++i)
    {
        cin >> x >> y >> cnt;
        graph.add_edge(graph.S, i+1, cnt, 0);
        graph.add_edge(i+1, n+2, cnt, -x-y);
        graph.add_edge(i+1, n+3, cnt, -x+y);
        graph.add_edge(i+1, n+4, cnt, +x-y);
        graph.add_edge(i+1, n+5, cnt, +x+y);
    }

    for(i=1; i<=n; ++i)
    {
        cin >> x >> y >> cnt;
        graph.add_edge(n+5+i, graph.D, cnt, 0);
        graph.add_edge(n+2, n+5+i, cnt, +x+y);
        graph.add_edge(n+3, n+5+i, cnt, +x-y);
        graph.add_edge(n+4, n+5+i, cnt, -x+y);
        graph.add_edge(n+5, n+5+i, cnt, -x-y);
    }

    graph.prepare();
    cout << -graph.max_flow_min_cost() << '\n';
       
    return 0;
}


Measured memory_bytes: 82408