#include<iostream> #include<vector> #include<algorithm> const int Max = 1 << 30; using namespace std; int n; vector<int> dim; int m[1010][1010]; int main() { cin >> n; int p1, p2; scanf("%d%d", &p1, &p2); dim.push_back(p1); dim.push_back(p2); for (int i = 1; i < n; i++) { scanf("%d%d", &p1, &p2); dim.push_back(p2); } for (int i = 1; i <= n; i++) m[i][i] = 0; for (int c = 2; c <= n; c++) for (int i = 1; i <= n - c + 1; i++){ int j = i + c - 1; m[i][j] = Max; for (int k = i; k <= j - 1; k++) { int q = (m[i][k] + m[k + 1][j] + dim[i - 1] * dim[k] * dim[j]); if (q < m[i][j]) m[i][j] = q; } } cout << m[1][n] << endl; return 0; }