#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;
const ll INF = (1LL<<50);
const int MAX = 101;

ll dp[MAX][MAX];
int T[MAX],B[MAX];

int main(){

  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> T[i] >> B[i];
 
  fill(dp[0],dp[0]+MAX*MAX,INF);
  for(int i = 0; i < MAX; i++) dp[i][i] = 0;

  for(int i = 0; i < n; i++)
    for(int j = i+1; j < n; j++)
      for(int k = i+1; k <= j; k++)
	dp[i][j] = min(dp[i][j],dp[i][k-1]+dp[k][j]+B[i]*T[k-1]*B[k]*T[j]);
  
  cout << dp[0][n-1] << endl;
  return 0;
}