#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

//BEGIN CUT HERE
template<typename T>
struct PrimalDual{
    struct edge{
        int to;
        T cap,cost;
        int rev;
        edge(){}
        edge(int to,T cap,T cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
    };
    
    T INF;
    vector<vector<edge> > G;
    vector<T> h,dist;
    vector<int> prevv,preve;
    
    PrimalDual(){}
    PrimalDual(int n,T INF):INF(INF),G(n),h(n),dist(n),prevv(n),preve(n){}
    
    void add_edge(int from,int to,T cap,T cost){
        G[from].emplace_back(to,cap,cost,G[to].size());
        G[to].emplace_back(from,0,-cost,G[from].size()-1);
    }
    
    T flow(int s,int t,T f,int &ok){
        T res=0;
        fill(h.begin(),h.end(),0);
        while(f>0){
            struct P{
                T first;
                int second;
                P(T first,int second):first(first),second(second){}
                bool operator<(const P&a) const{return first>a.first;}
            };
            priority_queue<P> que;
            fill(dist.begin(),dist.end(),INF);
            
            dist[s]=0;
            que.emplace(dist[s],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<(int)G[v].size();i++){
                    edge &e=G[v][i];
                    if(e.cap==0) continue;
                    if(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.emplace(dist[e.to],e.to);
                    }
                }
            }
            if(dist[t]==INF) return ok=0;
            
            for(int v=0;v<(int)h.size();v++) h[v]+=dist[v];
            
            T 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;
            }
        }
        ok=1;
        return res;
    }
};
//END CUT HERE

const ll INF=1e15;
const ll C=MOD*2;

ll dist(pll a,pll b){return abs(a.F-b.F)+abs(a.S-b.S);}

int main(){
    ll n;
    cin>>n;
    PrimalDual<ll> P(n*2+6,INF);
    ll s=n*2;
    ll g=s+1;
    ll ty=g+1;
    vector<pair<pll,ll>> A(n),B(n);
    cin>>A>>B;
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=A[i].S;
        P.add_edge(s,i,A[i].S,0);
        P.add_edge(n+i,g,B[i].S,0);
        for(int j=0;j<4;j++){
            P.add_edge(i,ty+j,INF,(j&1?-1:1)*A[i].F.F+(j&2?-1:1)*A[i].F.S+C);
            P.add_edge(ty+j,n+i,INF,(j&1?1:-1)*B[i].F.F+(j&2?1:-1)*B[i].F.S+C);
        }
    }
    int ok=1;
    cout<<C*sum*2-P.flow(s,g,sum,ok)<<endl;
    assert(ok);
    
    return 0;
}


Measured memory_bytes: 1492