#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;

typedef long long LL;

const int MAXN = 1e05 + 10;
const int MAXM = 5e05 + 10;

const int INF = 0x7fffffff;
const LL LMIN = 0xcfcfcfcfcfcfcfcf;

struct LinkedForwardStar {
	int to;
	int cap;
	LL cost;

	int next;
} ;

LinkedForwardStar Link[MAXM << 1];
int Head[MAXN]= {0};
int size = 1;

void Insert (int u, int v, int cap, LL cost) {
	Link[++ size].to = v;
	Link[size].cap = cap;
	Link[size].cost = cost;
	Link[size].next = Head[u];

	Head[u] = size;
}
inline void add (int u, int v, int cap, LL cost) {
	Insert (u, v, cap, cost);
	Insert (v, u, 0, - cost);
}

struct T {int x, y, sum;} ;
int N;
T man[MAXN], fem[MAXN];

const int optx[5]= {0, 1, 1, - 1, - 1};
const int opty[5]= {0, 1, - 1, 1, - 1};

int S, T, mid[5];
int id[2][MAXN][5]= {0};
int nodes = 0;
void init () {
	S = ++ nodes;
	for (int i = 1; i <= N; i ++) id[0][i][0] = ++ nodes;
	for (int i = 1; i <= N; i ++)
		for (int j = 1; j <= 4; j ++)
			id[0][i][j] = ++ nodes;
	for (int j = 1; j <= 4; j ++) mid[j] = ++ nodes;
	for (int i = 1; i <= N; i ++) id[1][i][0] = ++ nodes;
	for (int i = 1; i <= N; i ++)
		for (int j = 1; j <= 4; j ++)
			id[1][i][j] = ++ nodes;
	T = ++ nodes;
}
void build () {
	for (int i = 1; i <= N; i ++) {
		add (S, id[0][i][0], man[i].sum, 0);
		int x = man[i].x, y = man[i].y;
		for (int j = 1; j <= 4; j ++) {
			add (id[0][i][0], id[0][i][j], man[i].sum, 0);
			add (id[0][i][j], mid[j], man[i].sum, optx[j] * x + opty[j] * y);
			// cout << "man: " << optx[j] * x + opty[j] * y << endl;
		}
	}
	for (int i = 1; i <= N; i ++) {
		add (id[1][i][0], T, fem[i].sum, 0);
		int x = fem[i].x, y = fem[i].y;
		for (int j = 1; j <= 4; j ++) {
			add (mid[j], id[1][i][j], fem[i].sum, - (optx[j] * x + opty[j] * y));
			add (id[1][i][j], id[1][i][0], fem[i].sum, 0);
			// cout << "fem: " << - (optx[j] * x + opty[j] * y) << endl;
		}
	}
}

queue<int> que;
LL dist[MAXN];
bool inque[MAXN]= {false};
int incf[MAXN]= {0}, pre[MAXN]= {0};
bool SPFA () {
	while (! que.empty()) inque[que.front()] = false, que.pop();
	memset (dist, 0xcf, sizeof (dist));
	que.push(S), dist[S] = 0, inque[S] = true;
	incf[S] = INF;
	while (! que.empty()) {
		int u = que.front(); que.pop();
		inque[u] = false;
		for (int i = Head[u]; i; i = Link[i].next) {
			if (! Link[i].cap) continue;
			int v = Link[i].to;
			if (dist[u] + Link[i].cost > dist[v]) {
				dist[v] = dist[u] + Link[i].cost;
				incf[v] = min (incf[u], Link[i].cap);
				pre[v] = i;
				if (! inque[v]) que.push(v), inque[v] = true;
			}
		}
	}
	if (dist[T] == LMIN) return false;
	return true;
}
int maxflow = 0;
LL total = 0;
void maintain () {
	int x = T;
	while (x != S) {
		int i = pre[x];
		Link[i].cap -= incf[T];
		Link[i ^ 1].cap += incf[T];
		x = Link[i ^ 1].to;
	}
	maxflow += incf[T], total += dist[T] * incf[T];
}

inline int getnum () {
	int num = 0; char ch = getchar (); bool isneg = false;
	while (! isdigit (ch)) if (ch == '-') isneg = true, ch = getchar ();
	while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar ();
	return isneg ? - num : num;
}

int main () {
	// freopen ("offsheet.in", "r", stdin);
	// freopen ("offsheet.out", "w", stdout);

	N = getnum ();
	for (int i = 1; i <= N; i ++)
		man[i].x = getnum (), man[i].y = getnum (), man[i].sum = getnum ();
	for (int i = 1; i <= N; i ++)
		fem[i].x = getnum (), fem[i].y = getnum (), fem[i].sum = getnum ();
	init (), build ();
	while (SPFA ()) maintain ();
	cout << total << endl;

	return 0;
}

/*
10
582463373 690528069 8
621230322 318051944 4
356524296 974059503 6
372751381 111542460 9
392867214 581476334 6
606955458 513028121 5
882201596 791660614 9
250465517 91918758 3
618624774 406956634 6
426294747 736401096 5
974896051 888765942 5
726682138 336960821 3
715144179 82444709 6
599055841 501257806 6
390484433 962747856 4
912334580 219343832 8
570458984 648862300 6
638017635 572157978 10
435958984 585073520 7
445612658 234265014 6
*/

/*
2
0 0 1
3 2 1
2 2 1
5 0 1
*/

/*
3
0 0 1
2 2 1
0 0 2
1 1 1
1 1 1
3 3 2
*/

Measured memory_bytes: 9344