#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll INF = (1LL<<34);
P t[100];
ll dp[100][100];
 
P on(P x,P y){
  return P(x.first,y.second);
}
 
ll cost(P x,P y){
  return x.first*x.second*y.first*y.second;
}
 
int compute(int a,int b){
  ll A,B;
  if(dp[a][b]!=-1)return dp[a][b];
  if(a==b)return 0;
  
 
  ll res=INF;
  ll sum;
  P X,Y;
  for(int i=a;i<b;i++){
    X=on(t[a],t[i]);
    Y=on(t[i+1],t[b]);
     
    sum=cost(X,Y);
    sum = compute(a,i)+ sum +compute(i+1,b) ;
    res=(sum<res?sum:res);
 
  }
  dp[a][b]=res;
  return res;
}
 
int main(){
 
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>t[i].first>>t[i].second;
    for(int i=0;i<100;i++)for(int j=0;j<100;j++)dp[i][j]=-1;
    cout<<compute(0,n-1)<<endl;
  }
  return 0;
}