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

#define MAX 101
#define Inf (UINT_MAX-1)

typedef unsigned long long int uint;
using namespace std;

struct State{
	State():cost(Inf),bottom(1),top(1){}
	uint cost;
	uint bottom;
	uint top;
};

State m[MAX][MAX];

void CardOrder(vector<pair<uint, uint> > &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){
				uint 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( cost < m[i][i+l-1].cost ){
					m[i][i+l-1].cost = cost;
					m[i][i+l-1].top = m[i][j].top;
					m[i][i+l-1].bottom = m[j+1][i+l-1].bottom;
				}
			}
		}
	}
}
void Reset(){
	for(int i = 0; i < MAX; ++i){
		for(int j = 0; j < MAX; ++j){
			m[i][j].cost = Inf;
			m[i][j].bottom = 1;
			m[i][j].top = 1;
		}
	}
}
int main()
{
	while( true ){
		int n;
		vector< pair<uint, uint> > vCards;
	
		cin >> n;

		if( cin.eof() )
			break;

		Reset();

		for(int x = 0; x < n; ++x){
			uint top, btm;
			cin >> top >> btm;

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