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<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("%lld\n",dp[0][N-1]);
	return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>

#define INF 1000000000

struct matrix {
	int row;
	int column;

};

using namespace std;

//leftはindexの添え字
int partprob_matchain(vector<vector<int>>& table, matrix* mat, int left, int right) {
	if (left == right) return 0;
	if (table.at(left).at(right) != 0) return table.at(left).at(right);
	int temp, min = INF;
	for (int i = left, j = left + 1; j <= right; i++, j++) {
		temp = partprob_matchain(table, mat, left, i);
		temp += partprob_matchain(table, mat, j, right);
		temp += mat[left].row * mat[i].column * mat[right].column;
		if (temp < min) min = temp;
	}
	table.at(left).at(right) = min;
	return min;
}


int matrix_chain(vector<vector<int>>& table, matrix* mat) {
	return partprob_matchain(table, mat, 0, table.at(0).size() - 1);
}


int main(void) {
	int size;
	cin >> size;
	matrix* mat = new matrix[size];
	vector<vector<int>> table(size, vector<int>(size));

	for (int i = 0; i < size; i++) cin >> mat[i].row >> mat[i].column;

	cout << matrix_chain(table, mat) << endl;
	delete[] mat;
	return 0;

}

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

inline int MIN(int a,int b){
	return ((a)<(b)?(a):(b));
}

int minimumProduct(int left, int right, vector<pair<int,int> >& mat, vector<vector<int> >& product) {
	if(left==right) return 0;
	if(product[left][right]!=-1) {
		return product[left][right];
	}
	int i,min=INT_MAX;
	for(i=left; i<right; ++i) {
		min=MIN(min,minimumProduct(left,i,mat,product)
				+minimumProduct(i+1,right,mat,product)
				+mat[left].first*mat[right].second*((i==right-1)?mat[right].first:mat[i].second));
	}
	return product[left][right]=min;
}

int main() {
	int n;
	int i,j;
	vector<pair<int,int> > mat;
	vector<vector<int> > product;

	scanf("%d",&n);
	mat.resize(n);
	product.resize(n);
	for(i=0; i<n; ++i) {
		product[i].resize(n);
		scanf("%d%d",&mat[i].first,&mat[i].second);
		for(j=0; j<n; ++j) {
			product[i][j]=-1;
		}
	}
	printf("%d\n",minimumProduct(0,n-1,mat,product));
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int MAXN = 100+7;

int p[MAXN];
int dp[MAXN][MAXN];
int n;
void generate_dp(){
    for(int i = 1; i <= n; i++){
        dp[i][i] = 0;
    }
    for(int b = 1; b < n; b++){
        for(int i = 1; i <= n-b; i++){
            int j = i+b;
            int k; k = i;
            int min_x = dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j];
            for(k = i+1; k < j; k++){
                if(dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j] < min_x){
                    min_x = dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j];
                }
            }
            dp[i][j] = min_x;
        }
    }
}
int main(){

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

    return 0;
}

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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;
	ll a, b;
	vector<pair<ll, ll>> v;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		v.push_back({a, b});
	}

	vector<vector<ll>> dp(n, vector<ll>(n, -1));
	function<ll(int, int)> f = [&](int i, int j)
	{
		if (i == j)
			return 0LL;

		if (dp[i][j] != -1)
			return dp[i][j];

		ll r = 1LL<<62;
		for (int k = i; k < j; ++k)
			r = min(r, f(i, k)+f(k+1, j)+v[i].first*v[j].second*v[k].second);

		return dp[i][j]=r;
	};

	cout << f(0, n-1) << "\n";

	return 0;
}

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

int n,m[101],cm[101][101];

void calc(){
  int i,j,l,p,k;
  for (i=0;i<n;i++)cm[i][i]=0;
  for (l=1;l<n;l++){
    for(i=0;i<n-l;i++){
      j=i+l;
      cm[i][j]=INF;
      //cout << i << " "<< j << endl;
      for (k=i;k<j;k++){
	//cout << i << " "<< j <<" "<< k<<" "<<cm[i][k]<<" "<<cm[k+1][j] <<  endl;
	p=cm[i][k]+cm[k+1][j]+m[i]*m[k+1]*m[j+1];
	cm[i][j]=min(cm[i][j],p);
      }
    }
  }
}

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

  calc();

  cout << cm[0][n-1]<<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[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>

int64_t calculateMultiply(std::vector<std::pair<int, int>>& v) {
  int n = v.size();
  std::vector<std::vector<int64_t>> m(n, std::vector<int64_t>(n, 0));
  for (int l = 1; l < n; ++l) {
    for (int i = 0; i < n-l; ++i) {
      int j = i+l;
      m[i][j] = INT64_MAX;
      for (int k = i; k < j; ++k) {
        int q = m[i][k] + m[k+1][j] + (v[i].first)*(v[k].second)*(v[j].second);
        if (q < m[i][j]) {
          m[i][j] = q;
        }
      }
    }
  }
  return m[0][n-1];
}


int main() {
  int n;
  std::cin >> n;
  std::vector<std::pair<int, int>> v;
  for (int i = 0; i < n; ++i) {
    int a, b;
    std::cin >> a >> b;
    v.push_back({a, b});
   }
  std::cout << calculateMultiply(v) << std::endl;
}