#include <iostream>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
struct BOOK{
	int a,b,c,d;
	BOOK(int x,int y,int z,int aa){a = x , b = y , c = z , d = aa;}
};
bool operator < (const BOOK &a,const BOOK &b){return a.a * a.b > b.a * b.b;}

bool done[100][100][100];

int main(){
	int n;
	ll a,b;
	cin >> n;
	priority_queue<BOOK> Q;
	rep(i,n) cin >> a >> b , Q.push(BOOK(a,b,1,0));
	while(Q.top().c != n){
		BOOK one = Q.top(); Q.pop();
		BOOK two = Q.top(); Q.pop();
		Q.push(BOOK(one.a , two.b , one.c+two.c , one.d + two.d + one.a * one.b * two.a * two.b));
		Q.push(BOOK(two.a , one.b , one.c+two.c , one.d + two.d + one.a * one.b * two.a * two.b));		
	}
	cout << Q.top().d << endl;
}