#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;
const long long INF = 1e9 + 5;
using namespace std;

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

    pair<long long, long long> p[105];
    rep(i,n) cin >> p[i].first >> p[i].second;

    vector<vector<vector<long long>>> dp(105,vector<vector<long long>>(205,vector<long long>(205,INF)));
    rep(l,n){
        for(int i = n; i > 1; i--){
            range(j,1,201){
                range(k,1,201){
                    long long next = dp[i - 1][j][k] + j * k * p[l].first * p[l].second;
                    dp[i][j][p[l].second] = min(dp[i][j][p[l].second], next);
                    dp[i][p[l].first][k] = min(dp[i][p[l].first][k], next);
                }
            }
        }
        dp[1][p[l].first][p[l].second] = 0;
    }

    long long mini = INF;
    rep(i,201) rep(j,201)  mini = min(mini, dp[n][i][j]);
    cout << mini << endl;
}