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++: // https://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
constexpr char bn = '\n';
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
const ll tl= 1000000007;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<=b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
   while (n > 0) {
      if (n & 1) res = res * a % mod;
      a = a * a % mod;
      n >>= 1;
  }
  return res;
}
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO"  )
#define Yes(n) ((n) ? "Yes" : "No"  )
#define yes(n) ((n) ? "yes" : "no"  )
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    ll ans= 0;
    inl(n);
    vector<pair<ll,ll>> A;
    vvl dp(n,vl(n,INF)); // dp[i][j]: 区間[i,j)の中での乗算回数最小値
    
    REP(i,n){
        inl(x,y);
        A.pb({x,y});
    }
    //対角部は0（dpテーブル初期値）
    REP(i,n){
        dp[i][i]= 0;
    }
    // REP(i,n){
    //     REP(j,n){
    //         if(dp[i][j]==INF) cout << -1 << " ";
    //         else cout<<(dp[i][j])<<" ";
    //     }out();
    // }
    // dp[i][j]: A[i]~A[j]で最小の計算
    // dp[i][j]: dp[i][k] +dp[k][j] + A[i]*A[k]*A[j]  (i<k<j) i~k番目の組み合わせとk+1~j番目の組み合わせ
    // この小さい方を選ぶ
    // 斜めに遷移するfor文
    REP(j,n){
        if(j==0) continue;
        REP(i,n-j){
            ll jj= i+j;
            FOR(k,i,jj){
                ll division= dp[i][k] + dp[k+1][jj] + A[i].first *A[k].second* A[jj].second; //or A[i].first *A[k+1].first* A[jj].second;
                chmin(dp[i][jj], division);
            // out(dp[i][jj],":",fromLeft-dp[i][jj-1],fromUnder-dp[i+1][jj]);
            }
        }
    }
    // REP(i,n){
    //     REP(j,n){
    //         if(dp[i][j]==INF) cout << -1 << " ";
    //         else cout<<(dp[i][j])<<" ";
    //     }out();
    // }
    out(dp[0][n-1]);
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <bitset>
#include <cmath>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

struct mat{
    ll r;
    ll c;
};

typedef pair<ll,mat> P;

ll cal(P &x, P &y){
    return x.first+y.first+x.second.r*y.second.r*y.second.c;
}

int main(){
    int n;
    cin >> n;
    vector<mat> da(n);
    rip(i,n,0){
        cin >> da[i].r >> da[i].c;
    }
    vector<vector<P>> dp(n,vector<P>(n));
    rip(i,n,0){
        dp[i][i].first=0;
        dp[i][i].second=da[i];
    }
    rip(i,n,1){
        rip(j,n-i,0){
            dp[j][j+i].first=LLONG_MAX;
            rip(k,i,0){
                dp[j][j+i].first=min(dp[j][j+i].first,cal(dp[j][j+k],dp[j+k+1][j+i]));
            }
            dp[j][j+i].second.r=da[j].r;
            dp[j][j+i].second.c=da[j+i].c;
        }
    }
    cout << dp[0][n-1].first << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;

int arr[100];
int dp[100][100];

int findNumOperation(int l, int r)
{
    if(dp[l][r] != -1) return dp[l][r];
    if(r-l==1) return 0;
    else if(r-l==2) return arr[l]*arr[l+1]*arr[r];

    int mn = 99999999;
    for(int i=l+1; i<r; i++){
        int a = findNumOperation(l,i);
        int b = findNumOperation(i,r);
        int c = a+b+(arr[l]*arr[i]*arr[r]);
        if(c<mn) mn=c;
    }
    return mn;
}

int main()
{
    int n;
    cin >> n;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            dp[i][j] = -1;
        }
    }
    cin >> arr[0] >> arr[1];
    for(int i=2; i<n+1; i++) {
        int a,b;
        cin >> a >> b;
        arr[i] = b;
    }
    int ans = findNumOperation(0, n);
    cout << ans << endl;
}