# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>

//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
map<LL, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, s, t, ans, cnt, sum, a[3000], b[3000], c[3000];
string str;
bool f[110000];
//char c;
struct PrimalDual {
	struct Edge {
		LL d, c, f, w, r, is_r;
		Edge(LL d_, LL c_, LL f_, LL w_, LL r_, bool is_r_)
			: d(d_), c(c_), f(f_), w(w_), r(r_), is_r(is_r_) {}
	};
	LL n;
	vector<vector<Edge>> g;
	PrimalDual(LL n_) : n(n_), g(vector<vector<Edge> >(n_)) {}
	void add_edge(LL src, LL dst, LL cap, LL cost) {  // 有向辺
		LL rsrc = g[dst].size();
		LL rdst = g[src].size();
		g[src].emplace_back(dst, cap, 0, cost, rsrc, false);
		g[dst].emplace_back(src, cap, cap, -cost, rdst, true);
	}
	LL solve(LL s, LL t, LL f) {
		LL res = 0;
		static LL h[100000 + 10], dist[100000];
		static LL prevv[100000 + 10], preve[100000 + 10];
		priority_queue<Pll, vector<Pll>, greater<Pll> > q;
		fill(h, h + n, 0);
		while (f > 0) {
			fill(dist, dist + n, INF / 8);
			dist[s] = 0;
			q.emplace(0, s);
			while (q.size()) {
				LL cd;
				LL v;
				tie(cd, v) = q.top();
				q.pop();
				if (dist[v] < cd) continue;
				for (LL i = 0; i < (LL)(g[v].size()); ++i) {
					Edge &e = g[v][i];
					if (residue(e) == 0) continue;
					if (dist[e.d] + h[e.d] > cd + h[v] + e.w) {
						dist[e.d] = dist[v] + e.w + h[v] - h[e.d];
						prevv[e.d] = v;
						preve[e.d] = i;
						q.emplace(dist[e.d], e.d);
					}
				}
			}
			if (dist[t] == INF) return -1;  // 経路が見つからなかった
			// s-t 間最短路に沿って目一杯流す
			for (LL i = 0; i < n; ++i) h[i] += dist[i];
			LL d = f;
			for (LL v = t; v != s; v = prevv[v]) {
				d = min(d, residue(g[prevv[v]][preve[v]]));
			}
			f -= d;
			res += d * h[t];
			for (LL v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.f += d;
				g[v][e.r].f -= d;
			}
		}
		return res;
	}
	LL residue(const Edge &e) { return e.c - e.f; }
};
int main() {
	cin >> n;
	rep(i, n * 2) {
		cin >> a[i] >> b[i] >> c[i];
		sum += c[i];
	}
	q = 10000000000;
	PrimalDual pd(n * 2 + 6);
	rep(i, n) {
		LL idx = i;
		rep(j, 2)rep(k, 2)pd.add_edge(idx, 2 * n + j + k * 2, INF, q - (a[idx] * (j ? 1 : -1) + b[idx] * (k ? 1 : -1)));
		pd.add_edge(n * 2 + 4, idx, c[idx], 0);
	}
	rep(i, n) {
		LL idx = i + n;
		rep(j, 2)rep(k, 2)pd.add_edge(2 * n + j + k * 2, idx, INF, q - (a[idx] * (j ? -1 : 1) + b[idx] * (k ? -1 : 1)));
		pd.add_edge(idx, n * 2 + 5, c[idx], 0);
	}
	cout << q * sum- pd.solve(n * 2 + 4, n * 2 + 5, sum / 2) << endl;
	return 0;
}


Measured memory_bytes: 1920