T, B = 0, 1
n = gets.to_i
deck = n.times.map{gets.split.map(&:to_i)}

dp = Array.new(n){Array.new(n){1<<32}}
n.times do |i| dp[i][i] = 0 end
(1 ... n).each do |d|
  (0 ... n - d).each do |i|
    (i ... i + d).each do |j|
      dp[i][i + d] = [dp[i][i + d], dp[i][j] + dp[j + 1][i + d] + deck[i][T] * deck[j][B] * deck[j + 1][T] * deck[i + d][B]].min
    end
  end
end
p dp[0][n - 1]