#include <bits/stdc++.h>
using i64 = long long;

class MinCostFlow {
    using i64 = long long;
    struct Edge {
        int from, to;
        i64 cap, cost;
        int rev;
        Edge(int from, int to, i64 cap, i64 cost, int rev) : from(from), to(to), cap(cap), cost(cost), rev(rev) {}
    };

    int size;
    std::vector<std::vector<Edge>> g;
    std::vector<i64> h;

    std::vector<i64> dist;
    std::vector<std::pair<int, int>> pred;
    std::priority_queue<std::pair<i64, int>> q;

    bool find_path(int s, int t) {
        std::fill(dist.begin(), dist.end(), inf);
        dist[s] = 0;
        q.emplace(0, s);

        while (!q.empty()) {
            auto p = q.top();
            q.pop();
            if (-p.first > dist[p.second]) continue;
            for (int i = 0; i < g[p.second].size(); i++) {
                auto &e = g[p.second][i];
                auto c = dist[e.from] + e.cost + h[e.from];
                if (e.cap > 0 && dist[e.to] + h[e.to] > c) {
                    dist[e.to] = c - h[e.to];
                    pred[e.to] = std::make_pair(p.second, i);
                    q.emplace(-dist[e.to], e.to);
                }
            }
        }

        if (dist[t] == inf) return false;

        return true;
    }

    void update(int s, int t, i64 &flow, i64 &cost) {
        for (int i = 0; i < size; i++) h[i] += dist[i];

        i64 f = flow;
        for (int v = t; v != s;) {
            int p = pred[v].first, i = pred[v].second;
            auto &e = g[p][i];
            f = std::min(f, e.cap);
            v = p;
        }

        for (int v = t; v != s;) {
            int p = pred[v].first, i = pred[v].second;
            auto &e = g[p][i];
            e.cap -= f;
            g[e.to][e.rev].cap += f;
            v = p;
        }
        cost += f * h[t];
        flow -= f;
    }

public:
    const static i64 inf;
    explicit MinCostFlow(int size) : size(size), g(size), h(size), dist(size), pred(size) {}

    void add_edge(int from, int to, i64 cap, i64 cost) {
        g[from].emplace_back(from, to, cap, cost, g[to].size());
        g[to].emplace_back(to, from, 0, -cost, g[from].size() - 1);
    }

    std::pair<i64, i64> calc(int s, int t, i64 k) {
        i64 flow = k, cost = 0;
        while (flow > 0) {
            auto found = find_path(s, t);
            if (!found) return { flow, cost };
            update(s, t, flow, cost);
        }
        return { flow, cost };
    }
};

constexpr i64 MinCostFlow::inf = std::numeric_limits<i64>::max() / 3;

int main() {
    int n;
    std::cin >> n;

    MinCostFlow mcf(2 * n + 6);
    int s = 2 * n, t = s + 1, pp = t + 1, pn = t + 2, np = t + 3, nn = t + 4;
    i64 sum = 0;
    for (int i = 0; i < n; i++) {
        i64 x, y, c;
        std::cin >> x >> y >> c;
        sum += c;
        mcf.add_edge(s, i, c, 0);
        mcf.add_edge(i, t + 1, c, -x - y);
        mcf.add_edge(i, t + 2, c, x - y);
        mcf.add_edge(i, t + 3, c, -x + y);
        mcf.add_edge(i, t + 4, c, x + y);
    }
    for (int i = 0; i < n; i++) {
        i64 x, y, c;
        std::cin >> x >> y >> c;
        mcf.add_edge(n + i, t, c, 0);
        mcf.add_edge(t + 1, n + i, c, x + y);
        mcf.add_edge(t + 2, n + i, c, -x + y);
        mcf.add_edge(t + 3, n + i, c, x - y);
        mcf.add_edge(t + 4, n + i, c, -x - y);
    }

    std::cout << -mcf.calc(s, t, sum).second << std::endl;

    return 0;
}


Measured memory_bytes: 1536