
import std.stdio, std.typecons, std.algorithm;

alias Tuple!(int, "top", int, "bottom") Bundle;

const int INF = (1 << 24);

void main() {
  uint times; scanf("%d", &times);
  uint[][] dp = new uint[][](times + 1, times + 1);
  Bundle[] cards;
  foreach(t; 0..times) {
    uint top, bottom; scanf("%d %d", &top, &bottom);
    cards ~= Bundle(top, bottom);
  }
  
  foreach(ref d; dp)
    foreach(ref x; d) x = INF;
  for(int i = 0; i < times; i++)
    for(int j = 0; j <= i + 1; j++) dp[i][j] = 0;
  
  // dp[i][j] -> i 番目 から j 番目を計算する時の最適コスト
  for(uint i = 0; i < times; i++) {
    for(uint j = i + 1; j < times; j++) {
      for(uint k = i + 1; k <= j; k++) {
        uint cost =
          (cards[i].top * cards[k - 1].bottom) * (cards[k].top * cards[j].bottom);
        cost += dp[i][k - 1] + dp[k][j];
        if (cost < dp[i][k]) dp[i][k] = cost;
      }
    }
  }
  writeln(dp[0][times - 1]);
}