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 <algorithm>
#include <iostream>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int MAX_N = 100;

struct matrix {
    int r;
    int c;
};

ll dp[MAX_N + 1][MAX_N + 1];

ll solve(const int i, const int j, const vector<struct matrix> &matrices) {
    if (j <= i) return 0;
    if (j - i == 1) return matrices[i].r * matrices[i].c * matrices[j].c;
    if (dp[i][j] != LONG_LONG_MAX / 2) return dp[i][j];

    ll answer = LONG_LONG_MAX / 2;
    for (int k = i; k < j; k++) {
        chmin(answer, solve(i, k, matrices) + solve(k + 1, j, matrices) + matrices[i].r * matrices[k].c * matrices[j].c);
    }

    dp[i][j] = answer;
    return answer;

    // for (int i = 1; i <= N; i++) {
    //     int j = i + 1;
    //     dp[i][j] = matrices[i].r * matrices[i].c * matrices[j].c;
    //     j++;
    //     for (; j <= N; j++) {
    //         for (int k = i + 1; k < j; k++) {
    //             chmin(dp[i][j], dp[i][k] + dp[k + 1][j] +
    //                     matrices[i].r * matrices[k].c * matrices[j].c);
    //         }
    //     }
    // }
    // 
    // return dp[1][N];
}

int main(void) {
    int N;
    cin >> N;
    vector<struct matrix> matrices(N + 1);

    for (int i = 1; i <= N; i++) {
        cin >> matrices[i].r >> matrices[i].c;
    }

    for (int i = 1; i <= MAX_N; i++) {
        for (int j = i + 1; j <= MAX_N; j++) {
            dp[i][j] = LONG_LONG_MAX / 2;
        }
    }

    cout << solve(1, N, matrices) << endl;

    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j <= N; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    
    return 0;
}

C++: #include <cstdio>

#define N 10000

typedef long long int lli;

lli a[N*N];
lli b[N*N];
lli c[N*N];

int n,m,l;

void mult() {
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            for(int k=0; k<m; k++)
                c[i*N + j] += a[i*N + k] * b[k*N + j];
}

int main(void) {
    scanf("%d%d%d",&n,&m,&l);

    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            scanf("%lld", &a[i*N + j]);
    for(int i=0; i<m; i++)
        for(int j=0; j<l; j++)
            scanf("%lld", &b[i*N + j]);
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            c[i*N + j] = 0;

    mult();

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<l-1; j++)
            printf("%lld ", c[i*N + j]);
        printf("%lld", c[i*N + l-1]);
        printf("\n");
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define 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]>>p[i+1];
	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=l+i-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 <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll n;
V< P<ll, ll> > rc;
vvll dp;

ll rec(ll l, ll r) {
    if (l == r) return dp[l][r] = 0;
    if (dp[l][r] != HIGHINF) return dp[l][r];
    for (ll i = l; i <= r - 1; i++) {
        chmin(dp[l][r], rec(l, i) + rec(i + 1, r) + rc[l].first * rc[i].second * rc[r].second);
    }
    return dp[l][r];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rc.resize(n);
    for (ll i = 0; i < n; i++) cin >> rc[i].first >> rc[i].second;
    dp.resize(n, vll(n, HIGHINF));
    cout << rec(0, n - 1) << '\n';

    // for (ll i = 0; i < n; i++) DEBUG_VLL(dp[i])
    return 0;
}

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

const int INF = 1 << 28;

int n;
int memo[101][101];
int r[102];

int dfs(int i, int j){
    int res = INF;
    
    if(memo[i][j] != -1) return memo[i][j];
    
    if(i == j){
        return 0;
    }
    
    for(int k = i; k < j; ++k){
        res = min(res, dfs(i,k) + dfs(k + 1, j) + r[i] * r[k + 1] * r[j + 1]);    
    }
    
    return memo[i][j] = res;
}


int main()
{

    cin >> n;
    fill((int*)memo, (int*)(memo + n), -1);
    for(int i = 0; i < n; ++i){
        cin >> r[i] >> r[i + 1];
    }
    
    cout << dfs(0, n-1) << endl;
    
}

C++: #include<cstdio>
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#define _USE_MATH_DEFINES // M_PI????????????????????????
#include<math.h>
#pragma warning(disable:4996)
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][k],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}
	cout << m[1][n] << "\n";
	return 0;
}