Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

type Matrix struct {
	r int // num of row
	c int // num of column
}

type Range struct {
	start int // index, inclusive
	end   int // index, inclusive
}

func calcMultiplication(x, y Matrix) (Matrix, int) {
	if x.c != y.r {
		panic("cannnot calculate")
	}
	return Matrix{x.r, y.c}, x.r * y.c * x.c
}

func calcMinMatrixChainMultiplication(matrices []Matrix, r Range, memo map[Range]int) (Matrix, int) {
	if v, ok := memo[r]; ok {
		return Matrix{matrices[0].r, matrices[len(matrices)-1].c}, v
	}
	if len(matrices) == 0 {
		panic("must not be empty")
	} else if len(matrices) == 1 {
		return matrices[0], 0
	} else if len(matrices) == 2 {
		return calcMultiplication(matrices[0], matrices[1])
	}

	var minCount int = math.MaxInt32

	for i := 0; i < len(matrices)-1; i++ {
		formerMatrices := matrices[:i+1]
		latterMatrices := matrices[i+1:]
		matF, countF := calcMinMatrixChainMultiplication(formerMatrices, Range{0, i}, memo)
		matL, countL := calcMinMatrixChainMultiplication(latterMatrices, Range{i + 1, len(matrices) - 1}, memo)
		_, countFL := calcMultiplication(matF, matL)
		count := countF + countL + countFL
		if count < minCount {
			minCount = count
		}
	}
	return Matrix{matrices[0].r, matrices[len(matrices)-1].c}, minCount
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, _ := nextInt(sc)
	matrices := make([]Matrix, n)
	for i := 0; i < n; i++ {
		r, _ := nextInt(sc)
		c, _ := nextInt(sc)
		matrices[i] = Matrix{r, c}
	}
	memo := make(map[Range]int)
	_, resultCount := calcMinMatrixChainMultiplication(matrices, Range{0, len(matrices) - 1}, memo)
	fmt.Println(resultCount)
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include<bits/stdc++.h>
#define INF 100000000
using namespace std;
int n,m[101][101],p[101];
void dp();

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>p[i-1]>>p[i];
  dp();
  cout<<m[1][n]<<endl;
   
  return 0;
}
void dp(){
  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++){
       int a=m[i][k]+m[k+1][j]+p[i-2]*p[k-1]*p[j-1];
       if(m[i][j]>a)m[i][j]=a;
     }
    } 
}

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 (i = 1; i <= n; 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++: // #Sazaの1日1AC
#include <bits/stdc++.h>
using namespace std;
const long long mod = 10000;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P = pair<long long, long long>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vP = vector<pair<long long, long long>>;
//ショートカット
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, k, n) for (int i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v, N) for (long long i = 0; i < N; i++) cin >> v.at(i)
#define lin(n)long long n;cin >> n
#define chin(x)char x;cin >> x;
#define sin(s)string s;cin >> s;
#define vlin(v, N)vector<long long> v(N);for (long long i = 0; i < N; i++)cin >> v.at(i)
#define max(a, b) max((ll)a, (ll)b)
#define min(a, b) min((ll)a, (ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a = max(m, n);
  long long b = min(m, n);
  long long r = a % b;
  while (r != 0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m * n / gcd(m, n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret = 1;
  for (long long i = 0; i < N; i++)
    ret *= x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
  {
    long long t = repeat_squaring(x, n / 2);
    return t * t % mod;
  }
  else
    return x * repeat_squaring(x, n - 1);
}
//素因数分解(mapで返す)
map<long long, long long> factor(long long p){
  ll p1 = p;
  map<long long, long long> ret;
  for (long long i = 2; i * i <= p1; i++)
  {
    while (p % i == 0)
    {
      ret[i]++;
      p /= i;
    }
  }
  if (p != 1)
    ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for (long long i = 2; i * i <= N; i++)
  {
    if (N % i == 0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a, long long b){
  a = max(a, b);
}
//最小値更新
void chmin(long long &a, long long b){
  a = min(a, b);
}

//構造体
//Union-Find木
struct UnionFind
{
  //メンバ変数
  vector<long long> par; //par[i]:=頂点iの親
  vector<long long> s;   //s[i]:=頂点iが属する集合の個数(iが根のとき)

  //コンストラクタ
  UnionFind(long long N) : par(N), s(N){
    for (long long i = 0; i < N; i++)
    {
      par[i] = i; //最初はすべてが根として初期化
      s[i] = 1;
    }
  }
  //メンバ関数
  //root(i):=頂点iの根
  long long root(long long i){
    if (par[i] == i)
      return i;
    par[i] = root(par[i]); //経路圧縮
    return root(par[i]);   //再帰
  }
  //size[i]:=iが属する集合の個数
  long long size(long long i){
    return s[root(i)];
  }
  //same(x,y) xとyが同じ根を持つか(同じ集合に含まれるか)
  bool same(long long x, long long y){
    return root(x) == root(y);
  }
  //unite(x,y) xの根をyの根に繋げる(集合を合併)
  void unite(long long x, long long y){
    if (!same(x, y)){
      long long rx = root(x);
      long long ry = root(y);
      par[rx] = par[ry];
      s[ry] = s[rx] + s[ry];
    }
  }
};
//Binary Indexed Tree
struct BIT{
  vector<long long> bit;
  long long N;

  BIT(long long n){
    N = n;
    bit.resize(N + 1);
  }

  void add(long long i, long long w){
    for (long long x = i; x <= N; x += x & -x){
      bit[x] += w;
    }
  }
  long long sum(long long i){
    long long ret = 0;
    for (long long x = i; x > 0; x -= x & -x){
      ret += bit[x];
    }
    return ret;
  }
};
/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////




int main(){
  //doubleの桁数
  cout << fixed << setprecision(10);

  lin(N);
  vector<P> M(N);
  rep(i,N) cin >> M[i].first >> M[i].second;

  vvl dp(200,vl(200,INF));

  rep2(w,1,N+1){
    rep(l,N){
      ll r = l + w;
      if(r > N) continue;
      if(w == 1) dp[l][r] = 0;
      if(w == 2){
        dp[l][r] = M[l].first*M[l].second*M[r-1].second; continue;
      }
      for(ll mid = l+1; mid < r; mid++){
        chmin(dp[l][r], dp[l][mid] + dp[mid][r] + M[l].first*M[mid].first*M[r-1].second);
      }
    }
  }

  cout << dp[0][N] << endl;
}

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

int solve(int *cr, int n) {
  int m[101][101];
  for (int i = 1; i <= n; i++) m[i][i] = 0;

  for (int length = 2; length <= n; length++) {
    for (int begin = 1; begin <= n - length + 1; begin++) {
      int end = begin + length - 1;
      m[begin][end] = numeric_limits<int>::max();
      for (int k = begin; k <= end - 1; k++) {
        m[begin][end] = min(m[begin][end], m[begin][k] + m[k + 1][end] + cr[begin - 1] * cr[k] * cr[end]);
      }
    }
  }
  return m[1][n];
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  int cr[101];

  for (int i = 1; i <= n; i++) {
    cin >> cr[i - 1] >> cr[i];
  }

  cout << solve(cr, n) << endl;

  return 0;
}