import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._
object Main extends App {

  case class Edge(to: Int, pair: Int, cost: Long, var flow: Int)
  case class Coordinate(x: Long, y: Long)
  val n = readInt()
  val reds = Array.tabulate(n){_ ⇒
    val Array(x, y, c) = readLine.trim.split(' ').map(_.toInt)
    (Coordinate(x, y), c)
  }
  val blues = Array.tabulate(n){_ ⇒
    val Array(x, y, c) = readLine.trim.split(' ').map(_.toInt)
    (Coordinate(x, y), c)
  }
  val start = 2 * n
  val drain = start + 1
  val midNode = drain + 1
  val nodes = Array.fill(2 * n + 6){ArrayBuffer[Edge]()}
  for (i ← 0 until n) {
    nodes(i).append(Edge(start, nodes(start).length, 0, 0))
    nodes(start).append(Edge(i, 0, 0, reds(i)._2))
    nodes(n + i).append(Edge(drain, nodes(drain).length, 0, blues(i)._2))
    nodes(drain).append(Edge(n + i, 0, 0, 0))
  }
  for (t ← 0 until 4) {
    for (i ← 0 until n){
      nodes(i).append(Edge(midNode + t, nodes(midNode + t).length, 2000000000L + (if ((t & 2) != 0) reds(i)._1.x else -reds(i)._1.x) + (if ((t & 1) != 0) reds(i)._1.y else -reds(i)._1.y) , 10))
      nodes(midNode + t).append(Edge(i, nodes(i).length - 1, -2000000000L + (if ((t & 2) != 0) -reds(i)._1.x else reds(i)._1.x) + (if ((t & 1) != 0) -reds(i)._1.y else reds(i)._1.y), 0))
      nodes(n + i).append(Edge(midNode + t, nodes(midNode + t).length, -2000000000L + (if ((t & 2) == 0) -blues(i)._1.x else blues(i)._1.x) + (if ((t & 1) == 0) -blues(i)._1.y else blues(i)._1.y), 0))
      nodes(midNode + t).append(Edge(n + i, nodes(n + i).length - 1, 2000000000L + (if ((t & 2) == 0) blues(i)._1.x else -blues(i)._1.x) + (if ((t & 1) == 0) blues(i)._1.y else -blues(i)._1.y), 10))
    }
  }
  val potential = Array.fill(nodes.length){0L}
  val minCost = Array.fill(nodes.length){Long.MaxValue}
  val prev = Array.fill(nodes.length){nodes.head.head}
  val queue = mutable.PriorityQueue[(Long, Int)]()(Ordering.by[(Long, Int), Long](_._1).reverse)
  var flow = true
  var cost = 0L
  while (flow) {
    flow = false
    minCost(start) = 0
    queue.enqueue((0, start))
    while (queue.nonEmpty) {
      val (cost, current) = queue.dequeue()
      if (minCost(current) == cost && current != drain) {
        for (next ← nodes(current) if next.flow > 0) {
          if (minCost(next.to) > potential(next.to) + cost + next.cost - potential(current)) {
            minCost(next.to) = potential(next.to) + cost + next.cost - potential(current)
            prev(next.to) = nodes(next.to)(next.pair)
            queue.enqueue((minCost(next.to), next.to))
          }
        }
      }
    }
    flow = minCost(drain) != Long.MaxValue
    if (flow) {
      var last = drain
      var minFlow = Int.MaxValue
      while (last != start) {
        minFlow = Math.min(nodes(prev(last).to)(prev(last).pair).flow, minFlow)
        last = prev(last).to
      }
      cost += minFlow * minCost(drain)
      last = drain
      while (last != start) {
        val e = prev(last)
        e.flow += minFlow
        nodes(e.to)(e.pair).flow -= minFlow
        last = e.to
      }
      for (i ← potential.indices if i != drain && minCost(i) != Long.MaxValue) {
        potential(i) += minCost(i)
        minCost(i) = Long.MaxValue
      }
      minCost(drain) = Long.MaxValue
    }
  }
  println(reds.map{_._2.toLong}.sum * 4000000000L - cost)
}