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<cstdio>
#define INT_MAX 100000000
using namespace std;
int sentinel;
int Mi[1000][1000];

void calc(int p[]);

int main(){
  int p[1000],a,b;
  scanf("%d",&sentinel);
  for(int i=0;i<sentinel;i++){
    scanf("%d %d",&a,&b);
    p[i] = a;
    if(i == sentinel-1)p[i+1] = b;
  }

  sentinel = sentinel+1;
  calc(p);

  printf("%d\n",Mi[1][sentinel-1]);
  return 0;
}

void calc(int p[]){
  int n = sentinel-1,j,q,l,k;
  for(int i=1;i<=n;i++)Mi[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      j = i+l-1;
      Mi[i][j] = INT_MAX;
      for(int k=i;k<=j-1;k++){
        q = Mi[i][k] + Mi[k+1][j] + p[i-1]*p[k]*p[j];
        if(q<Mi[i][j]){
          Mi[i][j] = q;
        }
      }
    }
  }
}

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

#define INF 1e9

int main(void){
  int n, temp;
  cin >> n;

  vector<int> c(n+1);
  cin >> c[0] >> c[1];
  for(int i=2; i<n+1; i++)
    cin >> temp >> c[i];

  vector< vector<int> > dp(n, vector<int>(n+1, INF));
  for(int i=0; i<n; i++)
    dp[i][i+1] = 0;
  
  for(int i=2; i<n+1; i++)
    for(int j=0; j<n; j++)
      for(int k=1; k<i; k++)
	if(j+i < n+1)
	  dp[j][j+i] = min(dp[j][j+i],
			   dp[j][j+k]+dp[j+k][j+i]+c[j]*c[j+k]*c[j+i]);
  
  cout << dp[0][n] << endl;
  
  return 0;
}

C++: // ALDS1_10_B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

vector<int> r(110);
vector<int> c(110);
int inf=pow(10,9);
vector<vector<int>> dp(110,vector<int>(110,inf));
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    
    int n;
    cin>>n;
    rep(i,n) cin>>r[i]>>c[i];
    rep(i,n) dp[i][i]=0; //長さ1の計算量
    for(int L=2;L<=n;L++){ //長さ 短い長さからdpテーブルを埋めていく
        for(int i=0;i<=n-2;i++){ //始点
            int j=i+L-1; //終点
            if(n-1<j) break; //範囲オーバー 
            for(int k=i;k<=j-1;k++){ //i~k,k+1~jで区切る。区切ったブロックの長さは互いにL以下なので、すでに互いのブロックの最小コストはdpテーブルにある。
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*r[k+1]*c[j]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using ll = long long;
const int inf = 1e8;

int dp[105][105];

int main() {
    int n;
    cin >> n;
    vector<int> p(n+1);
    cin >> p[0] >> p[1];
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        p[i+2] = b;
    }
    rep(i,105)rep(j,105) dp[i][j] = inf;
    rep(i,n+1) dp[i][i] = 0;
    for (int i = n-1; i >= 1; i--) {
        for (int j = i+1; j <= n; j++) {
            if (j == i+1) dp[i][j] = p[i-1]*p[i]*p[i+1];
            else {
                for (int k = i; k <= j-1; k++) {
                    dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j]);
                }
            }
        }
    }
    cout << dp[1][n] << endl;
}

C++: #include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

#define INFTY 2000000000

int p[100], c[105][105];

void solve( int n ){

    int i, j, k, l;

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

    for( l = 2; l <= n; l++ ){

        for( i = 1; i <= n - l + 1 ; i++ ){

            j = i + l - 1;

            c[i][j] = INFTY;

            for( k = i; k <= j - 1; k++ ){

                c[i][j] = min( c[i][j], c[i][k] + c[k+1][j] + p[i-1] * p[k] * p[j] );

            }

        }

    }

}


int main(){

    int n, i, trash;

    scanf("%d", &n);

    for( i = 1; i <= n; i++ ){

        scanf("%d %d", &p[i-1], &p[i] );

    }

    solve(n);

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

}