Go: package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	P := make([]int, n+1)
	for i := 1; i <= n; i++ {
		l := nextInt(sc)
		P[i-1] = l
		m := nextInt(sc)
		P[i] = m
	}

	matrix := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		matrix[i] = make([]int, n+1)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n - l + 1; i++ {
			j := i + l - 1
			matrix[i][j] = (1 << 21)
			for k := i; k <= j-1; k++ {
				matrix[i][j] = min(matrix[i][j], matrix[i][k] + matrix[k+1][j] + P[i-1] * P[k] * P[j])
			}
		}
	}
	fmt.Println(matrix[1][n])
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
using namespace std;


#define min(a, b) ((a) < (b) ? (a) : (b))

int N;
const int MAX_N = 110;
const int INF = 0x3fffffff;
int A[MAX_N];
int B[MAX_N];
int dp[MAX_N][MAX_N];

void init() {
    scanf("%d", &N);
    for(int i = 0; i < N; ++i)
        scanf("%d%d",&A[i], &B[i]);
    for(int i = 0 ;i < N; ++i)
        for(int j = 0; j < N; ++j)
            dp[i][j] = INF;
    for(int i = 0; i < N; ++i)
        dp[i][i] = 0;
}

int solve() {
    for(int k = 1; k < N; ++k) {
        for(int i = 0; i < N - k; ++i) {
            for(int j = i; j < i + k; ++j) {
                printf("i = %d j = %d k = %d\n", i, j, k);
                int sz = A[i] * B[j] * B[i + k];
                dp[i][i + k] = min(dp[i][i + k],dp[i][j] + dp[j+1][i + k] + sz);
            }
        }
    }
    // for(int i = 0; i < N; ++i) {                                                                                                                                              
    //  for(int j = 0; j < N; ++j)                                                                                                                                               
    //      printf("%d ", dp[i][j]);                                                                                                                                             
    //  printf("\n");                                                                                                                                                            
    // }                                                                                                                                                                         
    return dp[0][N - 1];
}

int main() {
    init();
    printf("%d\n", solve());
    return 0;
}

C++: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
ll func(int l,int r,VV &dp,vector<pair<ll,ll>>&data){
	if(dp[l][r]==-1){
		dp[l][r]=INFLL;
		for(int med=l;med<r;med++){
			chmin(dp[l][r],func(l,med,dp,data)+func(med+1,r,dp,data)+data[l].F*data[med].S*data[r].S);
		}
	}
	return dp[l][r];
}
int main(){
	int n;
	
	cin >>n;
	vector<pair<ll,ll>>data(n,mp(1,1));
	rep(i,n){
		cin>>data[i].F>>data[i].S;
	}
	VV dp(n,V(n,-1));
	rep(i,n){
		dp[i][i]=0LL;
	}

	cout<<func(0,n-1,dp,data)<<endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

vector<vector<ll>> dp;
vector<ll> L,R;

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

    if(l==r) return dp[l][r] = 0;

    ll sum = HIGHINF;
    for(int i = l; i+1 <= r; ++i) {
    
        ll xl = rec(l,i);
        ll xr = rec(i+1,r);    
        chmin(sum,L[l]*R[i]*R[r]+xl+xr);
    }
    return dp[l][r] = sum;
}

int main() {
    int N; cin >> N;
    dp.resize(N,vector<ll>(N,-1));
    L.resize(N);
    R.resize(N);

    for(int i = 0; i < N; ++i) cin >> L[i] >> R[i];
    cout << rec(0,N-1) << endl;

    return 0;
}