
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, times);
  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 - 1; i++) dp[i][i] = 0;
  dp[times - 1][times - 1] = 0;
  
  // dp[i][j] -> i 番目 から j 番目を計算する時の最適コスト
  for(uint len = 1; len < times; len++) {
    for(uint s = 0; s + len < times; s++) {
      int f = s + len;
      for(uint i = s; i < f; i++) {
        uint cost =
          (cards[s].top * cards[i].bottom) * (cards[i + 1].top * cards[f].bottom);
        cost += dp[s][i] + dp[i + 1][f];
        if (cost < dp[s][f]) dp[s][f] = cost;
      }
    }
  }
  writeln(dp[0][times - 1]);
}