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 <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 <algorithm>
#include <vector>
#include <climits>
#define range(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
using namespace std;

int n;
int m[110][110];
int p[110];

int matrixChainMultiplication() {
  rep1(i, n) m[i][i] = 0;

  range(l, 2, n) {
    rep1(i, n - l + 1) {
      int j = i + l - 1;
      m[i][j] = INT_MAX;
      range(k, i, j - 1) {
        m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
      }
    }
  }
  return m[1][n];
}

int main() {
  cin >> n;
  rep1(i, n) {
    cin >> p[i - 1] >> p[i];
  }
  cout << matrixChainMultiplication() << endl;
  return 0;
}

C++: //ALDS1_10B Matrix Chain Multiplication
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

static const int N=100;
vector<int> p(N+1);
vector< vector<int> > m(N+1,vector<int>(N+1));

int main(){
 int n;
 cin >> n;
 for(int i=1;i<=n;i++){
 cin>>p[i-1]>>p[i];
 }
 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<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int dp[100][100];
	int P[101];

	int n;
	cin >> n;
	cin >> P[0] >> P[1];
	for (int i = 1; i < n; i++)
	{
		int t;
		cin >> t >> P[i + 1];
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; (j + i) < n; j++)
		{
			if (i == 0)
			{
				dp[j][j + i] = 0;
			}
			else if (i == 1)
			{
				dp[j][j + i] = P[j] * P[j + 1] * P[j + 2];
			}
			else
			{
				int mini = 10000000;
				for (int k = 0; k < i; k++)
				{
					mini = min(mini, dp[j][j + k] + dp[j + k + 1][j + i] + P[j] * P[j + k + 1] * P[j + i + 1]);
				}
				dp[j][j + i] = mini;
			}
		}
	}

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

	return 0;
}

C++: //#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;
static const int N = 100;

int main(){
  //int i,j,k,l;
  int n,p[N+1],m[N+1][N+1];
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> p[i-1];
    cin >> 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] = INFINITY;
      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 rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

vl R, C;

vector<vl> dp;

ll calc(int l, int r) {
    if(dp[l][r] != INF) return dp[l][r];
    auto& ret = dp[l][r];
    if(r - l == 1) return ret = 0;
    if(r - l == 2) return ret = R[l] * C[l] * C[l+1];
    for(int m = l + 1; m < r; ++m) {
        chmin(ret, R[l] * C[m-1] * C[r-1] + calc(l, m) + calc(m, r));
    }
    return ret;
}

int main(){
    int n;
    cin >> n;
    R.resize(n);
    C.resize(n);
    rep(i, n) cin >> R[i] >> C[i];
    dp = vector<vl>(n+1, vl(n+1, INF));
    cout << calc(0, n) << endl;
    return 0;
}

C++: // http://algorithms.blog55.fc2.com/blog-entry-66.html

#include <stdio.h>
#include <string.h>

#define M 100

int N,R[M+1],C[M][M],B[M][M];

void compute(){
	int i=0,j,k,cost;
	memset(C,99,sizeof(C));
	for(;i<N;i++)C[i][i]=0;
	for(j=1;j<N;j++)
		for(i=0;i<N - j; i++ )
			for (k = i; k < i + j; k++ ){
				cost = C[i][k] + C[k+1][i+j] + R[i]*R[k+1]*R[i+j+1];
				if(cost<C[i][i+j])C[i][i+j]=cost,B[i][i+j]=k; 
			}
}

void order( int i, int j ){
	if(i==j)printf("M%d",i);
	else{
		printf("(");
		order( i, B[i][j]-1 ); order(B[i][j], j);
		printf(")");
	}
}

void input(){
	scanf("%d",&N);
	int z,i=0;
	for(;i<N;i++)scanf("%d%d",R+i,z);
	R[i]=z;
}

void output(){
	printf("%d\n",C[0][N-1]);
	//order(0, N);
	//puts("");
}

main(){
	input();
	compute();
	output();
}

C++: #include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

ll DP[105][105];
ll larr[105], rarr[105];

ll solve(int l, int r){
    if(DP[l][r] != 0) return DP[l][r];
    for(int i=l;i<r;++i){
        if(DP[l][r] == 0) DP[l][r] = solve(l, i) + solve(l+1, r) + larr[l] * rarr[i] * rarr[r];
        else DP[l][r] = min(solve(l, i) + solve(i+1, r) + larr[l] * rarr[i] * rarr[r], DP[l][r]);
    }
    return DP[l][r];
}

int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>larr[i]>>rarr[i];
    }
    cout<<solve(0, n-1)<<endl;
}