#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

//jから始まる長さiのスタックの最小コスト
ll dp[110][110];

int main(){
    int n;
    cin >> n;
    vector<pair<ll,ll>> v;
    REP(i,n) {
        int t,b;
        cin >> t >> b;
        v.pb({t,b});
    }
    REP(i,110) REP(j,110) dp[i][j] = inf;
    for (int w = 1; w <= n; w++) {
        for (int from = 0; from + w - 1 < n; from++) {
            int to = from + w - 1;
            if (from == to) {
                dp[w][from] = 0;
                continue;
            }
            for (int l1 = 1; l1 < w; l1++) {
                int l2 = w - l1;
                dp[w][from] = min(dp[w][from], dp[l1][from] + dp[l2][from + l1] + v[from].fi * v[from + l1 - 1].se * v[from + l1].fi * v[to].se);
            }
        }
    }
    // for (int i = 0; i <= n; i++) {
    //     for (int j = 0; j <= n; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[n][0] << endl;
}
