#include <queue>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long int LL;
const LL INF(0X3F3F3F3F3F3F3F3FLL);

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

namespace G
{
	const int Max_V(1050 * 2);
	const int Max_E(1050 * 20);
	int V, S, T, Head[Max_V], Total, To[Max_E], Next[Max_E], Cap[Max_E], Flow[Max_E], Weight[Max_E];
	inline void Add_Edge(int tot, int s, int t, int c, int w)
	{
		To[tot] = t, Next[tot] = Head[s], Head[s] = tot, Cap[tot] = c, Flow[tot] = 0, Weight[tot] = w;
	}
	inline void Add_Link(int s, int t, int c, int w)
	{
		Total += 2, Add_Edge(Total, s, t, c, w), Add_Edge(Total ^ 1, t, s, 0, -w);
	}
	LL Dist[Max_V];
	int Cur[Max_V];
	bool done[Max_V];
	bool SPFA()
	{
		queue<int> Q;
		for (int i = 1;i <= V;++i)
			Dist[i] = -INF, done[i] = false;
		Dist[S] = 0LL, Q.push(S), done[S] = true;
		for (int u;Q.empty() == false;)
		{
			done[u = Q.front()] = false, Q.pop();
			for (int i = Head[u], v;i;i = Next[i])
				if (Cap[i] > Flow[i] && Dist[v = To[i]] < Dist[u] + Weight[i])
				{
					Dist[v] = Dist[u] + Weight[i];
					if (!done[v])
						Q.push(v), done[v] = true;
				}
		}
		return Dist[T] > 0LL;
	}
	int DFS(int u, int a)
	{
		if (u == T || a == 0)
			return a;
		int Ans(0);
		done[u] = true;
		for (int &i = Cur[u], v, f;i;i = Next[i])
			if (Dist[v = To[i]] == Dist[u] + Weight[i] && !done[v = To[i]] && (f = DFS(v, min(a, Cap[i] - Flow[i]))) > 0)
			{
				Ans += f, Flow[i] += f, Flow[i ^ 1] -= f;
				if ((a -= f) == 0)
					break;
			}
		done[u] = false;
		return Ans;
	}
	LL MCMF()
	{
		LL Ans(0LL);
		for (int f;SPFA();)
		{
			for (int i = 1;i <= V;++i)
				Cur[i] = Head[i];
			f = DFS(S, 0X3F3F3F3F), Ans += f * Dist[T];
		}
		return Ans;
	}
}

int main()
{
	int N;
	gi(N);
	G::V = N + N + 4 + 2, G::S = N + N + 4 + 1, G::T = N + N + 4 + 2;
	for (int i = 1, x, y, c;i <= N;++i)
	{
		gi(x), gi(y), gi(c);
		G::Add_Link(G::S, i, c, 0);
		G::Add_Link(i, N + N + 1, c, +x + y);
		G::Add_Link(i, N + N + 2, c, -x + y);
		G::Add_Link(i, N + N + 3, c, -x - y);
		G::Add_Link(i, N + N + 4, c, +x - y);
	}
	for (int i = 1, x, y, c;i <= N;++i)
	{
		gi(x), gi(y), gi(c);
		G::Add_Link(N + i, G::T, c, 0);
		G::Add_Link(N + N + 1, N + i, c, -x - y);
		G::Add_Link(N + N + 2, N + i, c, +x - y);
		G::Add_Link(N + N + 3, N + i, c, +x + y);
		G::Add_Link(N + N + 4, N + i, c, -x + y);
	}
	print(G::MCMF());
	return 0;
}

Measured memory_bytes: 2816