// https://atcoder.jp/contests/agc034/tasks/agc034_d
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

type Capacity = i64;
type Cost = i64;
type Graph = Vec<Vec<Edge>>;
type Edge = (usize, usize, Capacity, Cost); // (to_index, rev_index, cap, cost)

const INF: Capacity = 1e12 as Capacity;

struct MinCostFlow {
    n: usize,
    graph: Graph,
}

type State = (i64, usize);

impl MinCostFlow {
    fn new(n: usize) -> Self {
        MinCostFlow {
            n: n,
            graph: vec![vec![]; n],
        }
    }

    fn add_edge(&mut self, u: usize, v: usize, cap: Capacity, cost: Cost) {
        let udeg = self.graph[u].len();
        let vdeg = self.graph[v].len();
        self.graph[u].push((v, vdeg, cap, cost));
        self.graph[v].push((u, udeg, 0, -cost));
    }

    fn min_cost_flow(&mut self, from: usize, to: usize, flow: Capacity) -> Cost {
        let n = self.graph.len();
        let mut flow = flow;
        let mut ans = 0;

        let mut h = vec![0; n];
        let mut from_v = vec![vec![0; 2]; n];

        while flow > 0 {
            let mut dist = vec![INF; n];
            dist[from] = 0;

            let mut q = BinaryHeap::new();
            q.push((0, from));
            while q.len() >= 1 {
                let state = q.pop().unwrap();
                let now = state.1;
                let val = -state.0;
                if dist[now] < val {
                    continue;
                }
                let mut ii = 0;
                for &e in &self.graph[now] {
                    let tval = dist[now] + e.3 + h[now] - h[e.0];
                    if e.2 > 0 && dist[e.0] > tval {
                        dist[e.0] = tval;
                        from_v[e.0][0] = now;
                        from_v[e.0][1] = ii;
                        q.push((-tval, e.0));
                    }
                    ii += 1;
                }
            }
            if dist[to] == INF {
                return ans;
            }

            for i in 0..n {
                h[i] += dist[i];
            }

            {
                let mut min_cap = flow;
                let mut tt = to;
                while tt != from {
                    min_cap = min(min_cap, self.graph[from_v[tt][0]][from_v[tt][1]].2);
                    tt = from_v[tt][0];
                }
                flow -= min_cap;
                ans += min_cap * h[to];
                let mut tt = to;
                while tt != from {
                    self.graph[from_v[tt][0]][from_v[tt][1]].2 -= min_cap;
                    let e = self.graph[from_v[tt][0]][from_v[tt][1]];
                    self.graph[tt][e.1].2 += min_cap;
                    tt = from_v[tt][0];
                }
            }
        }
        ans
    }
}

fn main() {
    input! {
        n: usize,
        reds: [(i64, i64, i64); n],
        blues: [(i64, i64, i64); n],
    };

    // [0, n): red
    // [n, 2n): blue
    // [2n, 2n+4): center
    // 2n+4: source
    // 2n+5: sink
    let mut min_cost_flow = MinCostFlow::new(2*n+2+4);
    let offset = 2000000000;
    let source = 2*n+4;
    let sink = 2*n+5;

    let mut total_flow = 0;
    for i in 0..n {
        total_flow += reds[i].2;
        min_cost_flow.add_edge(source, i, reds[i].2 as Capacity, 0);
        for j in 0..2 {
            for k in 0..2 {
                let tj = j as i64 * 2 - 1;
                let tk = k as i64 * 2 - 1;
                min_cost_flow.add_edge(i, 2*n+j*2+k, reds[i].2 as Capacity,      (reds[i].0 * tj) +  (reds[i].1 * tk) + offset);
                min_cost_flow.add_edge(2*n+j*2+k, n+i, blues[i].2 as Capacity, -(blues[i].0 * tj) - (blues[i].1 * tk) + offset);
            }
        }
        min_cost_flow.add_edge(n+i, sink, blues[i].2 as Capacity, 0);
    }

    println!("{}", total_flow * offset * 2 - min_cost_flow.min_cost_flow(source, sink, total_flow));
}


Measured memory_bytes: 4352