#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))

const int mod = 998244353;
typedef unsigned long long lu;
typedef long long li;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (lu)x * y % mod; }
inline int Mul(int x, int y, int z) { return (lu)x * y % mod * z % mod; }

inline int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

namespace mcmf {
  typedef int FlowType;
  typedef li CostType;
  const int maxn = 1e5, maxm = 2e5;
  const FlowType inff = ~0U >> 2;
  const CostType infc = ~0LLU >> 2;

  int n, m, s, t;
  vector<int> g[maxn];

  struct Edge {
    int v;
    FlowType cap, flow;
    CostType cost;
  } edge[maxm << 1];

  void Init(int n0, int s0, int t0) {
    n = n0; m = 0; s = s0; t = t0;
    for (int i = 0; i < n; ++i) {
      g[i].clear();
    }
  }

  void AddEdge(int u, int v, FlowType cap, CostType cost) {
    g[u].push_back(m);
    edge[m++] = (Edge){v, cap, 0, cost};
    g[v].push_back(m);
    edge[m++] = (Edge){u, 0, 0, -cost};
  }

  CostType dist[maxn], h[maxn];

  struct Node {
    int u;
    CostType d;
    bool operator < (const Node &rhs) const {
      return d > rhs.d;
    }
  };

  bool Dijkstra(void) {
    priority_queue<Node> q;
    q.push((Node){s, 0});
    fill(dist, dist + n, infc);
    dist[s] = 0;
    while (!q.empty()) {
      int u = q.top().u;
      CostType d = q.top().d;
      q.pop();
      if (d != dist[u]) continue;
      for (int i = 0; i < g[u].size(); ++i) {
        Edge &e = edge[g[u][i]];
        if (e.flow < e.cap) {
          CostType t = dist[u] + h[u] - h[e.v] + e.cost;
          if (dist[e.v] > t) {
            dist[e.v] = t;
            q.push((Node){e.v, t});
          }
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      h[i] = min(h[i] + dist[i], infc);
    }
    return h[t] != infc;
  }

  bool ins[maxn];
  int cur[maxn];

  FlowType Dfs(int u, FlowType f) {
    if (u == t) return f;
    ins[u] = true;
    FlowType sum = 0;
    for (int &i = cur[u]; i < g[u].size(); ++i) {
      Edge &e = edge[g[u][i]], &r = edge[g[u][i] ^ 1];
      if (e.flow < e.cap && e.cost + h[u] - h[e.v] == 0 && !ins[e.v]) {
        FlowType t = Dfs(e.v, min(f - sum, e.cap - e.flow));
        e.flow += t;
        r.flow -= t;
        sum += t;
        if (sum == f) break;
      }
    }
    ins[u] = false;
    return sum;
  }

  pair<FlowType, CostType> Solve(void) {
    pair<FlowType, CostType> ans(0, 0);
    fill(h, h + n, 0);
    fill(ins, ins + n, false);
    while (Dijkstra()) {
      fill(cur, cur + n, 0);
      FlowType f = Dfs(s, inff);
      ans.first += f;
      ans.second += f * h[t];
    }
    return ans;
  }
}

// void Init(int n0, int s0, int t0)
// void AddEdge(int u, int v, FlowType cap, CostType cost)
// pair<FlowType, CostType> Solve(void)

// ----------------------------------------

const int maxn = 1000;
int n, rx[maxn], ry[maxn], bx[maxn], by[maxn], rc[maxn], bc[maxn];

const int co_x[] = {1, 1, -1, -1};
const int co_y[] = {1, -1, 1, -1};

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d", rx + i, ry + i, rc + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d", bx + i, by + i, bc + i);
  }
  int V = 2 * n + 6, S = V - 2, T = V - 1;
  mcmf::Init(V, S, T);
  for (int i = 0; i < n; ++i) {
    mcmf::AddEdge(S, i, rc[i], 0);
    mcmf::AddEdge(n + i, T, bc[i], 0);
    for (int x = 0; x < 4; ++x) {
      int M = 2 * n + x;
      li co_l = co_x[x] * rx[i] + co_y[x] * ry[i];
      li co_r = -(co_x[x] * bx[i] + co_y[x] * by[i]);
      mcmf::AddEdge(i, M, rc[i], co_l);
      mcmf::AddEdge(M, n + i, bc[i], co_r);
    }
  }
  auto res = mcmf::Solve();
  li ans = -res.second;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 6400