Go: package main

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

var cache [100][100]int

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	tables := []table{}
	for i := 0; i < num; i++ {
		sc.Scan()
		num1, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		num2, _ := strconv.Atoi(sc.Text())
		t := table{num1, num2}
		tables = append(tables, t)
	}

	fmt.Println(minimum(0, len(tables)-1, tables))
}

type table struct {
	v int
	h int
}

func minimum(i int, j int, t []table) int {
	if i == j {
		return 0
	}

	// fmt.Printf("i:%v j:%v\n", i, j)
	if cache[i][j] != 0 {
		return cache[i][j]
	}

	min := math.MaxInt64
	for k := i; k < j; k++ {
		p := t[i].v
		n := t[k].h
		q := t[j].h
		val := minimum(i, k, t) + minimum(k+1, j, t) + p*n*q
		if val < min {
			min = val
		}
	}

	cache[i][j] = min
	return min
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <climits>
 
using namespace std;
 
int f(const int);
 
int main()
{
    int N;
    pair<int,int> data[100];
    vector<vector<int> > vdata(100,vector<int>(100,INT_MAX));
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>data[i].first>>data[i].second;
    }
    vdata[0][0]=0;
    for(int j=1;j<N;j++){
        vdata[j][j]=0;
        for(int i=j-1;i>=0;i--){
            for(int k=i+1;k<=j;k++){
                int c=vdata[i][k-1]+vdata[k][j]+data[i].first*data[k].first*data[j].second;
                if(c<vdata[i][j]){
                    vdata[i][j]=c;
                }
            }
        }
    }
    cout<<vdata[0][N-1]<<endl;
}

C++: #include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;

    int dp[101][101];
    int N[101];
    for (int i = 1; i <= n; ++i) {
        cin >> N[i- 1] >> N[i];
    }

    for (int i = 1; i <= n; ++i) {
        dp[i][i] = 0;
    }

    for (int len = 2; len <= n ; ++len) {
        for (int i = 1; i <= n - len + 1; ++i) {
            int j = i + len - 1;
            dp[i][j] = (1 << 21);
            for (int k = i; k <= j - 1; ++k) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + N[i - 1] * N[k] * N[j]);
            }
        }
    }

    cout << dp[1][n] << endl;
    return 0;
}

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

typedef long long lli;

const lli INF = 1LL << 59;
const int N = 1000;

int n;
vector<lli> v;

