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;
#define MAX 100
#define INF 1<<30

int main(void){
  int n, p[MAX+1], m[MAX][MAX];
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> p[i] >> p[i+1];
  }

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

  for(int l=1; l<n; l++){ // iとjの差を1からn-1まで変化させる
    for(int i=1; i<=n-l; i++){
      int j = i + l; // l-1がiとjの差
      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]);
      }
    }
  }
  cout << m[1][n] << endl;
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
const int N = 100;
int main() {
	int n;
    int p[N + 1], a[N + 1][N + 1];
	cin >> n;
	for( int i = 0; i < n; ++i ) {
		cin >> p[i] >> p[i + 1];
	}
	for( int i = 1; i <= n; i++ ) a[i][i] = 0;

	for( int m = 2; m <= n; m++ ) { 
		for( int i = 1; i <= n - m + 1; i++ ) {
			int j = i + m - 1;
			a[i][j] = ( 1 << 21 );
			for( int k = i; k<=j - 1; k++) {
				a[i][j] = min(a[i][j], a[i][k] + a[k+1][j] + 
					p[i-1] * p[k] * p[j] );
			}
		}
	}
	cout << a[1][n] << endl;
}

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

int x[101];
int S[101][101];

int solve(int n){
  for(int i = 2; i <= n; i++){
    for ( int l = 1; l <= n - i + 1 ; l++){
      // l は 始まりの数
      int j = l + i - 1; // 終わりの数
      S[l][j] = 100000;
      for ( int k = l; k <= j-1; k++){
        S[l][j] = min(S[l][j], S[l][k] + S[k+1][j] + x[l-1]*x[k]*x[j]);
      }
    }
  }

 return S[1][n];
}

int main(){
  int n;
  cin >> n;
  int r, c;
  for ( int i = 0; i < n; i++){
    cin >> r >> c;
    if(i == 0){
      x[0] = r;
      x[1] = c;
   } else {
     x[i+1] = c;
   }
  }

  // init
  for ( int i = 0; i <= n; i++){
    S[i][i] = 0;
  }

  cout << solve(n) << endl;

  return 0;
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_B&lang=ja
//Matrix Chain Multiplication
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
#if LOCAL&01
	//std::ifstream in("./test/sample-1.in");
	std::ifstream in("./input.txt");
	std::cin.rdbuf(in.rdbuf());
#else
	cin.tie(0);
	ios::sync_with_stdio(false);
#endif
  ll n; cin>>n;
  vector<pair<ll,ll>> rcn(n);
  for(auto&& rc:rcn){
   cin>>rc.first>>rc.second;
  }
	vector<vector<ll>> dp(n,vector<ll>(n+1,-1));
  auto dfs = [&](auto&& self, ll l, ll r)->ll{
    if(l+1>=r)return 0;
		if(dp[l][r]>=0)return dp[l][r];
    ll ret=INT64_MAX;
    FOR(k,l+1,r){
      ll mulnum = rcn.at(l).first * rcn.at(k).first * rcn.at(r-1).second;
      chmin(ret, self(self,l,k)+self(self,k,r) + mulnum);
    }
		dump(l,r,ret);
		dp[l][r]=ret;
    return ret;
  };

	ll ans=dfs(dfs,0,n);
	cout<<ans<<endl;

  return 0;
}

C++: #include<stdio.h>
int main()
{
  int n,r[100],c[100][100];
  int i,j,k,l,m;
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&r[i],&j);
  }
  r[n]=j;
  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]=1000000;
      for(k=i;k<=j-1;k++){
    m=c[i][k]+c[k+1][j]+(r[i-1]*r[k]*r[j]);
       
    if(c[i][j]>m){
      c[i][j]=m;
    }
      }
    }
  }
  printf("%d\n",c[1][n]);
   
  return 0;
}

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

int main() {
  uint32_t n = 0;
  std::cin >> n;
  std::vector<uint32_t> mat(n + 1);
  for (uint32_t i = 0; i < n; i++) {
    std::cin >> mat[i] >> mat[i + 1];
  }

  std::vector<std::vector<uint32_t>> dp(n + 1,
                                        std::vector<uint32_t>(n + 1, -1));
  for (size_t i = 0; i < dp.size(); i++) dp[i][i] = 0;

  for (size_t d = 1; d < n; d++) {
    for (size_t i = 1; i < dp.size() - d; i++) {
      for (size_t j = 0; j < d; j++) {
        dp[i][i + d] =
            std::min(dp[i][i + d], mat[i - 1] * mat[i + j] * mat[i + d] +
                                       dp[i][i + j] + dp[i + j + 1][i + d]);
      }
    }
  }

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

  return 0;
}

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

int main(void) {
	int n, i, j, k, len;
	cin >> n;
	int p[n + 1], m[n + 1][n + 1];
	for (i = 0; i <= n; i++)
	{
		if (i == 0) {
			cin >> p[i];
		} else if (i == 1) {
			cin >> p[i];
		} else {
			cin >> p[i] >> p[i];
		}
	}

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

	for (len = 2; len <= n; len++) {
		for (i = 1; i <= n - len + 1; i++) {
			j = i + len - 1;
			m[i][j] = INT_MAX;
			for (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;
}