Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

type matrixSize struct{ row, col int }

func calcNum(i, j matrixSize) int {
	return i.row * j.col * i.col
}

func parseProblem() (int, []matrixSize) {
	n := scanInt(sc)
	sizes := make([]matrixSize, n)
	for i := 0; i < n; i++ {
		sizes[i] = matrixSize{row: scanInt(sc), col: scanInt(sc)}
	}
	return n, sizes
}

var dp [][]int

func initDP(n int) {
	dp = make([][]int, n+1)
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, n+1)
		for j := 0; j < len(dp[i]); j++ {
			dp[i][j] = math.MaxInt64
		}
	}
}

func resolve(n int, sizes []matrixSize) int {
	// TODO 復習
	initDP(n)
	_rec(sizes, 0, n)
	return dp[0][n]
}

func _rec(sizes []matrixSize, l, r int) int {
	if dp[l][r] != math.MaxInt64 {
		return dp[l][r]
	}
	if r-l <= 1 {
		dp[l][r] = 0
		return 0
	}
	num := math.MaxInt64
	for i := l + 1; i < r; i++ {
		v := _rec(sizes, l, i) + _rec(sizes, i, r) + calcNum(matrixSize{sizes[l].row, sizes[i].row}, matrixSize{sizes[i].row, sizes[r-1].col})
		if v < num {
			num = v
		}
	}
	dp[l][r] = num
	return dp[l][r]
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

long int M[101][101];
long int a[1000];
int n;
void solve(){
  for(int i=0;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]=INT_MAX;
       	  for(int k=i;k<j;k++){
	        long int tmp = M[i][k]+M[k+1][j]+a[i-1]*a[k]*a[j];
		M[i][j] = min(M[i][j],tmp);	
	    }
	}
    }
}

int main(){ 
   cin>>n;
   int p, q;
   for(int i=0; i<n; i++){
    cin>>p>>q;
    if(i == 0){
      a[i] = p;
      a[i+1] = q;
    }else{
      a[i+1] = q;
    }
  }

//   for(int i=0;i<2*n;i++)
//	cout<<a[i]<<endl;
   solve();
// for(int i=0;i<=n;i++){
//	for(int j=0;j<=n;j++){
//	    cout<<"("<<i<<","<<j<<")"<<M[i][j]<<" ";
//	}
//	cout<<endl;
 //  }
   cout<<M[1][n]<<endl;
   return 0;
}

C++: #include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;


int main() {
    int n;
    cin >> n;
    vector<P> ps(n);
    rep(i, n) {
        //y,x
        cin >> ps[i].first >> ps[i].second;
    }
    vector<vector<ll>> dp(n, vector<ll>(n, INF));
    rep(i, n) {
        dp[i][i] = 0;
    }
    for (int len = 1; len < n; len++) {
        for (int left = 0; left < n-len; left++) {
            int right = left + len;
            for (int middle = left; middle < right; middle++) {
                ll add1 = ps[left].first * ps[middle].second * ps[right].second;
                ll u1 = dp[left][middle] + dp[middle+1][right] + add1;
                dp[left][right] = min(dp[left][right], u1);
            }
        }
    }
    cout << dp[0][n - 1] << endl;
    return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <climits>

/*
 * http://ttrsq.exblog.jp/24318687/
 */

const int MAX_N = 100;
int DP[MAX_N + 1][MAX_N + 1] = {0};
int *p;

int best(int r, int c) {
  int min = INT_MAX;
  int num = c - r;

  for (int i = 0; i < num; i++) {
    min = std::min(min, DP[r][r + i] + DP[r + i + 1][c] + p[r - 1] * p[r + i] * p[c]);
  }
  
  return min;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n = 0;
  std::cin >> n;

  if (n == 1) {
    std::cout << "0" << std::endl;
  }
  
  p = (int *) std::malloc(sizeof(int) * n + 1);

  int bb = 0;

  std::cin >> p[0];
  std::cin >> p[1];
  
  for (int i = 2; i <= n; i++) {
    std::cin >> bb;
    std::cin >> p[i];
  }

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

  for (int j = 0; j <= n - 3; j++) {
    for (int i = j + 3; i <= n; i++) {
      DP[i - 2 - j][i] = best(i - 2 - j, i);
    }
  }

  std::cout << DP[1][n] << std::endl;

  return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[111][111],n,L[111],R[111];

int dfs(int l,int r){
	if(dp[l][r]!=-1)return dp[l][r];
	int res=1e9;
	for(int i=l;i<r;i++){
		res=min(res,dfs(l,i)+dfs(i+1,r)+L[l]*R[i]*R[r]);
	}
	return dp[l][r]=res;
}

signed main(){
	memset(dp,-1,sizeof(dp));
	r(i,111)dp[i][i]=0;
	cin>>n;
	r(i,n)cin>>L[i]>>R[i];
	cout<<dfs(0,n-1)<<endl;
}

C++: /*
** Matrix Chain Multiplication
*/

# include <cstdio>
# include <algorithm>
using namespace std;

const int MAX = 100 + 5;

int n, m[MAX][MAX], p[MAX];

void matrixCM() {
    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; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
}

void solve() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &p[i], &p[i + 1]);
    }
    matrixCM();
    printf("%d\n", m[1][n]);
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}

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

int main()
{
	int n, p = 0, m = 101, mini;
	int v[101];

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> v[i] >> v[i + 1];
		if (m > v[i]) {
			m = v[i];
			mini = i;
		}
	}

	if (n > 1) {
		for (int j = 0; j < n; j++)
			p += v[j] * v[j + 1];

		if (mini == 0) {
			p -= v[0] * v[1];
			p *= v[0];
		}
		else if (mini == n) {
			p -= v[n - 1] * v[n];
			p *= v[n];
		}
		else {
			p -= v[mini] * (v[mini + 1] + v[mini - 1]);
			p *= v[mini];
			p += v[0] * v[mini] * v[n];
		}
	}

	cout << p << 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;

#define MAX_N 10000
#define INF 10000000LL

long long n, j, x[MAX_N][MAX_N], p[MAX_N + 2], sum;

int matrix() {
	for (int i = 0; i < n; i++) { x[i][i] = 0; }
	for (int h = 2; h <= n; h++) {
		for (int i = 1; i <= n - h + 1; i++) {
			j = i + h - 1;
			x[i][j] = INF;
			for (int k = i; k < j; k++) {
				x[i][j] = min(x[i][j], x[i][k] + x[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	sum = x[1][n];
	return sum;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i - 1] >> p[i];
	}
	cout << matrix() << endl;
	return 0;
}