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 rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
constexpr auto INF = 2147483647;
typedef long long ll;

// void DebugGrid(int row, int column, auto table){
//   cout << endl;
//   rep(i,row){
//     rep(j,column) cout << table[i][j] << " ";
//     cout << endl;
//   }
// }

int main(){

  ll ans, n, DP[100][100];
  vector<pair<int,int>> matrix;
  cin >> n;
  rep(i,n){
    pair<int,int> inp;
    cin >> inp.first >> inp.second;
    matrix.emplace_back(inp);
  }

  rep(i,n)rep(j,n) DP[i][j] = INF;
  for(int l=0; l<n; l++)for(int i=0; i<n-l; i++){
    if(l == 0) DP[i][i] = 0;
    else{
      for(int j=i;j<=i+l;j++){
      DP[i][i+l] = min(DP[i][i+l],DP[i][j]+DP[j+1][i+l] + (matrix[i].first*matrix[j].second*matrix[i+l].second));
      }
    }
  }

  // DebugGrid(n,n,DP);
  cout << DP[0][n-1] << endl;
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct mat {
	ll r, c;
};

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vector<mat> m(n);
	rep(i, n) cin >> m[i].r >> m[i].c;

	if(n == 1) {cout << 0 << endl; return 0; }

	vector<vll> dp(n, vll(n));
	rep(i, n) dp[i][i] = 0;
	int l, r;
	for(int d = 1; d <= n - 1; d++) {
		for(l = 0; l + d < n; l++) {
			r = l + d;
			dp[l][r] = INFL;
			for(int k = l; k + 1 <= r; k++) {
				dp[l][r] = min(dp[l][k] + dp[k + 1][r] + m[l].r * m[k].c * m[r].c, dp[l][r]);
			}
		}
	}
	cout << dp[0][n - 1] << endl;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = (1<<21);

int main() {
  int n;
  cin >> n;
  int cnt[n][n];
  int p[n+1];
  rep(i, n) {
    cin >> p[i] >> p[i+1];
  }

  rep(i, n) {
    rep(j, n) {
      if (i == j) cnt[i][j] = 0;
      else cnt[i][j] = INF;
    }
  }

  FOR(l, 1, n) {
    rep(i, n-l) {
      int j = i+l;
      FOR(k, i, j) {
        cnt[i][j] = min(cnt[i][j], cnt[i][k] + cnt[k+1][j] + p[i] * p[k+1] * p[j+1]);
      }
    }
  }

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



  
  return 0;
}

C++: #include <bits/stdc++.h>
#define N 110
using namespace std;
int A[N];
int dp[N][N];

int Min(int &a,int b){return a = min(a,b);}
int main(){
  int n;
  cin>>n;

  for(int i=0,cnt=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    if(i == 0) A[cnt++] = a;
    A[cnt++] = b;
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++)dp[i][j] = 1e9;
    dp[i][i] = 0;
  }
  
  for(int len=0;len<n;len++)
    for(int l=1;l<n;l++){
      int r = l+len;
      for(int m = l;m<r;m++){
        Min(dp[l][r],dp[l][m] + dp[m+1][r] + A[l-1]*A[m]*A[r]);
      }
}
  
  cout<<dp[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];

	scanf("%d", &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]);
				}
			}
		}

		printf("%d\n", m[1][n]);

		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;

int main() {
    int n; 
    cin >> n; 
    int r, c;
    vector<pair<int, int>> v; 
    vector<int> dims; 
    for (int i = 0; i < n; ++i) { 
            cin >> r >> c; 
            if (i == 0) { 
                dims.push_back(r);
            } 
        dims.push_back(c);
    }
    // for (int i = 0; i < dims.size(); ++i)
    //     cout << dims[i] << " ";
    int dp[n][n];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            dp[i][j] = 0;
    
    for (int len = 2; len <= n; ++len) { 
        for (int i = 0; i <= n - len; ++i) { 
            int j = i + len-1;
            // cout << i << " " << j <<" -> ";
            dp[i][j] = INT_MAX;
            for (int k = i; k < j; ++k) { 
                // cout << dp[i][k] << " " << dims[i] << " " << dims[k+1] << " " << dims[j+1] << endl;
               int q = dp[i][k] + dp[k+1][j] + dims[i]*dims[k+1]*dims[j+1]; 
               dp[i][j] = min(q, dp[i][j]);
            }
        }
    }
    // for (int i = 0; i < n; ++i) {
    //     for (int j = 0;j < n; ++j)
    //         cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    cout << dp[0][n-1] << endl;
   
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

#define MAX 100005
#define INF INT_MAX

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

P a[MAX];
map<P, int> memo;

int minMultTime(int s, int e)
{
    if (s >= e) return 0;
    if (memo[P(s,e)]) return memo[P(s,e)];

    int ans = INF;
    rep(i,e-s) {
        int m1 = minMultTime(s,s+i);
        int m2 = minMultTime(s+i+1,e);
        int m3 = a[s].first * a[s+i].second * a[e].second;
        ans = min(ans, m1+m2+m3);
    }
    memo[P(s,e)] = ans;

    return ans;
}

int main(int, char**)
{
    int n;
    cin >> n;

    rep(i,n) {
        cin >> a[i].first;
        cin >> a[i].second;
    }

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

    return 0;
}