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 <string>
#include <algorithm>

#define INF 100000001

using namespace std;

int DP[101][101];
int *p;

int rec(int r, int c){
  int Min = INF;
  int num = c-r;

  for (int i = 0; i < num; 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(){
    int N;
    cin >> N;
    for(int i = 1; i <= N; i++) DP[i][i] = 0;

    p = (int *)malloc(sizeof(int)*(N+1));

    cin >> p[0];
    cin >> p[1];
      int bb;
    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;

    return 0;
  }

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

static const int N = 100;

int main()
{
	int n;
	int p[N + 1];
	int 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 << 27);
			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 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; 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<bits/stdc++.h>
using namespace std;
int main(){
  int n,p[105],m[105][105];
  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 <iostream>
#include <algorithm>
using namespace std;

static const int N = 100;

signed 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 <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(101);
    ll dp[101][101];
    REPP(i,1,n+1) cin >> p[i-1] >> p[i];
    REPP(i,1,n+1) dp[i][i]=0;

    for(int i = 2; i <= n;i++){
        for(int l = 1; l <= n - i + 1;l++){
            int j =  i  +  l - 1;
            dp[l][j] = (1 << 21);
            for(int k = l; k <= j - 1;k++){
            dp[l][j] = min(dp[l][j],dp[l][k] + dp[k+1][j] + p[l-1]*p[k]*p[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 h=2;h<=n;h++){
        for(int i=1;i<=n-h+1;i++){
            int j=i+h-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;
}