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;

int main(){
	int n, p[101],m[101][101];
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>p[i-1]>>p[i];
		}
		
	for(int i=1 ; i<=101 ; 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;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;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384626433832795

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, in;
	vector<ll> v;
	cin >> n;
	rep(i, n) {
		cin >> in;
		v.push_back(in);
		cin >> in;
		if (i == n - 1)v.push_back(in);
	}
	vector<vector<ll>> vv(n, vector<ll>(n));
	for (int i = 1; i < n; i++) {
		vv[i - 1][i] = v[i - 1] * v[i] * v[i + 1];
	}
	for (int i = 2; i < n; i++) {
		for (int j = 0; i+j < n; j++) {
			ll ans;
			for (int k = 0; k <= i - 1; k++) {
				if (k == 0) {
					ans = vv[j][j + k] + vv[j + k+1][j + i] + v[j] * v[j + k + 1] * v[i + j + 1];
				}
				else {
					ll tmp = vv[j][j + k] + vv[j + k+1][j + i] + v[j] * v[j + k + 1] * v[i + j + 1];
					if (ans > tmp)ans = tmp;
				}
			}
			vv[j][i + j] = ans;
		}
	}
	cout << vv[0][n - 1] << endl;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
#define MAX 100


int P[MAX+1];
int n,j;
int m[MAX+1][MAX+1];
void matrix(){
  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++){
      j=i+l-1;
      m[i][j]=(1<<21);
      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;
}

int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>P[i-1]>>P[i];
    //printf("%d\n", P[i-1]);
  }
  matrix();

}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int n,p[101],m[101][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 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 <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
pii A[200];//firstは行secondを列とする
int dp[200][200];//dp[i][j]:=Ai...Ajの最小スカラー積とする
int n;
int f[200][200];//最適な括弧を挿入する位置
void solve(){
	for(int i =0;i < n;i++){
		for(int j =0;j < n;j++){
			if(i==j)dp[i][j]=0;
			else dp[i][j]=INF;
		}
	}
	
	for(int k =1;k <n;k++){//鎖の数
		for(int i =0;i <n-k;i++){//どこから始めるか
			for(int j =i;j <i+k;j++){//どこに括弧を挟むか
				int tmp =A[i].first*A[j].second*A[i+k].second;
				if(dp[i][i+k] >dp[i][j]+dp[j+1][i+k]+tmp){
					dp[i][i+k]=dp[i][j]+dp[j+1][i+k]+tmp;
					f[i][i+k] =j;
				}
			}
		}
	}
}

void print(int i,int j){//解を表示する
	if(i==j){
		cout <<"A"<<i;
	}else{
		cout <<"(";
		         print(i,f[i][j]);
		         print(f[i][j]+1,j);
		         cout <<")";
}
}


int main(){
	cin>>n;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for(int i =0;i < n;i++){
		cin>>A[i].first>>A[i].second;
	}
	solve();
	cout <<dp[0][n-1]<<endl;
	//print(0,n-1);
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 110
#define INF (int)(2<<29)

int main(){
	int n, r, c, m[MAX][MAX] = {}, p[MAX];
	
	cin>>n;
	
	for(int i = 1; i <= n; i++){
		cin>>r>>c;
		p[i-1] = r;
		p[i] = c;
	}
	for(int l = 2; l <= n; l++){
		for(int i = 1; i <= n-l+1; i++){
			int j = i + l - 1;
			m[i][j] = INF;
			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]);
			}
		}
	}
	// for(int i = 0; i <= n; i++){
		// for(int j = 0; j <= n; j++){
			// printf("%12d", m[i][j]);
		// }cout<<endl;
	// }
	
	cout<<m[1][n]<<endl;
	
	return 0;
}