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 <bits/stdc++.h>

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define _shv(v) for (auto _t1 : v) cerr << _t1 << " "; cerr << endl;
#define dg(x) cerr << #x << ": " << (x) << endl;
#define dgv(v) cerr << #v << ": "; _shv(v);
#define dgm(m) cerr << #m << ":" << endl; for (auto _t2 : m) { _shv(_t2); }

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

template<typename T> inline void pt(T x) { cout << x << endl; }
template<typename T> inline void inv(T& v) { for (auto& t : v) cin >> t; }
template<typename T> inline int siz(T& x) { return x.size(); }
template<typename T> inline ll pow2(T n) { return 1ll << n; }
template<typename T, typename U> inline int bit(T x, U n) { return x >> n & 1; }
template<typename T, typename U>
inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }


int main() {
    int n; cin >> n;
    vi r(n), c(n);
    rep(i, n) cin >> r[i] >> c[i];
    vvl dp(n, vl(n, 0));
    rep(i, 1, n) {
        rep(j, n - i) {
            dp[j][j + i] = INF;
            rep(k, i) {
                umin(dp[j][j + i],
                    dp[j][j + k] + dp[j + k + 1][j + i] +
                    r[j] * c[j + i] * c[j + k]
                );
            }
        }
    }
    pt(dp[0][n - 1]);

    return 0;
}

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

int dp[110][110];

int main() {
  int n;
  cin >> n;
  vector<int> r(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> r[i] >> c[i];
  }
  for (int i = 0; i < 110; i++) {
    for (int j = 0; j < 110; j++) {
      if (i == j) {
        dp[i][j] = 0;
      }
      else {
        dp[i][j] = 100000000;
      }
    }
  }
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n - l + 1; i++) {
      int j = i + l - 1;
      for (int k = i; k <= j - 1; k++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + r[i - 1]*c[k - 1]*c[j - 1]);
      }
    }
  }
  cout << dp[1][n] << endl;
  return 0;
}

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

const int N = 100;

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[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] = numeric_limits<int>::infinity();
      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<stdio.h>
#include<algorithm>

using namespace std;
int n;
int m[101][101]; 
int s[101][101];
int q;
//連鎖行列積
int mco(int p[]) {
	for (int i = 1; i < n + 1; i++) {
		m[i][i] = 0; 
	}
	for (int l = 2; l < n + 1; l++) {
		for (int i = 1; i < n - l + 2; i++) {
			int j = i + l - 1;
			m[i][j] = 2000000;
			for (int k = i; k < j ; k++) {
				q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
				m[i][j] = min(q, m[i][j]);
				
			}
		}

	}return m[1][n];
	

}
int main() {
	cin >> n;
	int p[101];
	for (int i = 0; i < n; i++) {
		cin >> p[i] >> p[i + 1];
	}
	cout << mco(p) << endl;
	return 0;
	
	
}

C++: #include <iostream>
#include <climits>

int min(int x, int y)
{
	return x>y ? y : x;
}

int main()
{
	int n; std::cin >> n;
	
	int* r = new int[n];
	int* c = new int[n];
	for (int i=0; i<n; i++) std::cin >> r[i] >> c[i];
	
	long long int** DP = new long long int*[n];
	for (int i=0; i<n; i++) DP[i] = new long long int[n];
	
	for (int d=0; d<n; d++) {
		for (int i=0; i<n-d; i++) {
			if (d==0) DP[i][i] = 0;
			else {
				long long int opt = LLONG_MAX;
				for (int j=0; j<d; j++) {
					long long int tmp = r[i] * c[i+j] * c[i+d] + DP[i][i+j] + DP[i+j+1][i+d];
					if (opt > tmp) opt = tmp;
				}
				DP[i][i+d] = opt;
			}
		}
	}
	
	std::cout << DP[0][n-1] << std::endl;
	
	for (int i=0; i<n; i++) delete[] DP[i];
	delete[] DP;
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	int ma[2][101];
	for (int i = 0; i < n; ++i) {
		cin >> ma[0][i] >> ma[1][i];
	}

	long counts[101][101];
	long k1, k2;
	long mins1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i <= j) {
				counts[i][j] = 0;
			}
		}
	}

	for (int l = 0; l < n; ++l) {
		for (int i = 0; i < n-l; ++i) {
		
			int j = i +l+1;
			mins1 = 100000000;
			for (int k = i; k < j; ++k) {
				k1 = counts[i][k] + counts[k+1][j] + ma[0][i] * ma[1][k] * ma[1][j];
				if (mins1 > k1) {
					mins1 = k1;
				}
			}
			counts[i][j] = mins1;
			
		}
	}
	cout << counts[0][n - 1] << endl;
	return 0;
}