#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();	
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
//ruogu_alter
const int N = 2e4 + 10;
const int s = N - 1;
const int t = N - 2;
int n, pre[N], pree[N], flow[N];
ll dis[N];
bool vis[N];
struct edge {
  int to, val, cost, rev;
};
const ll inf = 2e18;
vector<edge> g[N];
//
inline void addedge(int x, int y, int z, int w) {
  g[x].emplace_back((edge){y, z, w, (int)g[y].size()});
  g[y].emplace_back((edge){x, 0, -w, (int)g[x].size() - 1}); 
}
bool spfa() {
  memset(vis, 0, sizeof(vis)); pre[t] = -1;
  rep(i, N) dis[i] = -inf, flow[i] = INF; dis[s] = 0;
  queue<int> qu; qu.emplace(s);
  while (qu.size()) {  
    int u = qu.front(); qu.pop(); vis[u] = false;
    rep(i, g[u].size()) {
      edge &e = g[u][i];
      if (e.val && dis[e.to] < 1ll * e.cost + dis[u]) {
        dis[e.to] = 1ll * e.cost + dis[u];
        pre[e.to] = u;
        pree[e.to] = i;
        flow[e.to] = min(flow[u], e.val);
        if (!vis[e.to]) {
          vis[e.to] = true;
          qu.emplace(e.to);
        }
      }
    }
  }
  return pre[t] >= 0;
}
ll ek() {
  ll res = 0;
  while (spfa()) {
    int now = t;
    res += 1ll * flow[t] * dis[t];
    while (now != s) {
      int u = pre[now], x = pree[now];
      g[u][x].val -= flow[t];
      g[now][g[u][x].rev].val += flow[t];
      now = u;
    }
  }
  return res;
}
int main() {
  n = getint();
  rep(i, n) {
    int x = getint(), y = getint(), c = getint();
    addedge(s, i, c, 0);
    addedge(i, 2 * n, INF, x + y);
    addedge(i, 2 * n + 1, INF, x - y);
    addedge(i, 2 * n + 2, INF, y - x);
    addedge(i, 2 * n + 3, INF, -x - y);
  }
  for (int i = n; i < 2 * n; i++) {
    int x = getint(), y = getint(), c = getint();
    addedge(i, t, c, 0);
    addedge(2 * n, i, INF, -x - y);
    addedge(2 * n + 1, i, INF, y - x);
    addedge(2 * n + 2, i, INF, x - y);
    addedge(2 * n + 3, i, INF, x + y);
  }
  cout << ek() << endl;
  return 0;
}
