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<bits/stdc++.h>
using namespace std;
#define int long long
int dp[111][111];
signed main(){
  int n;
  cin>>n;
  int r[n],c[n];
  for(int i=0;i<n;i++) cin>>r[i]>>c[i];
  int INF=1LL<<55LL;
  for(int i=0;i<111;i++) fill_n(dp[i],111,INF);
  for(int i=0;i<n;i++) dp[i][i+1]=0;
  for(int i=2;i<=n;i++)
    for(int j=0;j<=n-i;j++)
      for(int k=1;k<i;k++)
	dp[j][j+i]=min(dp[j][j+i],dp[j][j+k]+dp[j+k][j+i]+(r[j]*r[j+k]*c[j+i-1]));
  cout<<dp[0][n]<<endl;
  return 0;
}

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

const long N = 100;

int main(){
	long n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for (long i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];
	for (long i = 1; i <= n; i++) m[i][i] = 0;
	for (long l = 2; l <= n; l++){
		for (long i = 1; i <= n - l + 1; i++){
			long j = i + l - 1;
			m[i][j] = (1 << 21);
			for (long 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<cstdio>
#include<algorithm>
#define inf 1 << 21
#define MAX 100
using namespace std;

int m[MAX + 1][MAX + 1], p[MAX + 1],n;

void MCM(){
    
    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] = inf;
            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]);
            }
        }
    }
    printf("%d\n",m[1][n]);
}

int main(){
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%d %d",&p[i-1],&p[i]);
    MCM();
    return 0;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vector<pii> mat;
vvi dp;
int rec(int l, int r){
    if(dp[l][r] != INF) return dp[l][r];
    if(l == r) return dp[l][r] = 0;
    int res = INF;
    REP(i,l,r){
        int x = mat[l].fi * mat[i].se * mat[r].se;
        res = min(res, x + rec(l,i) + rec(i+1,r));
    }
    return dp[l][r] = res;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    mat = vector<pii>(n);
    rep(i,n){
        int r, c; cin >> r >> c;
        mat[i] = pii(r, c);
    }
    dp = vvi(n, vi(n, INF));
    if(n == 1) cout << 0 << endl;
    else cout << rec(0, n-1) << endl;
    return 0;
}

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

static const int N = 100;

struct Matrix{int row, col;};
Matrix M[N];
int cost[N][N] = {0};

int prod(int begin, int end){
  int mincost = 100000000, l = end - begin;
  if(cost[begin][end] > 0){
    return cost[begin][end];
  } else {
    if(l == 0){
      mincost = 0;
    } else if(l == 1){
      cost[begin][end] = M[begin].row * M[begin].col * M[end].col;
      mincost = cost[begin][end];
    } else {
      int temp;
      for(int i = 0; i < l; i++){
        temp = prod(begin, begin + i) + prod(begin + i + 1, end);
        temp += M[begin].row * M[begin + i].col * M[end].col;
        mincost = min(mincost, temp);
      }
      cost[begin][end] = mincost;
    }
    return mincost;
  }
}

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> M[i].row >> M[i].col;
  }

  cout << prod(0, n - 1) << endl;

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <climits>

using namespace std;


int main()
{
    int n;
    int p[101];
    int m[101][101];

    cin >> n;

    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            m[i][j] = 0;

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

    for (int len = 1; (n - 1) - len >= 0; len++) {
        for (int i = 0; i <= (n - 1) - len; i++) {
            m[i][i + len] = INT_MAX / 3;
            for (int j = i; j < i + len; j++) {
                m[i][i + len] = min(m[i][i + len], m[i][j] + m[j + 1][i + len] + p[i] * p[j + 1] * p[i + len + 1]);
            }
        }
    }

    cout << m[0][n - 1] << endl;

    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cassert>
#include <memory.h>
#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <cassert>
typedef unsigned long long ull;
typedef unsigned long ul;
#define rep(i,n) for(unsigned long long i = 0;i<n;i++)
#define clear(c) memset(c,0,sizeof(c))
#define clearm(c) memset(c,-1,sizeof(c))
using namespace std;

int main(){
	int n;

	cin >> n;
	ull dp[100+1][100+1];
	clearm(dp);
	ull r[n],c[n];
	rep(i,n){
		int rr,cc;
		cin >> rr >> cc;
		r[i] = rr;
		c[i] = cc;
	}
	rep(i,n-1){
		dp[i][i+1] = r[i] * c[i+1] * r[i+1];
	}
	rep(i,n){
		dp[i][i] = 0;
	}
	for(int dif = 2;dif<n;dif++){
		for(int i = 0;i + dif<n;i++){
			for(int j = i + 1;j <= i +dif - 1;j++){
				dp[i][i+dif] = min(dp[i][i+dif],dp[i][j] + dp[j+1][i+dif] + r[i] * c[j] * c[i+dif]);
			}
		}
	}
	cout << dp[0][n-1] << endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>
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][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}

	cout << m[1][n] << endl;

    return 0;
}