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 rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

const int INF = 1e8;

int main() {
	int n;
	cin >> n;
	vector<int> r(n), c(n);
	rep(i, n) cin >> r[i] >> c[i];
	vector<vector<int>> dp(n + 1, vector<int>(n + 1, INF));
	rep(i, n + 1) dp[i][i] = 0;
	rep(i, n) dp[i][i + 1] = 0;
	for (int w = 2; w <= n; w++) {
		for (int i = 0; i <= n - w; i++) {
			int j = i + w;
			for (int m = i + 1; m < j; m++) {
				int t = r[i] * r[m] * c[j - 1];
				dp[i][j] = min(dp[i][j], dp[i][m] + dp[m][j] + t);
			}
		}
	}
	cout << dp[0][n] << endl;
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    //cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);N;
    int N; cin >> N;
    int r[N], c[N];
    REP(i,N){
        cin >> r[i] >> c[i];
    }

    /*if(N == 2){
        cout << r[0] * c[0] * c[1] << endl;
        return 0;
    }*/

    int dp[N][N];
    REP(i,N){
        REP(j,N){
            //dp[i][j] = INF;
            if(i == j) {dp[i][j] = 0;}
            else dp[i][j] = INF;
        }
    }
    //cout << dp[3][4] << endl;

    for(int w = 1; w < N; w++){
        for(int left = 0; left + w < N; left++){
            int right = left + w;
            //int mini = INF;
            for (int k = left;k < right; k++){
                int num = r[left] * r[k+1] * c[right];
                /*if(left == 3 && right == 4) {
                    cout << num << endl;
                    //cout << r[left] << " " << r[k+1] << " " << c[right] << endl;
                } */
                dp[left][left+w] = min(dp[left][left+w], dp[left][k] + dp[k+1][right] + num);
            }
        }   
    }

    cout << dp[0][N-1] << endl;
    
}

C++: #define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable: 4244) // 最悪をします
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <sstream>
#define BIT(nr) (1UL << (nr))
#define int long long
//#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }


using namespace std;

//デバッグ用カッコの有無
#ifdef DEBUG
template <class T>ostream &operator<<(ostream &o, const vector<T>&v)
{
	o << "{"; for (int i = 0; i<(int)v.size(); i++)o << (i>0 ? ", " : "") << v[i]; o << "}"; return o;
}
#endif // DEBUG

template <class T>ostream &operator<<(ostream &o, const vector<T>&v)
{
	for (int i = 0; i<(int)v.size(); i++)o << (i>0 ? " " : "") << v[i]; return o;
}

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int dxp[4] = { 0, 1 }; // x軸方向への変位(正のみ)
int dyp[4] = { 1, 0 }; // y軸方向への変位(負のみ)

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;

	// libalgo のものに追加、メンバを追加するだけなので互換性は崩さないはず、逆辺のG[e.dstの]インデックスを保持
	int rev;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph& g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph& g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

int dp[110][110];
signed main() {
	int n;
	cin >> n;

	vector<int> ro(n), co(n);
	rep(i, n) {
		cin >> ro[i] >> co[i];
	}

	rep(i, 100) rep(j, 100) dp[i][j] = LL_HALFMAX;

	// [l, r) における最適解
	function<int(int, int)> rec = [&](int l, int r) -> int {
		if (dp[l][r] != LL_HALFMAX) {
			return dp[l][r];
		}
		
		if (r - l == 1) {
			return dp[l][r] = 0;
		}

		int ret = LL_HALFMAX;

		REP(m, l + 1, r) {
			int cand = ro[l] * ro[m] * co[r - 1] + rec(l, m) + rec(m, r);
			chmin(ret, cand);
		}

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

	cout << rec(0, n) << "\n";
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int n;
int m[200][200];
int p[200];

int matrixChainMultiplication(){
    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] = 1001001001;
            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]);                
            }
        }
    }
    return m[1][n];
}

int main() {
    cin >> n;
    rep(i, n){
        int a, b; cin >> a >> b;
        p[i] = a;
        p[i+1] = b;
    }
    int ans = matrixChainMultiplication();

    cout << ans << endl;

    return 0;
}