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++: /*
 * aoj/alds1_10_b_2nd/main.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const ll INF = 100000000000000000;
// 1 1
// 1 1
// 1 1
//
// 1 1 1
// 1 1 1
//
struct Mat {
  ll r, c, count;
  Mat operator * (Mat v) {
    assert(c == v.r);
    ll numOp = r * v.c * c;
    return (Mat){ r, v.c, numOp + count + v.count };
  }
  bool operator == (const Mat &v) const {
    return r == v.r && c == v.c;
  }
  bool operator < (const Mat &v) const {
    assert(v.count == INF or (r == v.r and c == v.c));
    return count < v.count;
  }
  bool operator > (const Mat &v) const {
    // cout << r << " " << v.r << " " << c << " " << v.c << " " << count << " " << v.count << endl;
    assert(v.count == INF or count == INF or (r == v.r and c == v.c));
    return count > v.count;
  }
};

const int MAX = 110;
ll N;
vector<Mat> A;

// dp[l][r] := [l:r)の範囲の行列を掛け算する時の最小回数.
Mat dp[MAX][MAX];

void input() {
  cin >> N;
  ll r, c;
  loop(n,0,N) {
    cin >> r >> c;
    A.push_back({ r, c, 0 });
  }
}

ll receive() {
  for (int len=0; len<=N; len++) {
    for (int l=0; l+len<=N; l++) {
      int r = l+len;
      dp[l][r] = Mat({ 0, 0, INF });
    }
  }

  for (int l=0; l<N; l++) dp[l][l+1] = A[l];
  for (int len=2; len<=N; len++) {
    for (int l=0; l+len<=N; l++) {
      int r = l+len;
      for (int k=l+1; k<r; k++) {
        chmin(dp[l][r], dp[l][k] * dp[k][r]);
      }
    }
  }

  return dp[0][N].count;
}

void solve() {
  cout << receive() << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e14;

signed
main(){
		int n;
		cin >> n;
		vector<ll> p(n+1);
		for(int i=0;i<n;i++)
		{
				cin >> p[i] >> p[i+1];
		}
		vector<vector<ll> > m(n+1,vector<ll>(n+1, INF));

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

		for(int sa=1;sa<n;sa++)
		{
				for(int fi=1;fi<=n-sa;fi++)
				{
						int la = fi + sa;
						for(int medi=fi;medi<=la-1;medi++)
						{
								m[fi][la] = min(m[fi][la],m[fi][medi] + m[medi+1][la] + p[fi-1]*p[medi]*p[la]  );
						}
						
				}
		}

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

C++: /******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

//return the cost
int cal(int a[],int i, int j){
    if(i==j) return 0;
    int min = 1<<30;
    //printf("%d\n",min);
    for(int k = i; k<j; k++){
        int count = cal(a, i, k)+cal(a,k+1, j)+a[i-1]*a[k]*a[j];
        if(count<min) min = count;
    }
    
    return min;
}

int main()
{
    int n;
    scanf("%d",&n);
    int x[n+2], y[n+2];
    int dp[n+1][n+1];
    for(int i = 1; i<=n; i++){
        scanf("%d %d",&x[i],&y[i]);
    } x[n+1] = y[n];
    
    printf("%d\n",cal(x, 2,n+1));
    return 0;
}

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

using namespace std;
static const int N = 100;


void solve(vector<int> &data)
{
	vector<vector<int> > dp(N + 1, vector<int>(N + 1, 0));

	int nums = data.size() - 1;
	for (int len = 2; len <= nums; ++len)
	{
		for (int l = 1; l <= nums - len + 1; ++l)
		{
			int r = l + len - 1;
			dp[l][r] = INT_MAX;
			for (int m = l; m <= r - 1; ++m)
			{
				cout << len << " " << l << " " << r << endl;
				dp[l][r] = min(dp[l][r], dp[l][m] + dp[m+1][r] + data[l - 1] * data[m] * data[r]);
			}
		}
	}

	cout << dp[1][nums] << endl;
}

int main()
{
	int num; cin >> num;
	vector<int> data(num + 1);
	for (int i = 1; i <= num; ++i)
		cin >> data[i-1] >> data[i];

	solve(data);
}

C++: #include<iostream>
#define INF 100000000
using namespace std;
int n,m[101][101],p[101];
void dp(){
  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]=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]);
    } 
}

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

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

class TMinimumMultiplications
{
	std::vector<std::vector<int> > FTable;
	std::vector<std::pair<int, int> >& FMatrixChain;
	
	int GetMinimum(int Begin, int End);
public:
	TMinimumMultiplications(std::vector<std::pair<int, int> >& MatrixChain);
	
	int Get(int Begin, int End);
};

TMinimumMultiplications::TMinimumMultiplications(std::vector<std::pair<int, int> >& MatrixChain)
: FMatrixChain(MatrixChain), FTable(MatrixChain.size(), std::vector<int>(MatrixChain.size(), -1))
{
}

int TMinimumMultiplications::GetMinimum(int Begin, int End)
{
	int Minimum = INT_MAX;
	for(int i = Begin; i < End; ++i){
		int Total = Get(Begin, i) + Get(i + 1, End) + FMatrixChain[Begin].first * FMatrixChain[i + 1].first * FMatrixChain[End].second;
		if(Minimum > Total) Minimum = Total;
	}
	return Minimum;
}

int TMinimumMultiplications::Get(int Begin, int End)
{
	if(Begin == End) return 0;
	if(FTable[Begin][End] < 0){
		FTable[Begin][End] = GetMinimum(Begin, End);
	}
	return FTable[Begin][End];
}

int main()
{
	int Count;
	std::cin >> Count;
	std::vector<std::pair<int, int> > MatrixChain;
	for(int i = 0; i < Count; ++i){
		int Row, Col;
		std::cin >> Row >> Col;
		MatrixChain.push_back(std::make_pair(Row, Col));
	}
	TMinimumMultiplications Minimum(MatrixChain);
	std::cout << Minimum.Get(0, MatrixChain.size() - 1) << std::endl;
	return 0;
}