Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	var n int
	var M [101][101]int

	n = nextInt()

	P := make([]int, n*2)

	for i := 1; i <= n; i++ {
		P[i-1] = nextInt()
		P[i] = nextInt()
	}
	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			M[i][j] = 1000000
			for k := i; k <= j-1; k++ {
				M[i][j] = int(math.Min(float64(M[i][j]), float64(M[i][k]+M[k+1][j]+P[i-1]*P[k]*P[j])))
			}
		}
	}
	fmt.Println(M[1][n])
}

C++: //#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll r[105], c[105], DP[105][105];

ll Calc(int L, int R){
  if (DP[L][R] != 0) return DP[L][R];
  if (L == R) return DP[L][R] = 0;

  ll ans = INF;
  for (int k = L; k < R; k++){
    ll now = r[L] * c[k] * c[R];
    now += Calc(L, k) + Calc(k + 1, R);
    ans = min(now, ans);
  }
  
  return DP[L][R] = ans;
}

int main(){
  cin >> N;
  for (int i = 0; i < N; i++) cin >> r[i] >> c[i]; 
  cout << Calc(0, N - 1) << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000;
long long matrix_chain_multiplication(vector<long long> &A){
    int n = A.size() - 1;
    vector<vector<long long>> dp(n, vector<long long>(n, INF));
    for (int i = 0; i < n; i++){
        dp[i][i] = 0;
    }
    for (int i = 1; i < n; i++){
        for (int j = 0; j < n - i; j++){
            for (int k = j; k < j + i; k++){
                dp[j][j + i] = min(dp[j][j + i], dp[j][k] + dp[k + 1][j + i] + A[j] * A[k + 1] * A[j + i + 1]);
            }
        }
    }
    return dp[0][n - 1];
}
int main(){
  int n;
  cin >> n;
  vector<long long> H(n + 1);
  for (int i = 0; i < n; i++){
    cin >> H[i] >> H[i + 1];
  }
  cout << matrix_chain_multiplication(H) << endl;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int N;
int r[105],c[105];
ll dp[105][105]={0};

void dbg()
{
	for(int i=0;i<N;i++,puts(""))
		for(int j=0;j<N;j++)
			printf("%7d ",dp[i][j]);
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
		scanf("%d%d",&r[i],&c[i]);
	for(int i=0;i<N;i++)dp[i][i]=0;
	for(int l=1;l<N;l++)
		for(int i=0;i<N-l;i++)
		{
			int j=i+l;
			dp[i][j]=10000000;
			for(int k=0;k<j;k++)
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*c[k]*c[j]);
		}
	printf("%d\n",dp[0][N-1]);
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;

static const int N = 100;

int main(){
int n,p[N+1],m[N+1][N+1];
cin >> n;

for(int i=1;i<=n;i++){
cin >> p[i-1] >> p[i];
}

for(int i=1;i<=n;i++) m[i][i]=0;
for(int l=2;l<=n;l++){
for(int i=1;i<=n-l+1;i++){
int j=i+l-1;
m[i][j]=(1 << 21);
for(int k = i;k<=j-1;k++){
m[i][j]=min(m[i][j],m[i][k]+m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
}
}
}
cout << m[1][n] << endl;

return 0;

}

C++: #include<iostream>
#include<algorithm>
using namespace std;

static const int N=100;

int main(){
  int n,p[N+1],m[N+1][N+1];
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>p[i-1]>>p[i];
  }

  for(int i=1;i<=n;i++) m[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      m[i][j]=(1<<21);
      for(int k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }

  cout<<m[1][n]<<endl;

  return 0;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;


int n, r[109], c[109];
long long dp[109][109];

const long long MAX = __LONG_LONG_MAX__;

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)dp[i][j] = MAX;
  }
  for(int i=0;i<n;i++)cin >> r[i] >> c[i];
  for(int i=0;i<n;i++)dp[i][i] = 0;
  for(int i=1;i<n;i++){
    for(int j=0;j+i<n;j++){
      for(int k=0;k<i;k++){
        dp[j][j+i] = min(dp[j][j+i], dp[j][j+k]+dp[j+k+1][j+i] + r[j]*c[j+k]*c[j+i]);
      }
    }
  }
  cout << dp[0][n-1] << endl;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;

static const int N=100;

int main()
{
  int n,p[N+1],m[N+1][N+1];
  cin >> n;
  for(int i=1; i<=n; i++)
    {
      cin>>p[i-1]>>p[i];
    }

  for(int i=1;i<=n;i++)
    {
    m[i][i]=0;
    }
  for(int l=2;l<=n;l++)
    x{
      for(int i=1; i<=n-l+1;i++)
	{
	  int j=i+l-1;
	  m[i][j]=(1<<21);
	  for(int k=i;k<=j-1;k++)
	    {
	      m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
	    }
	}
    }
  cout<<m[1][n]<<endl;

  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
int C[101];
int dp[100][100];
const int INFTY = (1 << 30);

int main() {
	cin >> N;
	rep(i, N) cin >> C[i] >> C[i+1];

	rep(y, N) rep(x , N) dp[y][x] = INFTY;

	rep(y, N) dp[y][y] = 0;

	for(int d = 1; d < N; d++)
		for(int y = 0; d + y < N; y++){
			for (int dd = 0; dd < d; dd++) {
				int m1_s = y;
				int m1_e = y+dd;
				int m2_s = y+dd+1;
				int m2_e = y+d;

				int cl = C[m1_s] * C[m2_s] * C[m2_e + 1];
				dp[m1_s][m2_e] = min(dp[m1_s][m2_e], dp[m1_s][m1_e] + dp[m2_s][m2_e] + cl);
			}
		}
	cout << dp[0][N-1] << endl;

}

C++: #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;
}