#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
#include <math.h>
#include <queue>

using namespace std;

struct Block{
	Block(){
		cost = top = bottom = 0;
	}
	int cost,top,bottom;
};

int main(){
	int n,minimum,tmp;
	scanf("%d",&n);
	Block table[n][n];

	for(int i=0;i<n;i++){
		scanf("%d %d",&table[0][i].top,&table[0][i].bottom);
	}

	for(int col = 0; col <= n-2; col++){
		table[1][col].cost = table[0][col].top*table[0][col].bottom*table[0][col+1].top*table[0][col+1].bottom;
		//??????????±±??????????????????????????????????????????°?????????????????????????????????????
		if(table[0][col].top*table[0][col+1].bottom < table[0][col].bottom*table[0][col+1].top){
			table[1][col].top = table[0][col].top;
			table[1][col].bottom = table[0][col+1].bottom;
		}else{
			table[1][col].top = table[0][col+1].top;
			table[1][col].bottom = table[0][col].bottom;
		}
	}

	int min_div,min_multi;
	for(int row = 2; row <= n-1; row++){
		for(int col = 0; col <= n-(row+1); col++){
			minimum = 2147483647;

			for(int div = 0; div <= row-1;div++){
				tmp = (table[div][col+div].cost+table[row-div-1][col+div+1].cost)
						+(table[div][col+div].top*table[div][col+div].bottom*table[row-div-1][col+div+1].top*table[row-div-1][col+div+1].bottom);
				if(minimum > tmp){
					minimum = tmp;
					min_div = div;

					//????????¨????????????????°????????±?????????????
					if(table[div][col+div].top*table[row-div-1][col+div+1].bottom < table[div][col+div].bottom*table[row-div-1][col+div+1].top){
						min_multi = table[div][col+div].top*table[row-div-1][col+div+1].bottom;
					}else{
						min_multi = table[div][col+div].bottom*table[row-div-1][col+div+1].top;
					}
				}else if(minimum == tmp){ //????????????????????§??????????????¨????????????????????????????°???????????????????????????????????????¶
					if(table[div][col+div].top*table[row-div-1][col+div+1].bottom < table[div][col+div].bottom*table[row-div-1][col+div+1].top){
						if(min_multi > table[div][col+div].top*table[row-div-1][col+div+1].bottom){
							min_div = div;
						}
					}else{
						if(min_multi > table[div][col+div].bottom*table[row-div-1][col+div+1].top){
							min_div = div;
						}
					}
				}
			}
			table[row][col].cost = minimum;
			//???????????????????????¨?????????????¨??????????
			if(table[min_div][col+min_div].top*table[row-min_div-1][col+min_div+1].bottom < table[min_div][col+min_div].bottom*table[row-min_div-1][col+min_div+1].top){
				table[row][col].top = table[min_div][col+min_div].top;
				table[row][col].bottom = table[row-min_div-1][col+min_div+1].bottom;
			}else{
				table[row][col].top = table[row-min_div-1][col+min_div+1].top;
				table[row][col].bottom = table[min_div][col+min_div].bottom;
			}
		}
	}

	printf("%d\n",table[n-1][0].cost);

    return 0;
}