#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i=0; i<n; ++i)
        cin >> a[i] >> b[i];

    vector<vector<long long> > cost(n, vector<long long>(n, INT_MAX));
    for(int i=0; i<n; ++i)
        cost[i][i] = 0;
    for(int i=1; i<n; ++i){
        for(int j=0; j+i<n; ++j){
            for(int k=j; k<j+i; ++k){
                long long c = cost[j][k] + cost[k+1][j+i] + b[j] * a[k] * b[k+1] * a[j+i];
                cost[j][j+i] = min(cost[j][j+i], c);
            }
        }
    }
    cout << cost[0][n-1] << endl;

    return 0;
}