#include<iostream>
#include<vector>
#include<climits>

#define MAX 101
#define Inf (UINT_MAX-1)
using namespace std;

struct State{
	State():cost(Inf),bottom(-1),top(-1){
	}
	unsigned int cost;
	int bottom;
	int top;
};

State m[MAX][MAX];

void CardOrder(vector<pair<int, int> > &vc){
	int n = vc.size();
	for(int i = 1; i <= n; ++i){
		m[i][i].cost = 0;
		m[i][i].top = vc[i-1].first;
		m[i][i].bottom = vc[i-1].second;
	}
	for(int l = 2; l <= n; ++l){
		for(int i = 1; i <= n - l + 1; ++i){
			for(int j = i; j < i + l; ++j){
				unsigned int cost = m[i][j].cost + m[j+1][i+l-1].cost +
					m[i][j].top * m[i][j].bottom * m[j+1][i+l-1].top * m[j+1][i+l-1].bottom;
				if( m[i][i+l-1].cost > cost ){
					m[i][i+l-1].cost = cost;
					if( m[i][j].top * m[j+1][i+l-1].bottom < m[j+1][i+l-1].top * m[i][j].bottom ){
						m[i][i+l-1].top = m[i][j].top;
						m[i][i+l-1].bottom = m[j+1][i+l-1].bottom;
					}else{
						m[i][i+l-1].top = m[j+1][i+l-1].top;
						m[i][i+l-1].bottom = m[i][j].bottom;
					}
				}
			}
		}
	}
}

int main()
{
	int n;
	vector< pair<int, int> > vCards;
	
	cin >> n;
	for(int x = 0; x < n; ++x){
		int top, btm;
		cin >> top >> btm;

		vCards.push_back( make_pair(top, btm) );
	}
	
	CardOrder( vCards );
	cout << m[1][n].cost << '\n';
	return 0;
}