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

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

const int INF = (1 << 24);

void main() {
  long times; scanf("%d", &times);
  long[][] dp = new long[][](times, times);
  Bundle[] cards;
  foreach(t; 0..times) {
    long 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(long len = 1; len < times; len++) {
    for(long s = 0; s + len < times; s++) {
      long f = s + len;
      for(long i = s; i < f; i++) {
        long cost =
          (cards[i].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]);
}