import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

class MinCostFlow(wint, cint) {
  int n, m;
  int[][] g;
  int[] zu;
  wint[] capa0, capa, ex;
  cint[] cost;
  real[] pot;
  bool[] vis;
  int[] itr, lev;
  this(int n) {
    this.n = n; m = 0; g = new int[][n]; zu = null; capa = null; cost = null;
    ex = new wint[n]; pot = new real[n]; pot[] = 0; vis = new bool[n]; itr = new int[n]; lev = new int[n];
  }
  void addEdge(int u, int v, wint w, cint c) {
    g[u] ~= m; zu ~= v; capa0 ~= w; capa ~= w; cost ~= +c; ++m;
    g[v] ~= m; zu ~= u; capa0 ~= 0; capa ~= 0; cost ~= -c; ++m;
  }
  wint augment(int u, int t, wint f) {
    if (u == t) return f;
    foreach (i; g[u][itr[u] .. $]) {
      if (capa[i] > 0 && lev[u] < lev[zu[i]]) {
        wint g = augment(zu[i], t, min(f, capa[i]));
        if (g > 0) {
          capa[i] -= g; capa[i ^ 1] += g; return g;
        }
      }
      ++itr[u];
    }
    return 0;
  }
  wint augment(int u, wint f) {
    if (ex[u] < 0) {
      wint g = min(f, -ex[u]); ex[u] += g; return g;
    }
    foreach (i; g[u][itr[u] .. $]) {
      if (capa[i] > 0 && cost[i] + pot[u] - pot[zu[i]] < 0) {
        wint g = augment(zu[i], min(f, capa[i]));
        if (g > 0) {
          capa[i] -= g; capa[i ^ 1] += g; return g;
        }
      }
      ++itr[u];
    }
    return 0;
  }
  wint dinic(int s, int t, wint f) {
    wint tof = 0;
    for (; tof < f; ) {
      int[] q;
      lev[] = -1;
      for (lev[s] = 0, q ~= s; !q.empty; ) {
        int u = q.front; q.popFront;
        foreach (i; g[u]) {
          int v = zu[i];
          if (capa[i] > 0 && lev[v] == -1) {
            lev[v] = lev[u] + 1; q ~= v;
          }
        }
      }
      if (lev[t] == -1) break;
      itr[] = 0;
      for (wint g; (g = augment(s, t, f - tof)) > 0; ) tof += g;
    }
    return tof;
  }
  void dfs(int u) {
    if (vis[u]) return; vis[u] = true;
    foreach (i; g[u]) if (capa[i] > 0 && cost[i] + pot[u] - pot[zu[i]] < 0) {
      dfs(zu[i]);
    }
  }
  // cint solve() {
    // real eps = 0;
  cint solve(int s, int t, wint flow) {
    real eps = 1;
    ex[s] += flow;
    ex[t] -= flow;
    foreach (i; 0 .. m) if (capa[i] > 0) chmax(eps, cast(real)(-cost[i]));
    for (; eps * n >= 1; ) {
      eps /= 4;
      foreach (i; 0 .. m) if (capa[i] > 0 && cost[i] + pot[zu[i ^ 1]] - pot[zu[i]] < 0) {
        ex[zu[i ^ 1]] -= capa[i]; ex[zu[i]] += capa[i]; capa[i ^ 1] += capa[i]; capa[i] = 0;
      }
      for (; ; ) {
        vis[] = false; itr[] = 0;
        foreach (u; 0 .. n) if (ex[u] > 0) dfs(u);
        foreach (u; 0 .. n) if (vis[u]) pot[u] -= eps;
        foreach (u; 0 .. n) for (wint f; ex[u] > 0 && (f = augment(u, ex[u])) > 0; ) ex[u] -= f;
        if (ex.all!"a <= 0") break;
      }
    }
    cint toc = 0;
    foreach (i; 0 .. m) if (capa0[i] > capa[i]) toc += (capa0[i] - capa[i]) * cost[i];
    return toc;
  }
}



void main() {
  try {
    for (; ; ) {
      alias Entry = Tuple!(long, "x", long, "y", int, "c");
      const N = readInt();
      auto A = new Entry[N];
      foreach (i; 0 .. N) {
        A[i].x = readLong();
        A[i].y = readLong();
        A[i].c = readInt();
      }
      auto B = new Entry[N];
      foreach (j; 0 .. N) {
        B[j].x = readLong();
        B[j].y = readLong();
        B[j].c = readInt();
      }
      
      int numBalls;
      foreach (i; 0 .. N) {
        numBalls += A[i].c;
      }
      
      auto mcf = new MinCostFlow!(int, long)(2 + N + N);
      foreach (i; 0 .. N) {
        mcf.addEdge(0, 2 + i, A[i].c, 0);
      }
      foreach (j; 0 .. N) {
        mcf.addEdge(2 + N + j, 1, B[j].c, 0);
      }
      foreach (i; 0 .. N) foreach (j; 0 .. N) {
        const dist = abs(A[i].x - B[j].x) + abs(A[i].y - B[j].y);
        mcf.addEdge(2 + i, 2 + N + j, min(A[i].c, B[j].c), -dist);
      }
      const res = mcf.solve(0, 1, numBalls);
      writeln(-res);
    }
  } catch (EOFException e) {
  }
}
