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 <bits/stdc++.h>
using namespace std;
#define INF 1e8;

int matrixChainMultiplication(int *p, int n) {
  int m[n+1][n+1];
  for (int i = 0; i <= n; i++) m[i][0] = 0;
  for (int j = 0; j <= n; j++) m[0][j] = 0;
  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] = INF;
      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]);
      }
    }
  }
  //上のループで、DPテーブル対角線上のゼロに近接するマスが順に埋まっていく
  //最終的に右端のm[1][n]がM1M2...Mnを計算する際の最小計算回数になる

  return m[1][n];
}

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

C++: #include <bits/stdc++.h>
using namespace std;

static const int N=100;

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

  for(i=1;i<=n;i++) m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-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 <vector>
#include <array>
#include <string>

const int size = 105;
const int NIL = -1;
int dp[size][size];
int ps[size];

int min_cost(int i, int j)
{
  if (dp[i][j] != NIL)
    return dp[i][j];

  int k=i;
  int min = min_cost(i,k) + min_cost(k+1,j) + ps[i-1]*ps[k]*ps[j];
  for (k=i+1; k<=j-1; ++k)
    {
      int tmp = min_cost(i,k) + min_cost(k+1,j) + ps[i-1]*ps[k]*ps[j];
      if (tmp < min) min = tmp;
    }
  dp[i][j] = min;
  return min;
}


int main()
{
  int n;
  std::cin >> n;

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

  for (int i=0; i<size; ++i)
    for (int j=0; j<size; ++j)
      dp[i][j] = NIL;

  for (int i=1; i<=n; ++i)
    {
      dp[i][i] = 0;
    }

  std::cout << min_cost(1,n) << std::endl;
}

C++: #include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;

static const int N = 100;

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

  REP1(i, n + 1) m[i][i] = 0;
  FOR(l, 2, n + 1) {
    REP1(i, n - l + 2) {
      int j = i + l - 1;
      m[i][j] = (1 << 21);
      FOR(k, i, j) {
        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;

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;
}

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

using namespace std;

typedef long long ll;
#define endl '\n'

int n;
ll r[111],c[111],d[111];
ll dp[111][111];
const ll oo = 1000000000000000LL;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> r[i] >> c[i];
	d[0] = r[1];
	for(int i = 1; i <= n; i++)
		d[i] = c[i];
	for(int size = 1; size <= n;size++){
		for(int i = 1; i <= n - size; i++){
			int j = i + size;
			dp[i][j] = oo;
			for(int k = i; k <= j - 1;k++){
				ll cost = dp[i][k] + dp[k + 1][j] + d[i - 1]*d[k]*d[j];
				dp[i][j] = min(dp[i][j],cost);
			}
		}
	}
	
	cout << dp[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;

const long N = 100;

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

	for (long i = 1; i <= n; i++) m[i][i] = 0;
	for (long l = 2; l <= n; l++){
		for (long i = 1; i <= n - l + 1; i++){
			long j = i + l - 1;
			m[i][j] = (1 << 21);
			for (long k = 0; 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;
    int DP[101][101];
    int *p;
int rec(int r,int c){
    int Min =100000001;
    
    for(int i=0;i<c-r;i++){
        Min =min(Min,DP[r][r+i] + DP[r+i+1][c]+p[r-1]*p[r+i]*p[c]);
    }
    return Min;
}
int main(void){
    int n,bb;
    cin>>n;
    p =new int[n+1];
    cin>> p[0];
    cin>>p[1];
    for(int i=1;i<=n ;i++) DP[i][i]=0;;
    for(int i=2;i<=n;i++){
        cin>>bb;
        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=3+j;i<=n;i++){
            DP[i-2-j][i] =rec(i-2-j,i);
        }
    }
    cout <<DP[1][n]<<endl;
}