#include <iostream>
#include <vector>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;

const int INF = 1 << 30;

struct P{
	int top;
	int bottom;
};
int d[101][101];
int s[101][101];

vector <P> y;

int f (int a, int b, int c, int d )
{
	return (a*b*c*d);
}

void init_memo (int n )
{
	rep (i, n ){
		rep (j, n ){
			d[i][j] = INF;
		} // end rep
	} // end rep
}

int memoize (int i, int j )
{
	if (d[i][j] != INF )
		return d[i][j];

	int res = -1;
	if (i == j ){
		res = 0;
	}else{
		for (int k = i; k < j; k++ ){
			int q = memoize (i, k ) + memoize (k+1, j ) + f(y[i].top, y[k].bottom, y[k+1].top, y[j].bottom );
			if (q < d[i][j] ){
				res = q;
				d[i][j] = q;
				s[i][j] = k;
			} // end if
		} // end for
	} // end if

	return d[i][j] = res;
}

int main()
{
	int n;

	while (cin >> n && n ){
		init_memo (n );
		memset (s, 0, sizeof (s ) );
		y.resize(n );	
		for (int i = 0; i < n; i++ ){
			cin >> y[i].top >> y[i].bottom;
		} // end for
		memoize (0, n-1 );
		cout << d[0][n-1] << endl;
	} // end loop
		
	return 0;
}