#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int N;
ll V, F;
ll RX[1010], RY[1010], RC[1010];
ll BX[1010], BY[1010], BC[1010];

const ll MAX_V = 2000000;

struct edge {int to; ll cap, cost; int rev;};
vector<edge> G[MAX_V];
ll h[MAX_V], dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

void add_edge(int from, int to, ll cap, ll cost){
	G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
	G[to].push_back((edge){from, 0, -cost, (int)G[from].size()-1});
}

ll min_cost_flow(int s, int t, ll f){
	ll res = 0;
	fill(dist, dist + V, INFL);
	dist[s] = 0;
	bool update = true;
	int cnt = 0;
	while(update && cnt < 2*V){
		cnt++;
		update = false;
		for(int v = 0; v < V; v++){
			if(dist[v] == INFL) continue;
			for(int i = 0; i < G[v].size(); i++){
				edge &e = G[v][i];
				if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
					dist[e.to] = dist[v] + e.cost;
					prevv[e.to] = v;
					preve[e.to] = i;
					update = true;
				}
			}
		}
	}

	if(dist[t] == INFL) return -1;

	ll d = f;
	for(int v = t; v != s; v = prevv[v]){
		d = min(d, G[prevv[v]][preve[v]].cap);
	}
	f -= d;
	res += d * dist[t];
	for(int v = t; v != s; v = prevv[v]){
		edge &e = G[prevv[v]][preve[v]];
		e.cap -= d;
		G[v][e.rev].cap += d;
	}
	if(f == 0) return res;

	for(int v = 0; v < V; v++){
		h[v] += dist[v];
	}
	while(f > 0){
		priority_queue <P, vector<P>, greater<P>> que;
		fill(dist, dist + V, INFL);
		dist[s] = 0;
		que.push(P(0, s));
		while(!que.empty()){
			P p = que.top(); que.pop();
			int v = p.second;
			if(dist[v] < p.first) continue;
			for(int i = 0; i < G[v].size(); i++){
				edge &e = G[v][i];
				if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(P(dist[e.to], e.to));
				}
			}
		}
		if(dist[t] == INFL) return -1;
		for(int v = 0; v < V; v++) h[v] += dist[v];

		d = f;
		for(int v = t; v != s; v = prevv[v]){
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * h[t];
		for(int v = t; v != s; v = prevv[v]){
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int main(void){
	cin >> N;
	V = 2 * N + 6;
	for(int i = 0; i < N; i++){
		cin >> RX[i] >> RY[i] >> RC[i];
		F += RC[i];
	}
	for(int i = 0; i < N; i++){
		cin >> BX[i] >> BY[i] >> BC[i];
	}

	int s = 2*N, t = s+1;
	int a1 = t+1, a2 = t+2, a3 = t+3, a4 = t+4;

	for(int i = 0; i < N; i++){
		ll rx = RX[i], ry = RY[i], rc = RC[i];
		add_edge(i, a1, INFL, rx+ry);
		add_edge(i, a2, INFL, rx-ry);
		add_edge(i, a3, INFL, -rx+ry);
		add_edge(i, a4, INFL, -rx-ry);
	}
	for(int i = 0; i < N; i++){
		ll bx = BX[i], by = BY[i], bc = BC[i];
		add_edge(a1, N+i, INFL, -bx-by);
		add_edge(a2, N+i, INFL, -bx+by);
		add_edge(a3, N+i, INFL, bx-by);
		add_edge(a4, N+i, INFL, bx+by);
	}

	for(int i = 0; i < N; i++){
		ll rx = RX[i], ry = RY[i], rc = RC[i];
		add_edge(s, i, rc, 0);
		ll bx = BX[i], by = BY[i], bc = BC[i];
		add_edge(N+i, t, bc, 0);
		V += 2;
	}
	cout << -min_cost_flow(s, t, F) << endl;

}


Measured memory_bytes: 56296