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 <cstdlib>
#include <cstring>

using namespace std;
const int maxn=100+10;
const int INF=(1<<21);
int n;
int p[maxn];
int dp[maxn][maxn];
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d%d",&p[i],&p[i+1]);
    }

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

    }
    for(int len=2;len<=n;len++)
    {
        for(int i=0;i<n-len+1;i++)
        {
            int j=i+len-1;
            dp[i][j]=INF;
            for(int k=i;k<j;k++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i]*p[k+1]*p[j+1]);
            }
        }
    }
    printf("%d\n",dp[0][n-1]);

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1001001001001001;

int n;
ll r[111], c[111];
ll dp[111][111]; // dp[le][ri] = [le, ri) の最小回数

ll rec(int le, int ri) {
    if (dp[le][ri] != INF) return dp[le][ri];
    if (ri - le - 2 == 0) {
        return dp[le][ri] = min(dp[le][ri], r[le] * c[le] * c[ri - 1]);
    }
    if (le + 1 < ri - 1) dp[le][ri] = min(dp[le][ri], rec(le + 1, ri) + r[le] * c[le] * c[ri - 1]);
    if (le < ri - 2) dp[le][ri] = min(dp[le][ri], rec(le, ri - 1) + r[le] * c[ri - 2] * c[ri - 1]);
    for (int md = le + 1; md < ri - 1; md++) {
        dp[le][ri] = min(dp[le][ri], rec(le, md) + rec(md, ri) + r[le] * c[md - 1] * c[ri - 1]);
    }
    return dp[le][ri];
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> r[i] >> c[i];
    for (int i = 0; i < 111; i++) {
        for (int j = 0; j < 111; j++) {
            dp[i][j] = INF;
        }
    }
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    rec(0, n);
    cout << dp[0][n] << endl;
}

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

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

static 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 <cstdio>
#include <climits>

typedef struct{
    int r;
    int c;
}matrix;

int table[100][100];

int calc(matrix* m, int l, int r){
    if(r<=l+1)return 0;
    if(table[l][r]>0)return table[l][r];
    int i, tmp;
    int ans = INT_MAX;
    for(i=l+1;i<r;i++){
        tmp = m[l].r*m[i].r*m[r-1].c + calc(m,l,i) + calc(m,i,r);
        if(tmp<ans)ans = tmp;
    }
    table[l][r] = ans;
    return ans;
}

int main(){
    int i, j, n;
    matrix m[100];
    scanf("%d",&n);
    for(i=0;i<100;i++){
        for(j=0;j<100;j++){
            table[i][j] = 0;
        }
    }
    for(i=0;i<n;i++){
        scanf("%d %d",&(m[i].r),&(m[i].c));
    }
    printf("%d\n",calc(m,0,n));
    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[i][n] << endl;
	
	return 0;
}

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

struct mat{
  int row, col;
};

int m[101][101];
mat p[101];

int main(){
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> p[i].row >> p[i].col;
  for(int l = 2; l <= n; l++){
    for(int i = 1; i <= n - l + 1; i++){
      int j = i + l - 1;
      if(i == j) m[i][j] = 0;
      else{
	int minc = 1e9;
	for(int k = i; k < j; k++){
	  int x = m[i][k] + m[k+1][j] + p[i].row * p[k].col * p[j].col;
	  minc = minc < x ? minc : x;
	}
	m[i][j] = minc;
      }
    }
  }
  cout << m[1][n] << endl;
  return 0;
}