
object Main extends App {

  import scala.io.StdIn._

  val n = readInt()
  val piles = Array.tabulate(n){_ ⇒
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
    Pile(b, a)
  }
  println(solve(piles))
  def solve(piles: Array[Pile]): Int = {
    val memo = Array.tabulate(piles.length){i ⇒ Array.tabulate(piles.length - i){_ ⇒ None: Option[Int]}}
    memo.indices.foreach(i ⇒ memo(i)(0) = Some(0))
    def sub(left: Int, right: Int): Int = {
      memo(left)(right - left) match {
        case Some(r) ⇒ r
        case None ⇒ (left until right).map{mid ⇒ sub(left, mid) + sub(mid + 1, right) + piles(left).top * piles(mid).bottom * piles(mid + 1).top * piles(right).bottom}.min.also(m ⇒ memo(left)(right - left) = Some(m))
      }
    }
    sub(0, piles.length - 1)
  }
  case class Pile(bottom: Int, top: Int) {
    def merge(right: Pile): Pile = Pile(right.bottom, top)
    def cost(right: Pile): Int = bottom * top * right.bottom * right.top
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}
