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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxx = 110;
const int INF = 1 << 30;
int main()
{
	int n, p[maxx], m[maxx][maxx];

	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d %d", &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] = 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]);

		}
	}
	printf("%d\n", m[1][n]);
	return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int n, r[100], c[100], dp[100][101];
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d%d", &r[i], &c[i]), dp[i][i] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; i + j <= n; j++) {
			dp[j][i + j] = min(dp[j][i + j - 1], dp[j + 1][i + j]) + r[j] * c[i + j - 1];
		}
	}
	printf("%d\n", dp[0][n]);
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <map>
#define MAX_NUM 100
#define INFTY 1000000000
#define NIL -1

using namespace std;

//think easy make easy

int n;//num of input


pair<int,int> MatrixChain[MAX_NUM+1];
map<pair<int,int>,int> map;

int calc(int s,int e){//s~eの連鎖行列積の最少計算回数を出力
	int min_time  = INFTY;
	int min_tmp;

	if(map[s,e] != NIL)
		return map[s,e];

	if(s == e){
		return 0;
	}
	for(int i=s;i<e;i++){
		min_tmp = calc(s,i) + calc(i+1,e) 
			+MatrixChain[s].first*MatrixChain[i].second*MatrixChain[e].second;
		if(min_tmp < min_time)
			min_time = min_tmp;
	}
	map[s,e] = min_time;//メモ
	return min_time;
}

int main(){
	scanf("%d",&n);
	int r,c;//row,column

	for(int i=0;i<n;i++){
		scanf("%d %d",&r,&c);
		MatrixChain[i] = pair<int,int>(r,c);//i:1~n-1
	}
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			map[i][j] = NIL;
		}
	}

	cout <<calc(0,n-1) <<endl;

	return 0;
}

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

int m[105][105];
int plen;
//function matrix chain order
void matrixco(int p[]){
  int n,j,q;
  n=plen-1;
  for(int i=1;i<=n;i++){
    m[i][i]=0;
  }

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

int main(){
  int n;
  int p[105];
  int r,c;
  //load n
  cin >>n;

  plen=n+1;

  for(int i=0;i<n;i++){
    //load r,c
    scanf("%d %d",&r,&c);

    if(i!=n-1) p[i]=r;
    else{
      p[i]=r;
      p[i+1]=c;
    }
  }

  matrixco(p);

  cout <<m[1][n]<<endl;
  return 0;
}

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

typedef long long ll;
const ll inf = 1<<30;

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

    int nb; cin >> nb;
    vector<ll> dim(nb);
    int trash;
    for(auto& a:dim) cin >> a >> trash;
    dim.push_back(trash);
    
    vector<vector<ll>> cost( nb, vector<ll>(nb, inf) );
    for (int i=0; i<nb; ++i){
        cost[i][i] = 0;
    }
    
    for (int k=1; k<nb; ++k){
        for (int i=0; i+k<nb; ++i){
            for (int j=0; j<i+k; ++j){
                cost[i][i+k] = min(
                    cost[i][i+k],
                    cost[i][j] + cost[j+1][i+k] + dim[i]*dim[j+1]*dim[i+k+1]);
            }
        }
    }

    cout<<cost[0][nb-1] <<"\n";
}

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

int main(void){
    int i,n;
    cin >> n;
    int p[n+1];
    int **m = new int*[n+1];
    for(i=1; i<=n; i++){
        m[i] = new int[n+1];
    }
    for(i=1; i<=n; i++) cin >> p[i-1] >> p[i];
    for(i=1;i<=n;i++) m[i][i] = 0;
    for(int l=2; l<=n; l++){
        for(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;
    for(int i=1; i<n+1; i++){
        delete[] m[i];
        m[i] = 0;
    }
    delete[] m;
    m = 0;
    return 0;
}

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

struct TMatrixInfo
{
	int RowSize;
	int ColSize;
	TMatrixInfo(int ARowSize, int AColSize)
	{
		RowSize = ARowSize;
		ColSize = AColSize;
	}
	TMatrixInfo()
	{
	}
};

vector<vector<int> > TableResize(int n)
{
	vector<vector<int> > CostCountTable;
	CostCountTable.resize(n);
	for(int i = 0; i < n; i++){
		CostCountTable[i].resize(n);
	}
	return CostCountTable;
}

int Cost(TMatrixInfo A, TMatrixInfo B)
{
	return A.RowSize * A.ColSize * B.ColSize;
}

TMatrixInfo M(int Index1, int Index2, const vector<TMatrixInfo>& MatrixChain)
{
	TMatrixInfo Matrix(MatrixChain[Index1].RowSize, MatrixChain[Index2].ColSize);
	return Matrix;
}

int GetCellValue(const vector<vector<int> >& CostCountTable, const vector<TMatrixInfo>& MatrixChain, int Row, int Col)
{
	if(Col == Row){
		return 0;
	}else{
		int CurrentMinCost;
		for(int i = Row; i < Col; i++){
			int CurrentCost = CostCountTable[Row][i] + Cost(M(Row, i, MatrixChain), M(i+1, Col, MatrixChain)) + CostCountTable[i+1][Col];
			if(i == Row || CurrentCost < CurrentMinCost){
				CurrentMinCost = CurrentCost;
			}
		}
		return CurrentMinCost;
	}
}

void CalcSlantingLine(vector<vector<int> >& CostCountTable, const vector<TMatrixInfo>& MatrixChain, int Col)
{
	int n = MatrixChain.size();
	for(int i = 0; i < n-Col; i++){
		CostCountTable[i][Col+i] = GetCellValue(CostCountTable, MatrixChain, i, Col+i);
	}
}

int MinCalcCost(const vector<TMatrixInfo>& MatrixChain)
{
	int n = MatrixChain.size();
	vector<vector<int> > CostCountTable = TableResize(n);
	for(int i = 0; i < n; i++){
		CalcSlantingLine(CostCountTable, MatrixChain, i);
	}
	return CostCountTable[0][n-1];
}

int main()
{
	int n;
	cin >> n;
	vector<TMatrixInfo> MatrixChain(n);
	for(int i = 0; i < n; i++){
		cin >> MatrixChain[i].RowSize;
		cin >> MatrixChain[i].ColSize;
	}
	cout << MinCalcCost(MatrixChain) << endl;
	return 0;
}