#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
class edge {
public:
    int to;
    llint cap;
    llint cost;
    int rev;
    bool isrev;
};
edge make_edge(int a,int b,int c,int d,bool e){
	edge x;
	x.to=a;
	x.cap=b;
	x.cost=c;
	x.rev=d;
	x.isrev=e;
	return x;
}
template< typename flow_t, typename cost_t >
struct PrimalDual {
  const cost_t INF;

 
  vector< vector< edge > > graph;
  vector< cost_t > potential, min_cost;
  vector< int > prevv, preve;

  PrimalDual(int V) : graph(V), INF(numeric_limits< cost_t >::max()) {}

  void add_edge(int from, int to, flow_t cap, cost_t cost) {
    graph[from].emplace_back(make_edge(to, cap, cost, (int) graph[to].size(), false));
    graph[to].emplace_back(make_edge(from, 0, -cost, (int) graph[from].size() - 1, true));
  }

  cost_t min_cost_flow(int s, int t, flow_t f) {
    int V = (int) graph.size();
    cost_t ret = 0;
    using Pi = pair< cost_t, int >;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    potential.assign(V, 0);
    preve.assign(V, -1);
    prevv.assign(V, -1);

    while(f > 0) {
      min_cost.assign(V, INF);
      que.emplace(0, s);
      min_cost[s] = 0;
      while(!que.empty()) {
        Pi p = que.top();
        que.pop();
        if(min_cost[p.second] < p.first) continue;
        for(int i = 0; i < graph[p.second].size(); i++) {
          edge &e = graph[p.second][i];
          cost_t nextCost = min_cost[p.second] + e.cost + potential[p.second] - potential[e.to];
          if(e.cap > 0 && min_cost[e.to] > nextCost) {
            min_cost[e.to] = nextCost;
            prevv[e.to] = p.second, preve[e.to] = i;
            que.emplace(min_cost[e.to], e.to);
          }
        }
      }
      if(min_cost[t] == INF) return -1;
      for(int v = 0; v < V; v++) potential[v] += min_cost[v];
      flow_t addflow = f;
      for(int v = t; v != s; v = prevv[v]) {
        addflow = min(addflow, graph[prevv[v]][preve[v]].cap);
      }
      f -= addflow;
      ret += addflow * potential[t];
      for(int v = t; v != s; v = prevv[v]) {
        edge &e = graph[prevv[v]][preve[v]];
        e.cap -= addflow;
        graph[v][e.rev].cap += addflow;
      }
    }
    return ret;
  }

  void output() {
    for(int i = 0; i < graph.size(); i++) {
      for(auto &e : graph[i]) {
        if(e.isrev) continue;
        auto &rev_e = graph[e.to][e.rev];
        cerr << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << rev_e.cap + e.cap << ")" << endl;
      }
    }
  }
};

int main(void){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m,i;cin>>n;m=n+n;
	PrimalDual<llint,llint> gra(m+6);
	llint ans=0,wa=0;
	for(i=0;i<n;i++){
		llint x,y,c;cin>>x>>y>>c;
		wa+=c;
		gra.add_edge(m,i,c,0);
		gra.add_edge(i,m+2,c,x+y);
		gra.add_edge(i,m+3,c,mod-x+y);
		gra.add_edge(i,m+4,c,x+mod-y);
		gra.add_edge(i,m+5,c,mod-x+mod-y);
	}
	for(i=n;i<n+n;i++){
		llint x,y,c;cin>>x>>y>>c;
		gra.add_edge(i,m+1,c,0);
		gra.add_edge(m+5,i,c,x+y);
		gra.add_edge(m+4,i,c,mod-x+y);
		gra.add_edge(m+3,i,c,x+mod-y);
		gra.add_edge(m+2,i,c,mod-x+mod-y);
	}
	cout<<wa*mod*2-gra.min_cost_flow(m,m+1,wa)<<endl;
	return 0;
}


Measured memory_bytes: 1408