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