#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
 
typedef long long lo;
 
template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

namespace mf {
	const int N = 1e4 + 233;
	const int M = 2e5 + 233;
	const lo inf = 1e15;
	struct E {
		int nxt, to, fl; lo w;
	} e[M];
	int head[N], e_cnt = 1, cur[N];
	lo d[N]; bool book[N];
	int all;
	inline void init(int n) {
		all = n;
		re0 (i, all + 1) head[i] = 0;
		e_cnt = 1;
	}
	inline void adde(int x, int y, int fl, lo w) {
		e[++e_cnt] = (E) { head[x], y, fl, w }; head[x] = e_cnt;
	}
	inline void link(int x, int y, int fl, lo w) {
		w = -w;
		adde(x, y, fl, w); adde(y, x, 0, -w);
	}
	inline bool spfa(int S, int T) {
		re0 (i, all + 1) d[i] = inf, book[i] = 0;
		queue <int> Q;
		book[S] = true; d[S] = 0; Q.push(S);
		while (!Q.empty()) {
			int u = Q.front(); Q.pop(); book[u] = false;
			for (int i = head[u]; i; i = e[i].nxt) if (e[i ^ 1].fl) {
					int v = e[i].to;
					if (d[v] > d[u] + e[i ^ 1].w) {
						d[v] = d[u] + e[i ^ 1].w;
						if (!book[v]) Q.push(v), book[v] = true;
					}
				}
		}
		return d[T] != inf;
	}
	inline int dfs(int u, int f, int T) {
		book[u] = true;
		if (u == T || !f) return f;
		int used = 0, t;
		for (int &i = cur[u]; i; i = e[i].nxt)
			if (e[i].fl) {
				int v = e[i].to;
				if (book[v] || d[u] != d[v] + e[i].w) continue;
				t = dfs(v, min(f - used, e[i].fl), T);
				e[i].fl -= t; e[i ^ 1].fl += t; used += t;
				if (used == f) break;
			}
		if (used == 0) d[u] = inf;
		return used;
	}
	pair <int, lo> doit(int S, int T) {
		int maxflow = 0; lo mincost = 0;
		while (spfa(T, S)) {
			re0 (i, all + 1) cur[i] = head[i], book[i] = 0;
			int t = dfs(S, 1e9, T);
			maxflow += t;
			mincost += t * d[S];
		}
		return make_pair(maxflow, mincost);
	}
}
 
using mf::link;
 

int dx[] = {1, 1, -1, -1};
int dy[] = {1, -1, 1, -1};

int n, id[4], S, T, tot;

signed main(void) {
	read(n);
	for (int k = 0; k < 4; k++) id[k] = ++tot;
	S = ++tot; T = ++tot;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		int x, y, c;
		read(x); read(y); read(c);
		sum += c;
		int u = ++tot;
		link(S, u, c, 0);
		vector <int> cid(4, 0);
		for (int k = 0; k < 4; k++) {
			int nx = x * dx[k];
			int ny = y * dy[k];
			cid[k] = ++tot;
			link(u, cid[k], c, nx + ny);
			link(cid[k], id[3 - k], c, 0);
			// cout << k << " " << nx << " " << ny << " " << 3 - k << "\n";
		}
	}
	for (int i = 1; i <= n; i++) {
		int x, y, c;
		read(x); read(y); read(c);
		int u = ++tot;
		link(u, T, c, 0);
		vector <int> cid(4, 0);
		for (int k = 0; k < 4; k++) {
			int nx = x * dx[k];
			int ny = y * dy[k];
			cid[k] = ++tot;
			link(cid[k], u, c, nx + ny);
			link(id[k], cid[k], c, 0);
			// cout << k << " " << nx << " " << ny << " " << 3 - k << "\n";
		}
	}
	mf::all = tot;
	auto it = mf::doit(S, T);
	cout << -it.second << "\n";
	assert(it.first == sum);
}


Measured memory_bytes: 1280