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>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> R, C;
	int r, c;
	R.push_back(0);
	for (int i = 0; i < n; ++i) {
		cin >> r >> c;
		R.push_back(r);
	}
	R.push_back(c);

	int cost[100+1][100+1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			cost[i][j] = INT_MAX;
	for (int i = 1; i <= n; ++i)
		cost[i][i] = 0;

	for (int j = 1; j <= n - 1; ++j) {
		for (int i = 1; i <= n - j; ++i) {
			for (int k = i + 1; k <= i + j; ++k) {
				cost[i][i+j] = min(cost[i][i+j], cost[i][k-1] + cost[k][i+j] + R[i]*R[k]*R[i+j+1]);
			}
		}
	}

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

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int inf = INT32_MAX;

int main() {
  int n;
  cin >> n;
  V<int> column;

  rep(i, n) {
    int r, c;
    cin >> r >> c;
    if(i == 0) {
      column.push_back(r);
    }
    column.push_back(c);
  }

  V<V<int>> dp(n + 1, V<int>(n + 1));
  rep(i, n + 1) {
    dp[i][i] = 0;
  }

  int len = 2;
  while(len <= n) {
    for(int i = 1; i + len - 1 <= n; i++) {
      int j = i + len - 1;

      int min_cost = inf;
      for(int k = i; k < j; k++) {
        int cost = dp[i][k] + dp[k + 1][j] + column[i - 1] * column[k] * column[j];
        min_cost = min(min_cost, cost);
      }

      dp[i][j] = min_cost;
    }
    len++;
  }

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

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    vector<pair<int, int>> m(n);
    int a, b;
    rep(i, n) {
        cin >> a >> b;
        m[i] = make_pair(a, b);
    }
    vector<vector<int>> dp(n, vector<int>(n, INF));
    rep(i, n) dp[i][i] = 0;
    for (int len = 1; len <= n; len++) {
        for (int i = 0; i < n; i++) {
            int j = i + len - 1;
            if (j >= n)
                continue;
            for (int k = i; k < j; k++) {
                chmin(dp[i][j], dp[i][k] + dp[k + 1][j] +
                                    m[i].first * m[k].second * m[j].second);
            }
        }
    }
    cout << dp[0][n - 1] << endl;
}

C++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>

using namespace std;


int main(){

  int n;
  cin >> n;
  int m[n + 1][n + 1], p[n + 1];

  for(int i = 0; i < n; i++){
    cin >> p[i] >> p[i + 1];
    m[i][i] = 0;
  }
  m[n][n] = 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] = 1000000;
      for(int k = i; k < j; 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<cmath>
#include<algorithm>

using namespace std;

int main() {
	int n;
	int r[100];

	cin >> n;

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

	int m[100][100];

	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] + r[i - 1] * r[k] * r[j]);
			}
		}
	}
	cout << m[1][n] << endl;

	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<map>
using namespace std;
const int MAX_V = 100;
int a[MAX_V+1];
map<pair<int,int>, int> memo;

int dp(int s,int t){
  int &res=memo[make_pair(s,t)];
  if(res!=0) return res;
  if(t-s<2) return 0;
  int min=0x7fffffff;
  for(int i=s+1;i<=t-1;i++){
    int sum=dp(s,i)+dp(i,t)+a[s]*a[i]*a[t];
    if(sum<min){
      min=sum;
    }
  }
  res=min;
  return res;
}

int main(){
  int n; scanf("%d",&n);
  for(int i=0;i<n;i++){
    int fst,snd;
    scanf("%d %d",&fst,&snd);
    a[i]=fst; a[i+1]=snd;
  }
  int sum=dp(0,n);
  printf("%d\n",sum);
}

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 <string>
#include <algorithm>
using namespace std;

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

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

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 i = 2; i <= n; i++) {
		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][j] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;

	return 0;
}