
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int p[101];
int M[101][101];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n + 1; i++) {
		cin >> p[i - 1] >> p[i];
	}
	for (int i = 1; i < n + 1; i++)M[i][i] = 0;
	for (int i = 2; i < n + 1; i++) {
		for (int j = 1; j + i - 1 < n + 1; j++) {
			int k = j + i - 1;
			M[j][k] = (1 << 21);
			for (int t = j; t < k; t++) {
				M[j][k] = min(
					M[j][t] + M[t + 1][k] + p[j - 1] * p[t] * p[k],
					M[j][k]
				);
			}
		}
	}
	cout << M[1][n] << endl;
}
