Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

type matrixSize struct{ row, col int }

func calcNum(i, j matrixSize) int {
	return i.row * j.col * i.col
}

func parseProblem() (int, []matrixSize) {
	n := scanInt(sc)
	sizes := make([]matrixSize, n)
	for i := 0; i < n; i++ {
		sizes[i] = matrixSize{row: scanInt(sc), col: scanInt(sc)}
	}
	return n, sizes
}

var dp [][]int

func initDP(n int) {
	dp = make([][]int, n+1)
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, n+1)
		for j := 0; j < len(dp[i]); j++ {
			dp[i][j] = math.MaxInt64
		}
	}
}

func resolve(n int, sizes []matrixSize) int {
	// TODO 復習
	initDP(n)
	_rec(sizes, 0, n)
	return dp[0][n]
}

func _rec(sizes []matrixSize, l, r int) int {
	if dp[l][r] != math.MaxInt64 {
		return dp[l][r]
	}
	if r-l <= 1 {
		dp[l][r] = 0
		return 0
	}
	num := math.MaxInt64
	for i := l + 1; i < r; i++ {
		v := _rec(sizes, l, i) + _rec(sizes, i, r) + calcNum(matrixSize{sizes[l].row, sizes[i].row}, matrixSize{sizes[i].row, sizes[r-1].col})
		if v < num {
			num = v
		}
	}
	dp[l][r] = num
	return dp[l][r]
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<iostream>
#include<algorithm>
using namespace std;

static const int N = 100;

int main() {
	int n;
	int 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 = 0; 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 rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int n;
vector<ll> r, c;
auto memo = make_vec<ll>(110, 110);
ll dp(int i, int j) {
    if (memo[i][j] != -1) return memo[i][j];
    if (i == j) return memo[i][j] = 0;
    ll ret = LINF;
    for (int k = i; k < j; k++) {
        chmin(ret, dp(i, k) + dp(k + 1, j) + r[i] * c[k] * c[j]);
    }
    return memo[i][j] = ret;
}
int main() {
    cin >> n;
    r.resize(n);
    c.resize(n);
    rep(i, n) cin >> r[i] >> c[i];
    rep(i, 110) rep(j, 110) memo[i][j] = -1;
    cout << dp(0, n - 1) << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define INF 100100100100100

int main(){

    long long n; cin >> n;
    vector<long long> r(n);
    vector<long long> c(n);
    for(long long i = 0; i < n; i++){
        cin >> r[i] >> c[i];
    }

    vector<vector<long long> > dp(n + 1, vector<long long> (n + 1, INF));
    for(int i = 0; i < n; i++) dp[i][i + 1] = 0;
    
    for(int k = 2; k <= n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 1; j < k; j++){
                if(i + k <= n){
                    chmin(dp[i][i + k], dp[i][i + j] + dp[i + j][i + k] + r[i] * c[i + j - 1] * c[i + k - 1]);
                }
            }
        }
    }

    cout << dp[0][n] << endl;
    
    return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <climits>

/*
 * http://ttrsq.exblog.jp/24318687/
 */

const int MAX_N = 100;
int DP[MAX_N + 1][MAX_N + 1] = {0};
int *p;

int best(int r, int c) {
  int min = INT_MAX;
  int num = c - r;

  for (int i = 0; i < num; i++) {
    min = std::min(min, DP[r][r + i] + DP[r + i + 1][c] + p[r - 1] * p[r + i] * p[c]);
  }
  
  return min;
}

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

  int n = 0;
  std::cin >> n;

  if (n == 1) {
    std::cout << "1" << std::endl;
  }
  
  p = (int *) std::malloc(sizeof(int) * n + 1);

  int bb = 0;

  std::cin >> p[0];
  std::cin >> p[1];
  
  for (int i = 2; i <= n; i++) {
    std::cin >> bb;
    std::cin >> p[i];
  }

  for (int i = 1; i < n; i++) {
    DP[i][i + 1] = p[i - 1] * p[i] * p[i + 1];
  }

  for (int j = 0; j <= n - 3; j++) {
    for (int i = j + 3; i <= n; i++) {
      DP[i - 2 - j][i] = best(i - 2 - j, i);
    }
  }

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

  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;

static const in N = 100;

int main(){
  int j,i,l,n,p[N+1],m[N+1][N+1];
  scanf("%d",&n);

  for(i = 0;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }

  for(i = 1; i<=n;i++) m[i][i] = 0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      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 int long long
int n,dp[111][111],p[111];

int rec(int i,int j){
  int Min=2*1e9;
  for(int k=0;k<i-1;k++){
    Min=min(Min,dp[j+1][j+k+1]+dp[j+k+2][j+i]+p[j]*p[j+k+1]*p[j+i]);
  }
  return Min;
}

signed main(){
  cin>>n;
  cin>>p[0]>>p[1];
  for(int i=2;i<=n;i++){
    cin>>p[i]>>p[i];
  }
  for(int i=0;i<n;i++){
    dp[i][i]=0;
    if(i)dp[i][i+1]=p[i-1]*p[i]*p[i+1];
  }

  for(int i=3;i<=n;i++){
    for(int j=0;j+i<=n;j++){
      dp[j+1][j+i]=rec(i,j);
    }
  }
  cout<<dp[1][n]<<endl;
  return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;

#define N_MAX 100
#define C_MAX 100
#define R_MAX 100

int p[N_MAX+1];
int m[R_MAX+1][C_MAX+1];


int chain_multiplication(int n)
{
    for (int i = 0; i < n; i++) {
        m[i][i] = 0;
    }
    for (int l = 1; l < n; l++) {
        for (int i = 0; i < n - l; i++) {
            int j = i + l;
            m[i][j] = 100000000;
            for ( int k = i ; k < j; k++) {
                int a = m[i][k] + m[k+1][j] + p[i] * p[k+1] * p[j+1];
//                printf("i %d k %d j %d a %d min %d\n", i, k, j, a, m[i][j]);
                if (m[i][j] > a) {
                    m[i][j] = a;
                }
            }
//            printf("m[%d][%d] = %d\n", i, j, m[i][j]);
        }
    }
    return m[0][n-1];
}

int main() {
    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> p[i];
        cin >> p[i+1];
    }
    cout << chain_multiplication(n) << endl;
        
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
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;

}