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<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][j] << endl;
			}
		}
	}

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

	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main() {
  int i, j, n, k, m[101], dp[101][101], s, t;
  
  scanf("%d", &n);
  for (i=0; i<n*2; i++)
    scanf("%d", &m[i]);  

  for (i=0; i<n; i++)
    for (j=0; j<n; j++)
      dp[i][j]=0;
 
  for (k=2; k<n; k++) {
    for (i=1; i<n-k+1; i++) {
     j=i+k-1;
     for (s=i; s<i; s++)
       dp[i][j]=m[s]*dp[i][j];
     for(t=0; t<j-1; t++)
       dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]+m[i-1]*m[t]*m[j]);
    }
  }
  printf("%d",dp[1][n]);
  
  return 0;
}

C++: #include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
using namespace std;

vector<int> r(100), c(100);
vector<vector<int>> dp(100, vector<int>(100, -1));
int rec(int left, int right){
  if (right - left == 0) return 0;
  if (right - left == 1) return r[left] * r[right] * c[right];
  if (dp[left][right] != -1) return dp[left][right];
  int min;
  rep2(mid, left, right){
    min = rec(left, mid) + rec(mid+1, right) + r[left] * c[mid] * c[right];
    if (dp[left][right] == -1 || dp[left][right] > min) dp[left][right] = min;
  }
  return dp[left][right];
}

int main(){
  int n;
  cin >> n;
  rep(i, n) cin >> r[i] >> c[i];
  int ans = rec(0, n-1);
  cout << ans << endl;
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
static const int INFTY = (1 << 21);

int main() {
    int n;
    cin >> n;
    int p[n + 1], m[n + 1][n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> p[i - 1] >> p[n];
        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] = INFTY;
            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 <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
	int INFTY = 1000000000;

	int n;
	scanf("%d", &n);

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

	int m[n + 1][n + 1];

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			m[i][j] = 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] = INFTY;
			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 << i << ":" << j << "," << m[i][j] << endl;
			}
		}
	}
	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 = 0;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 <vector>
#define eol '\n'
using namespace std;

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

  int n;
  cin >> n;

  vector< vector<int> > mat(n, vector<int>(n, (1 << 21)));
  vector<int> r(n), c(n);
  
  for (int i = 0; i < n; i++) {
    mat[i][i] = 0;
    cin >> r[i] >> c[i];
  }
  
  for (int l = 1; l < n; l++) {
    for (int i = 0; i < n - l; i++) {
      int j = i + l;
      for (int k = i; k < j; k++) {
        mat[i][j] = min(mat[i][j], mat[i][k] + mat[k+1][j] + r[i] * c[k] * c[j]);
      }
    }
  }

  cout << mat[0][n-1] << eol;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define MAX 100
int main() {

    int n;
    cin >> n;
    int p[MAX+1], m[MAX+1][MAX+1];
    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] = INT_MAX;     //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] ) );
            }
        }
    }

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

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int n;
int m[110][2], dp[110][110];

int rec(int l, int r) {
    if (dp[l][r] != -1) {
        return dp[l][r];
    }

    if (abs(l - r) <= 1) {
        return dp[l][r] = 0;
    }

    int res = iINF;

    if (abs(l - r) == 2) {
        return dp[l][r] = m[l][0] * m[l][1] * m[r - 1][1];
    }

    for (int mid = l + 1; mid < r; mid++) {
        res = min(
            res, rec(l, mid) + rec(mid, r) + m[l][0] * m[mid - 1][1] * m[r - 1][1]);
    }

    return dp[l][r] = res;
}

int main() {
    cin >> n;
    REP(i, n) {
        int r, c;
        cin >> r >> c;
        m[i][0] = r;
        m[i][1] = c;
    }

    memset(dp, -1, sizeof(dp));

    cout << rec(0, n) << endl;
    return 0;
}