#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 1005, V = 200005, E = 500005, inf1 = 1000000000;

const long long inf2 = 100000000000000ll;
template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}

template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

struct edge {
	int to, nxt, cap;
	long long cost; 
} graph[E];
int head[V], s, t, cntv = 0, cnte = 0;
int newnode () {
	head[++cntv] = -1;
	return cntv;
}
void addedge (int u, int v, int cap, long long cost) {
	edge e = {v, head[u], cap, cost};
	graph[head[u] = cnte++] = e;
}

int par[V], path[V];
long long dist[V];
bool vis[V];
queue<int> q;
bool spfa () {
	for (int i = 1; i <= cntv; i++) vis[i] = false, dist[i] = -inf2;
	dist[s] = 0ll, vis[s] = true, q.push(s);
	while (!q.empty()) {
		int u = q.front();
		for (int i = head[u]; ~i; i = graph[i].nxt) {
			int v = graph[i].to;
			if (graph[i].cap && dist[v] < dist[u] + graph[i].cost) {
				dist[v] = dist[u] + graph[i].cost;
				path[v] = i, par[v] = u;
				if (!vis[v]) q.push(v), vis[v] = true;
			}
		}
		vis[u] = false, q.pop();
	}
	return dist[t] > 0ll;
}

long long maxcost () {
	long long res = 0ll;
	while (spfa()) {
		int min_cap = inf1;
		for (int i = t; i != s; i = par[i]) min_cap = min(min_cap, graph[path[i]].cap);
		res += dist[t] * min_cap;
		for (int i = t; i != s; i = par[i]) graph[path[i]].cap -= min_cap, graph[path[i] ^ 1].cap += min_cap;
	}
	return res;
}

int n, id1[N], id2[N], id[4];
long long X1[N], X2[N], c1[N], Y1[N], Y2[N], c2[N];

int main () {
	read(n);
	for (int i = 1; i <= n; i++) read(X1[i]), read(Y1[i]), read(c1[i]);
	for (int i = 1; i <= n; i++) read(X2[i]), read(Y2[i]), read(c2[i]);

	s = newnode(), t = newnode();
	for (int i = 1; i <= n; i++) id1[i] = newnode();
	for (int i = 1; i <= n; i++) id2[i] = newnode();
	for (int i = 0; i < 4; i++) id[i] = newnode();

	for (int i = 1; i <= n; i++) {
		addedge(s, id1[i], c1[i], 0ll);
		addedge(id1[i], s, 0, 0ll);

		addedge(id1[i], id[0], inf1, X1[i] + Y1[i]);
		addedge(id[0], id1[i], 0, -X1[i] - Y1[i]);

		addedge(id1[i], id[1], inf1, -X1[i] - Y1[i]);
		addedge(id[1], id1[i], 0, X1[i] + Y1[i]);

		addedge(id1[i], id[2], inf1, X1[i] - Y1[i]);
		addedge(id[2], id1[i], 0, Y1[i] - X1[i]);

		addedge(id1[i], id[3], inf1, Y1[i] - X1[i]);
		addedge(id[3], id1[i], 0, X1[i] - Y1[i]);
	}

	for (int i = 1; i <= n; i++) {
		addedge(id2[i], t, c2[i], 0ll);
		addedge(t, id2[i], 0, 0ll);

		addedge(id[0], id2[i], inf1, -X2[i] - Y2[i]);
		addedge(id2[i], id[0], 0, X2[i] + Y2[i]);

		addedge(id[1], id2[i], inf1, X2[i] + Y2[i]);
		addedge(id2[i], id[1], 0, -X2[i] - Y2[i]);

		addedge(id[2], id2[i], inf1, Y2[i] - X2[i]);
		addedge(id2[i], id[2], 0, X2[i] - Y2[i]);

		addedge(id[3], id2[i], inf1, X2[i] - Y2[i]);
		addedge(id2[i], id[3], 0, Y2[i] - X2[i]);
	}

	write(maxcost()), putchar('\n');
	fclose(stdin), fclose(stdout);
	return 0;
}

Measured memory_bytes: 4480