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<vector>
#include<algorithm>
#define INF (1<<21)
using namespace std;

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

  vector<int> p(105);
  int m[105][105];

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

  for(int i = 2; i <= n; i++){
    for(int j = 1; j <= n-i+1; j++){
      int x = i + j - 1;
      m[j][x] = INF;

      for(int k = j; k <= x-1; k++){
	m[j][x] = min(m[j][x], m[j][k]+m[k+1][x] + p[j-1]*p[k]*p[x]);
      }
    }
  }

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

  return 0;

}

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


int main() {
	int n, p[101], m[101][101];
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];
	
	int i, j, k, l;
	for (i = 1; i <= n; i++) m[i][i] = 0;
	for (l = 2; l <= n; l++) {
		for (i = 1; i <= n - l - 1; i++) {
			j = i + l - 1;
			m[i][j] = (1 << 21);
			for (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 <iostream>
#include <vector>
using namespace std;
const int INF = 1001001001;

int main(){
    int n;
    cin >> n;
    vector<int> rnum(n+1);
    for(int i = 0; i < n; i++){
        cin >> rnum[i] >> rnum[i+1];
    }

    vector<vector<int>> memo(n, vector<int>(n, INF));
    for(int i = 0; i < n; i++) memo[i][i] = 0;

    for(int i = n-1; i >= 0; i--){
        for(int j = i; j < n; j++){
            for(int k = i; k+1 < n; k++){
                if(memo[i][j] > memo[i][k] + memo[k+1][j] + rnum[i]*rnum[k+1]*rnum[j+1]){
                    memo[i][j] = memo[i][k] + memo[k+1][j] + rnum[i]*rnum[k+1]*rnum[j+1];
                }
            }
        }
    }

    cout << memo[0][n-1] << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
long long dp[1005][1005];
long long a[1005];
long long b[1005];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//	freopen("a.txt","r",stdin);
	int n;cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i];
	memset(dp,0xc,sizeof(dp));
	for(int i=1;i<=n;i++)dp[i][i]=0;
	for(int l=1;l<n;l++){
		for(int i=1;i<=n;i++){
			int j=i+l;
			if(j>n)continue;
			for(int k=i;k<j;k++)
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+a[i]*a[k+1]*b[j]);
		}
	}		
	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 <limits>
using namespace std;

int M[101][101] = {};
int p[101];

int matrixChain(int n)
{
    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] = std::numeric_limits<int>::max();

            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 M[1][n];
}

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

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

    cout << matrixChain(n) << endl;

    return 0;
}

C++: #include<iostream>
#include<cassert>
using namespace std;
struct mat
{
	int w;
	int h;
};
typedef struct mat mat_t;
int mulnum(mat_t,mat_t);
long long min(long long a,long long b);

int n;
mat_t a[101];
long long dp[101][101] ;

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i].h >> a[i].w;
	}
	for(int x = 0;x<n;x++){
		for(int y =0;y<n;y++){
			dp[x][y] = 2000000;
			if(x == y) dp[x][y] = 0;
		}
	}
	int i = 0;
	int j = 1;
	for(int l = 1;l<n;l++){
		i = 0;
		for(j=l;j<n;j++){
			for(int k = i;i <= k && k < j;k++){
				dp[i][j] = min(dp[i][j],dp[i][k] + dp[k+1][j] + a[i].h *a[k].w * a[j].w);
			}
			i++;
		}
	}
	/*
	for(int x = 0;x<n;x++){
		for(int y=0;y<n;y++){
			cerr << dp[x][y] << " ";
		}
		cerr << endl;
	}
	*/
	cout << dp[0][n-1] << endl;
}

int mulnum(mat_t a,mat_t b){
	assert(a.h == b.w);
	return a.h*a.w*b.h;
}

long long min(long long a,long long b) {
	return a<b? a:b;
}

C++: #include <string>
#include <utility>
#include <iostream>
 
#define MAX 100

#define INF 100000000

int left[MAX];
int right[MAX];

int DP[MAX][MAX];

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

  for(int i = 0; i < n; i++){
    std::cin >> left[i];
    std::cin >> right[i];
  }
  
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++){
      DP[i][j] = INF;
   }
  }

  for(int k = 0; k < n; k++){
    for(int l = 0; l + k < n; l++){
      int r = l + k;
      
      if(k == 0){
	DP[l][r] = 0;
      }else if(k == 1){
	DP[l][r] = left[l] * right[l] * right[r];
      }else{
	for(int t = l; t < r; t++){
	 
	  DP[l][r] = std::min(DP[l][r], DP[l][t] + DP[t + 1][r] + left[l] * right[t] * right[r]);
	}

	// printf("%d %d %d\n", l, r, DP[l][r]);
      }
    }
  }
  
  std::cout << DP[0][n - 1] << std::endl;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
static const int A=100;
int main(){
    int n,p[A+1],m[A+1][A+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 j=2; j<=n; j++){
        for(int i=1;i<=n-j+1;i++){
        int l=i+j-1;
        m[i][l]=(1<<21);
        for(int x=i;x<=l-1;x++){
            m[i][l]=min(m[i][l],m[i][x]+m[x+1][l]+p[i-1]*p[x]*p[l]);
        }
        }
    }
cout<<m[1][n]<<endl;
return 0;
}