void solve(){
  lli dp[N][N];
  fill(dp[0],dp[N],INF);
  
  for(int i=0;i<=n;i++) dp[i][i] = 0;
  for(int i=2;i<=n;i++){
    for(int j=0;j+i-1<n;j++){
      int next = j + i - 1;
      for(int k=j;k<next;k++){
        dp[j][next] = min(dp[j][next], dp[j][k] + dp[k+1][next] + v[j] * v[k+1] * v[next+1]);
      }
    }
  }

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

int main(){
  while(cin >> n){
    v.clear();
    for(int i=0;i<n;i++) {
      int a,b;
      cin >> a >> b;
      if(i == 0) v.push_back(a);
      v.push_back(b);
    }
    solve();
  }
}

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

int n, a[100], v[101];
long sum, m = 1000000000;
bool f[100], g[100];

void permsum(int p) {
	if (p == n - 1) {
		sum = 0;
		memset(g, 0, 100);
		for (int i = 0; i < n - 1; i++) {
			g[a[i]] = 1;
			int u = 1, w = 1;
			while (g[a[i] - u])
				u++;
			while (g[a[i] + w])
				w++;
			sum += v[a[i] - u] * v[a[i]] * v[a[i] + w];			
		}
		if (m > sum)
			m = sum;
	}
	else {
		for (int j = 0; j < n - 1; j++) {
			if (!f[j]) {
				a[p] = j + 1;
				f[j] = 1;
				permsum(p + 1);
				f[j] = 0;
			}
		}
	}
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> v[i] >> v[i + 1];

	permsum(0);

	cout << m << endl;

	return 0;
}

C++: #pragma GCC diagnostic ignored "-Wunused-variable" 
#include <bits/stdc++.h>
using namespace std;

//#define BOOST
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace boost;
using ml = boost::multiprecision::cpp_int;
using md = boost::multiprecision::cpp_dec_float_100;
#define forir(i, ...) if(ll i=(ll)v.size())for(__VA_ARGS__)if(i--,1)
#define eachr(i, e, c) forir(i, auto &&e: adaptors::reverse(c))
#endif

/***** type *****/
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
template <class T> using vvvt = vector<vector<vector<T>>>;
/***** define *****/
#define all(c) (c).begin(), (c).end()            // begin to end
#define coutd cout << fixed << setprecision(10)  // cout double
#define output(x) do{cout<<x;return 0;}while(0)  // cout return
#define rep(i, b, e) for (ll i = b; i < e; i++)  // repeat
#define repr(i, b, e) for (ll i = b; e < i; i--) // repeat reverse
#define fori(i, ...) if (ll i = -1) for(__VA_ARGS__) if (i++, 1)
#define each(i, e, c) fori (i, auto&& e: c)      // for each
/***** const value *****/
#define llong_max 9223372036854775807            // 9 * 10^18
#define ldbl_max 1.79769e+308                    // 1.7 * 10^308
#define pi 3.1415926535897932                    // 3.14 ...
/***** lambda *****/
auto Ceil = [] // if (a % b != 0) return a / b + 1;
(auto x) { return (ll)ceil(x); };
auto Count = [] // long long count value
(auto b, auto e, auto x) { return (ll)count(b, e, x); };
auto CtoL = [] // char to number
(auto c) { return (ll)c - (ll)'0'; };
auto LtoC = [] // number to char
(auto n) { return (char)('0' + n); };
auto Pow = [] // long long pow
(auto a, auto b) { return (ll)pow(a, b); };
auto Pow2 = [] // long long pow2
(auto n) { return (1LL << n); };
auto Pow10 = [] // long long pow10
(auto n) { return (ll)pow(10, n); };
auto Size = []  // long long collection size
(auto& c) { return (ll)(c).size(); };
auto Sum = [] // long long accumulate
(auto b, auto e) { return accumulate(b, e, 0LL); };

/***** template *****/
template <class T> void MakeVVT
(ll ys, ll xs, vvt<T>& v, T fill = T())
{	// vector<vector<T>> resize + fill
	v.resize(ys); rep(y, 0, ys) v[y].resize(xs, fill);
}
template <class T> void MakeVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fill = T())
{	// vector<vector<vector<T>>> resize + fill
	v.resize(zs); rep(z, 0, zs) MakeVVT(ys, xs, v[z], fill);
}
template <class T> void InputVT
(ll xs, vt<T>& v, T fix = T())
{	// input vector<T> (T != struct) + fix
	v.resize(xs); rep(i, 0, xs) { cin >> v[i]; v[i] += fix; }
}
template <class T> void InputVVT
(ll ys, ll xs, vvt<T>& v, T fix = T())
{	// input vector<vector<T>> (T != struct) + fix
	MakeVVT(ys, xs, v, fix);
	rep(y, 0, ys) rep(x, 0, xs) { cin >> v[y][x]; v[y][x] += fix; }
}
template <class T> void InputVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fix = T())
{	// input vector<vector<vector<T>>> (T != struct) + fix
	v.resize(zs); rep(z, 0, zs) InputVVT(ys, xs, v[z], fix);
}

/**************************************/
/********** BEGIN OF NYA LIB **********/
/**************************************/

namespace NyaGadget {}

/**************************************/
/*********** END OF NYA LIB ***********/
/**************************************/

using namespace NyaGadget;
//using mll = NT_ModLL< 1000000007 >;
//using mll = NT_ModLL< 998244353 >;

int main(void)
{
	ll n; cin >> n;

	vt<ll> nyaa(n+1);
	rep(i, 0, n) cin >> nyaa[i] >> nyaa[i+1];

	ll const inf = Pow10(9);
	vvt<ll> dp; MakeVVT(n, n, dp, inf);
	rep(i, 0, n) dp[i][i] = 0;
	rep(range, 1, n) rep(l, 0, n)
	{
		ll r = l + range;
		if (n <= r) continue;
		rep(m, l, r) dp[l][r] = min(dp[l][r], dp[l][m] + dp[m+1][r] + nyaa[l] * nyaa[m+1] * nyaa[r+1]);
	}
	cout << dp[0][n-1] << endl;
	return 0;
}