#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

const int INF = 1e18 + 239;

struct Edge {
    int u, v;
    int cost, flow, cap;

    Edge(int u_, int v_, int cost_, int flow_, int cap_) : u(u_), v(v_), cost(cost_), flow(flow_), cap(cap_) {}
};

namespace MinCostFlow {
    int n;
    int start;
    int end;

    vector<int> d;
    vector<int> p;
    vector<int> path;
    vector<int> poten;
    vector<vector<int>> g;
    vector<Edge> ed;

    void init_potent() {
        for (int i = 0; i < n; i++) {
            d[i] = INF;
        }
        d[start] = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < (int)ed.size(); j++) {
                auto e = ed[j];
                if (d[e.v] > d[e.u] + e.cost && e.flow < e.cap) {
                    d[e.v] = d[e.u] + e.cost;
                    p[e.v] = j;
                }
            }
        }
        poten = d;
    }

    void renew_poten() {
        poten = d;
    }

    bool dij() {
        for (int i = 0; i < n; i++) {
            d[i] = INF;
        }
        d[start] = 0;
        p[start] = -1;
        set<pair<int, int>> s;
        s.insert({d[start], start});
        while (!s.empty()) {
            int u = s.begin()->second;
            s.erase(s.begin());
            for (auto ind : g[u]) {
                auto e = ed[ind];
                int rc = e.cost + poten[e.u] - poten[e.v];
                if (e.flow < e.cap && poten[e.v] < INF && d[e.v] > d[e.u] + rc) {
                    s.erase({d[e.v], e.v});
                    d[e.v] = d[e.u] + rc;
                    p[e.v] = ind;
                    s.insert({d[e.v], e.v});
                }
            }
        }
        if (d[end] == INF) {
            return false;
        } else {
            for (int i = 0; i < n; i++) {
                d[i] -= poten[start];
                d[i] += poten[i];
            }
            path.clear();
            int cur = end;
            while (cur != start) {
                path.push_back(p[cur]);
                cur = ed[p[cur]].u;
            }
            return true;
        }
    }

    int solve() {
        init_potent();
        while (dij()) {
            //cerr << "dij ok " << d[end] << endl;
            int to = INF;
            for (auto ind : path) {
                auto e = ed[ind];
                to = min(to, e.cap - e.flow);
            }
            for (auto ind : path) {
                ed[ind].flow += to;
                ed[ind ^ 1].flow -= to;
            }
            renew_poten();
        }
        int ans = 0;
        for (auto e : ed) {
            ans += e.flow * e.cost;
        }
        return ans / 2;
    }

    void add_edge(int u, int v, int cap, int cost) {
        int pnt = (int)ed.size();
        ed.push_back(Edge(u, v, cost, 0, cap));
        ed.push_back(Edge(v, u, -cost, 0, 0));
        g[u].push_back(pnt);
        g[v].push_back(pnt + 1);
    }

    void init(int n_, int start_, int end_) {
        n = n_;
        start = start_;
        end = end_;
        d.resize(n);
        p.resize(n);
        g.resize(n);
    }
}//namespace MinCostFlow

struct Ball {
    int cnt;
    int x, y;

    int get(int mask) {
        int ans = 0;
        if (mask & 1) {
            ans -= x;
        } else {
            ans += x;
        }
        if ((mask >> 1) & 1) {
            ans -= y;
        } else {
            ans += y;
        }
        return ans;
    }

    Ball() {}
};

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    
    // cout << n << endl;

    int start = 4 + n + n;
    int end = start + 1;
    MinCostFlow::init(4 + n + n + 2, start, end);
    
    vector<Ball> a(n);
    vector<Ball> b(n);
    for (auto &t : a) {
        cin >> t.x >> t.y >> t.cnt;
    }
    for (auto &t : b) {
        cin >> t.x >> t.y >> t.cnt;
    }
    cerr << "read ok" << endl;
    for (int i = 0; i < n; i++) {
        for (int mask = 0; mask < 4; mask++) {
            MinCostFlow::add_edge(4 + i, mask, INF, a[i].get(mask));
        }
        MinCostFlow::add_edge(start, 4 + i, a[i].cnt, 0);
    }
    for (int i = 0; i < n; i++) {
        for (int mask = 0; mask < 4; mask++) {
            MinCostFlow::add_edge(mask, 4 + i + n, INF, b[i].get(mask ^ 3));
        }
        MinCostFlow::add_edge(4 + i + n, end, b[i].cnt, 0);
    }
    cout << abs(MinCostFlow::solve()) << endl;
}


Measured memory_bytes: 1936