#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;


typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, P> data;
const ll INF = 1LL <<50;

data dp[200][200];

ll mul(data d1, data d2){
  return d1.second.first * d1.second.second * d2.second.first * d2.second.second;
}

P get_minP(data d1, data d2){
  int a = d1.second.first * d2.second.second;
  int b = d2.second.first * d1.second.second;
  if(a < b) return P(d1.second.first, d2.second.second);
  else return P(d2.second.first, d1.second.second);
}

int main(){
  int n;
  while(cin >> n && n){
    fill(&dp[0][0], &dp[199][199] + 1, data(INF, P(0, 0)));
    rep(i, n){
      cin >> dp[i][1].second.first >> dp[i][1].second.second;
      dp[i][1].first = 0;
    }
    rep2(i, 2, n + 1){
      rep(j, n - i + 1){
	rep2(k, j + 1, j + i){
	  ll cost = dp[j][k-j].first + dp[k][i-(k-j)].first + mul(dp[j][k-j], dp[k][i-(k-j)]);
	  P m = get_minP(dp[j][k-j], dp[k][i-(k-j)]);
	  if(cost < dp[j][i].first || cost == dp[j][i].first
	     && m.first * m.second < dp[j][i].second.first * dp[j][i].second.second){
	    dp[j][i] = data(cost, m);
	  }
	}
      }
    }
    cout << dp[0][n].first << endl;
  }
  return 0;
}