#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

// O(n^3)
// dp[i][j] := [i,j]????¨???????????????????????°?????????????????????°
// i??????????????????(?????°????????°)??????(p[i - 1], p[i])
int matrixChainMultiplication(int n, pair<int, int> p[105]){
    int dp[105][105] = {{0}};
    range(seg, 2, n + 1){ //?¨????????????????????????°
        range(i, 0, n - seg + 1){
            int j = i + seg - 1;
            dp[i][j] = INT_MAX;
            range(k,i,j){
                //cout << i << ' ' << k << ' ' << j << endl;
                //show(dp[i][k])
                //show(dp[k + 1][j])
                //show(p[i].second * p[k].first * p[k + 1].second * p[j].first);
                int cost = dp[i][k] + dp[k + 1][j] + p[i].second * p[k].first * p[k + 1].second * p[j].first;
                //show(cost)
                dp[i][j] = min(dp[i][j], cost);
            }
        }
    }
    return dp[0][n - 1];
}

int main(){
    int n;
    cin >> n;

    pair<int, int> p[105];
    rep(i,n) cin >> p[i].second >> p[i].first;
    cout << matrixChainMultiplication(n,p) << endl;
}