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 INF 1 << 30
#define N 101
int main(void){
	int n,m[N][N],tmp[N];
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		cin >> tmp[i-1] >> tmp[i];
	}
	for(int i = 1 ; i <= n ; i++){
		m[i][i] = 0;
	}
	for(int j = 2; j<= n ; j++){
		for(int i = 1; i <= n- j + 1; i++){
			int k = i + j -1;
			m[i][k] = INF;
			for(int l = i; l <= k - 1 ; l++){
				m[i][k] = min(m[i][k],m[i][l] + m[l+1][k]+tmp[i-1] * tmp[l] * tmp[k]);
			}
		}
	}

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

}

C++: #include<iostream>
#include<vector>

const static int MAX = 1000;
const static int INF = 1001001001;

int M[MAX];
int C[MAX][MAX];

int main(void){
    int n;
    int trash;
    std::cin >> n;
    std::cin >> M[0];
    for(int i = 1; i <= n; i++){
	std::cin >> M[i];
	std::cin >> trash;
    }

    for(int i = 0; i < MAX; i++){
	for(int j = 0; j < MAX; j++){
	    C[i][j] = INF;
	}
    }

    for(int i = 0; i < MAX; i++){
	C[i][i] = 0;
    }


    for(int l = 2; l <= n; l++){
	for(int i = 1; i <= n - l + 1; i++){
	    int j = i + l - 1;
	    for(int k = i; k <= j; k++){
		int tmp = C[i][k] + C[k+1][j] + M[i-1] * M[k] * M[j]; 
		if(tmp < C[i][j]){
		    C[i][j] = tmp;
		}
	    }
	}
    }

    std::cout << C[1][n] << std::endl;

    return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1000000000
typedef long long ll;
using namespace std;

int main()
{
	ll n;
	cin >> n;
	vector<ll> M(n + 1);
	cin >> M[0];
	for (int i = 1; i < n; i++) {
		cin >> M[i] >> M[i];
	}
	cin >> M[n];
	vector<vector<ll>> dp(n, vector<ll>(n, INF)), mon(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		dp[i][i] = 0;
		mon[i][i] = i;
	}
	for (ll k = 1; k < n; k++) {
		for (ll i = 0; i + k < n; i++) {
			for (ll j = 0; j <= i + k - 1; j++) {
				ll cost = dp[i][j] + dp[j + 1][i + k] + M[i] * M[j + 1] * M[i + k + 1];
				if (cost < dp[i][i + k]) {
					dp[i][i + k] = cost;
					mon[i][i + k] = j;
				}
			}
		}
	}
	cout << dp[0][n - 1] << endl;
	return 0;
}

C++: /*
 * ALDS1_10_B.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>
#include<algorithm>

using namespace std;

struct Mat {
	int row;
	int col;
};

long mcm(Mat* M, int n) {
	long dp[101][101];
	for(int i=2; i<=n; i++) {
		for(int j=0; j<=n-i; j++) {
			dp[i][j] = 99999999999L;
			for(int k=1; k<i; k++) {
				dp[i][j] = min(dp[k][j]+dp[i-k][j+k]+M[j].row*M[j+k].row*M[j+i-1].col, dp[i][j]);
			}
		}
	}
	return dp[n][0];
}

int main() {
	int n;
	Mat M[100];

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

	cout << mcm(M, n) << endl;

}

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;
}

C++: #include <iostream>
#include<climits>
using namespace std;
int m[100][100];

int MCM(int p[],int n) {
	for (int i = 0; i < n; i++)
		m[i][i] = 0;
	for (int l = 2; l < n; l++) {
		for (int i = 1; i < n - l; i++) {
			int j = i + l - 1;
			m[i][j] = INT_MAX;
			for (int k = i; k <= j; k++) {
				int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
				if (m[i][j] > q) {
					m[i][j] = q;
				}

			}
		}

	}
	return m[0][n - 1];
}

int main() {
	int n, p[200];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[2*i] >> p[2*i + 1];
	}
	cout << MCM(p, n) << endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#define MAX 100
#define INFTY (1 << 21)
using namespace std;

int main() {
	int n, p[MAX + 1], mat[MAX + 1][MAX + 1];;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i - 1] >> p[i];
	}
	for (int i = 1; i <= n; i++) {
		mat[i][i] = 0;
	}
	for (int k = 2; k <= n; k++) {
		for (int i = 1; i <= n - k + 1; i++) {
			int j = i + k - 1;
			mat[i][j] = INFTY;
			for (int h = i; h <= j - 1; h++) {
				mat[i][j] = min(mat[i][j], mat[i][h] + mat[i][h] + mat[h + 1][j] + (p[i - 1] * p[h] * p[j]));
			}
		}
	}
	cout << mat[1][n] << 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;
}

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

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define all(v) (v).begin(), (v).end()

const int inf = 1e9+100;
vector<vector<int>> dp;
vector<int> a, b;

int dfs(int l, int r) {
    int& res = dp[l][r];
    if (res != inf) return res;
    if (r - l == 1) return res = 0;
    reps(i, l+1, r) {
        int t = dfs(l, i) + dfs(i, r) + a[l] * a[i] * b[r-1];
        res = min(res, t);
    }
    return res;
}

int main() {
    int n; cin >> n;
    a.resize(n); b.resize(n);
    rep(i, n) cin >> a[i] >> b[i];
    dp.resize(n+1, vector<int>(n+1, inf));
    cout << dfs(0, n) << endl;
}