#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define sd(x) scanf("%d", &(x))

#define fst first
#define snd second
#define all(c) ((c).begin()), ((c).end())
#define TEST(s) if (!(s)) { cout << __LINE__ << " " << #s << endl; exit(-1); }

const long long INF = 5e9;
struct graph {
  typedef long long flow_type;
  typedef long long cost_type;
  struct edge {
    int src, dst;
    flow_type capacity, flow;
    cost_type cost;
    size_t rev;
  };
  vector<edge> edges;
  void add_edge(int src, int dst, flow_type cap, cost_type cost) {
    // cerr << src << " " << dst << " " << cap << endl;
    adj[src].push_back({src, dst, cap, 0, cost, adj[dst].size()});
    adj[dst].push_back({dst, src, 0, 0, -cost, adj[src].size()-1});
  }
  int n;
  vector<vector<edge>> adj;
  graph(int n) : n(n), adj(n) { }

  pair<flow_type, cost_type> min_cost_max_flow(int s, int t) {
    flow_type flow = 0;
    cost_type cost = 0;

    for (int u = 0; u < n; ++u) // initialize
      for (auto &e: adj[u]) e.flow = 0;

    vector<cost_type> p(n, 0);

    auto rcost = [&](edge e) { return e.cost + p[e.src] - p[e.dst]; };
    for (int iter = 0; ; ++iter) {
      vector<int> prev(n, -1); prev[s] = 0;
      vector<cost_type> dist(n, INF); dist[s] = 0;
      if (iter == 0) { // use Bellman-Ford to remove negative cost edges
        vector<int> count(n); count[s] = 1;
        queue<int> que; 
        for (que.push(s); !que.empty(); ) {
          int u = que.front(); que.pop();
          count[u] = -count[u];
          for (auto &e: adj[u]) {
            if (e.capacity > e.flow && dist[e.dst] > dist[e.src] + rcost(e)) {
              dist[e.dst] = dist[e.src] + rcost(e);
              prev[e.dst] = e.rev;
              if (count[e.dst] <= 0) {
                count[e.dst] = -count[e.dst] + 1;
                que.push(e.dst);
              }
            }
          }
        }
      } else { // use Dijkstra 
        typedef pair<cost_type, int> node;
        priority_queue<node, vector<node>, greater<node>> que;
        que.push({0, s});
        while (!que.empty()) {
          node a = que.top(); que.pop();
          if (a.snd == t) break;
          if (dist[a.snd] > a.fst) continue;
          for (auto e: adj[a.snd]) {
            if (e.capacity > e.flow && dist[e.dst] > a.fst + rcost(e)) {
              dist[e.dst] = dist[e.src] + rcost(e);
              prev[e.dst] = e.rev;
              que.push({dist[e.dst], e.dst});
            }
          }
        }
      }
      if (prev[t] == -1) break;

      for (int u = 0; u < n; ++u) 
        if (dist[u] < dist[t]) p[u] += dist[u] - dist[t];

      function<flow_type(int,flow_type)> augment = [&](int u, flow_type cur) {
        if (u == s) return cur;
        edge &r = adj[u][prev[u]], &e = adj[r.dst][r.rev];
        flow_type f = augment(e.src, min(e.capacity - e.flow, cur));
        e.flow += f; r.flow -= f;
        return f;
      };
      flow_type f = augment(t, INF);
      flow += f;
      cost += f * (p[t] - p[s]);
    }
    return {flow, cost};
  }
};

const int N = 1005;
int rx[N], ry[N], bx[N], by[N], rc[N], bc[N];
int main(){
  int n; sd(n);
  int s = 0;
  graph g(2 * n + 6);
  const ll offset = 2e9 + 10;
  for(int i = 1; i <= n; i++){
    sd(rx[i]), sd(ry[i]), sd(rc[i]);
    g.add_edge(0, i, rc[i], 0);
    g.add_edge(i, n + 1, INF, offset - rx[i] - ry[i]);
    g.add_edge(i, n + 2, INF, offset - rx[i] + ry[i]);
    g.add_edge(i, n + 3, INF, offset + rx[i] - ry[i]);
    g.add_edge(i, n + 4, INF, offset + rx[i] + ry[i]);
  }
  for(int i = 1; i <= n; i++){
    sd(bx[i]); sd(by[i]); sd(bc[i]); s += bc[i];
    int node = n + 4 + i;
    g.add_edge(node, 2 * n + 5, bc[i], 0);
    g.add_edge(n + 1, node, INF, offset + bx[i] + by[i]);
    g.add_edge(n + 2, node, INF, offset + bx[i] - by[i]);
    g.add_edge(n + 3, node, INF, offset - bx[i] + by[i]);
    g.add_edge(n + 4, node, INF, offset - bx[i] - by[i]);
  }
  auto flowvals = g.min_cost_max_flow(0, 2 * n + 5);
  // cerr << flowvals.fst << " " << flowvals.snd << endl;
  printf("%lld\n", offset * (2 * s) - flowvals.snd);
}

Measured memory_bytes: 1672