#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define MAX_N 100
#define INF 1000000000


int N;
int r[MAX_N],c[MAX_N];
int memo[MAX_N][MAX_N];
int saiki(int i ,int j){
    if(memo[i][j] > -1)
        return memo[i][j];
    if(i == j)
        return 0;
    int mini = INF;
    FOR(k,i,j){
        mini = min(mini,saiki(i,k) + saiki(k + 1,j) + r[i] * c[k] * c[j]);
    }
    return memo[i][j] = mini;
}

int main(){
    scanf("%d",&N);
    REP(i,N){
        scanf("%d%d",&r[i],&c[i]);
    }
    REP(i,N)REP(j,N)memo[i][j] = -1;
    printf("%d\n",saiki(0,N-1));
    return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>

using namespace std;
int INF = 100000000;

struct Matrix { int row, col; };

int getMinMCM(const vector<Matrix>& matVec) {
	const size_t n = matVec.size();
	//table(i,num)は、与えられた行列積のindex=i(0始まり）の行列から、num個先の行列までの積についてのMCM最小値を記録する
	//（ table.at(0).at(n - 1) が求まると、与えられた行列積全体のMCMが求まる ）
	vector< vector<int> > table(n, vector<int>(n, 0));
	for (size_t num = 1; num != n; ++num) {
		const size_t end = n - num;
		for (size_t i = 0; i != end; ++i) {
			const Matrix& matI = matVec.at(i);
			const Matrix& matNum = matVec.at(i+num);
			int& target = table.at(i).at(num);
			target = INF;
			int end2 = i + num;
			for (int j = i; j != end2; ++j) {
				const Matrix& matJ = matVec.at(j);
				target = min(target, matI.row * matJ.col * matNum.col + table.at(i).at(j - i) + table.at(j + 1).at(num+i-j-1));
			}

		}
	}
	return table.at(0).at(n - 1);
}

template<typename T>
void execute(T& cin) {
	int n;
	cin >> n;
	vector<Matrix> m(n);
	for (auto& matrix : m)cin >> matrix.row >> matrix.col;
	cout << getMinMCM(m) << endl;

}

int main()
{
	execute(cin);

	return 0;
}
