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 <limits.h>
using namespace std;

int main() 
{
	int n, m[101][101], p[101];
	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 j = 2; j <= n; j++) 
	{
		for (int i = 1; i <= n - j + 1; i++) 
		{
			int k = i + j - 1;
			m[i][k] = INT_MAX;
			for (int l = i; l <= k - 1; l++)
				m[i][k] = min(m[i][k], m[i][l] + m[l + 1][k] + p[i - 1] * p[l] * p[k]);
		}
	}

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

	return 0;
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;

static const int N = 100;

int main(){
  int n, p[N + 1], m[N + 1][N + 1];
  cin >> n;l <= n; l++){
  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 - 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 <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N;
int R[110], C[110];

// [i, j) ???????????????????????°????°?
int dp[110][110];

signed main() {
    cin >> N;
    rep(i,0,N) cin >> R[i] >> C[i];
    repq(i,0,N) {
        repq(j,0,N) {
            if(i < j && j-i != 1) {
                dp[i][j] = dp[i][j-1] + R[i] * R[j-1] * C[j-1];
                // printf("dp[%lld][%lld] = %lld\n", i, j, dp[i][j]);
            }
        }
    }

    repq(i,3,N) {
        rep(j,0,N-i+1) {
            rep(k,j+1,j+i-1) {
                chmin(dp[j][j+i], 
                      dp[j][k] + dp[k][j+i] + R[j] * R[k] * C[j+i-1]);
            }
        }
    }
    cout << dp[0][N] << endl;
    return 0;
}

C++: /*
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int rs[MAX_N], cs[MAX_N];
int dp[MAX_N][MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) cin >> rs[i] >> cs[i];

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

  int sum = 0;

  for (int l = 1; l < n; l++)
    for (int i0 = 0, i1 = l; i1 < n; i0++, i1++) {
      dp[i0][i1] = INF;
      for (int j = i0; j < i1; j++) {
	int d = rs[i0] * cs[j] * cs[i1] + dp[i0][j] + dp[j + 1][i1];
	if (dp[i0][i1] > d) dp[i0][i1] = d;
      }
    }

  printf("%d\n", dp[0][n - 1]);
  return 0;
}

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

using namespace std;
#define N 100

int main(){
  int n;
  int M[N+1][N+1],p[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 j=1;j<=n-i+1;j++){
      int k=j+i-1;
      M[j][k] = (1 << 21);
      for(int l=j;l<= k-1 ; l++){
        M[j][k] = min(M[j][k],M[j][l]+M[l+1][k]+p[j-1]*p[l]*p[k]);
      }
    }
  }
  cout <<M[1][n]<<endl;
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1e9;
int n;
int r[102],c[102];
int p[102];

int dp[102][102];
// [i,j)
int dfs(int i,int j) {
    //cout<<i<<", "<<j<<endl;
    if(dp[i][j]!=-1) return dp[i][j];
    if(j-i==1) return r[i]*c[i]*c[j-1];
    if(i==j) return 0;
    int ret=INF;
    for(int k=i+1;k<j;k++) {
        //ret=min(ret,dfs(i,k)+dfs(k,j)+r[i]*c[k]*c[j-1]);
        ret=min(ret,dfs(i,k)+dfs(k,j)+p[i]*p[k]*p[j]);
    }

    return dp[i][j]=ret;
}

int main() {
    memset(dp,-1,sizeof(dp));
    cin>>n;
    //rep(i,n) cin>>r[i]>>c[i];
    rep(i,n+1) if(i) cin>>p[i-1]>>p[i];
    cout<<dfs(0,n)<<endl;
    return 0;
}

C++: #include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 1e2 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int n;
int a[MAXN],b[MAXN];
int f[MAXN][MAXN];

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
    for(int len=2;len<=n;len++){
        for(int i=1;i+len-1<=n;i++){
            int j=i+len-1;
            for(int k=i;k<j;k++){
                if(f[i][j]==0) f[i][j]=f[i][k]+f[k+1][j]+a[i]*b[k]*b[j];
                else f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]+a[i]*b[k]*b[j]);
            }
        }
    }
    printf("%d\n",f[1][n]);
}

int main(){
    work();
    return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;

int calc(vii& dp, const vector<pair<int, int>>& M, int i, int j) {
    if (i == j) { return 0; }
    if (dp[i][j] != 0) { return dp[i][j]; }

    int mul = M[i].first * M[j].second;
    int tmp = calc(dp, M, i + 1, j) + mul * M[i].second;
    rep(k, i + 1, j) {
        tmp = min(tmp, calc(dp, M, i, k) + calc(dp, M, k + 1, j) + mul * M[k].second);
    }
    return dp[i][j] = tmp;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<pair<int, int>> M(n);

    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        M[i] = make_pair(x, y);
    }

    vii dp(n, vi(n, 0));

    cout << calc(dp, M, 0, n - 1) << endl;

    return 0;
}