
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;

struct Pair{int top,bottom;};

int main()
{
  vector<int> order;
  vector<Pair> card;
  Pair p;
  int n,i,min,cost;
  cin>>n;
  order.resize(n);
  card.resize(n);
  for(i=0;i<n;i++){
    cin>>p.top>>p.bottom;
    card[i]=p;
    order[i]=i;
  }
  min=INT_MAX;
  do{
    cost=0;
    for(i=1;i<n;i++)cost+=card[0].bottom*card[i-1].top*card[i].bottom*card[i].top;
    if(cost<min)min=cost;
  }while(next_permutation(order.begin(),order.end()));
  cout<<min<<endl;
}