
def lay(stocks)
  nst = stocks.length
  return 0 if nst <= 1

  ims = (0..(nst - 2)).map{|i| [i, stocks[i][1] * stocks[i + 1][0]]}
  is = ims.sort{|a, b| b[1] <=> a[1]}.map{|im| im[0]}

  sum = 0

  for i in is
    st0 = stocks[i]
    while ! st0[2].nil?
      st0 = st0[2]
    end

    st1 = stocks[i + 1]
    while ! st1[2].nil?
      st0 = st1[2]
    end

    sum += st0[0] * st0[1] * st1[0] * st1[1]

    st0[1] = st1[1]
    st1[2] = st0
  end

  sum
end

### main

n = gets.strip.to_i

stocks = n.times.map{gets.strip.split(' ').map{|s| s.to_i}}

puts lay(stocks)