Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for 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])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

C++: #ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)\
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

constexpr auto no_value = numeric_limits<uint64_t>::max();

uint64_t solve(const vector<pair<int, int>>& mat) {
  if (mat.size() < 2) {
    return 0ULL;
  }
  auto n = mat.size();
  vector<vector<uint64_t>> cache(n - 1, vector<uint64_t>(n, no_value));
  for (size_t range = 2; range <= n; ++range) {
    for (size_t first = 0; ; ++first) {
      auto last = first + range - 1;
      if (last == n) {
        break;
      }
      for (size_t mid = first; mid != last; ++mid) {
        auto lhs = first == mid ? 0 : cache[first][mid];
        auto rhs = (mid + 1) == last ? 0 : cache[mid + 1][last];
        auto mul = mat[first].first * mat[last].second * mat[mid].second;
        cache[first][last] = min(cache[first][last], lhs + rhs + mul);
      }
    }
  }
  return cache[0][n - 1];
}

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> mat;
  for (int i = 0; i < n; ++i) {
    int row, col;
    cin >> row >> col;
    mat.push_back(make_pair(row, col));
  }
  uint64_t result = solve(mat);
  cout << result << endl;
}

C++: #pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
int r[105],c[105],dp[105][105]={0};
int main(){
	int i,j,k,n,len;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d%d",&r[i],&c[i]);
	for(i=0;i<n-1;i++)
		dp[i][i+1]=r[i]*c[i]*c[i+1];
	for(len=3;len<=n;len++){
		for(i=0;i<n-len+1;i++){
			j=i+len-1;
			dp[i][j]=2147483647;
			for(k=i;k<j;k++){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*c[k]*c[j]);
			}
		}
	}
	printf("%d\n",dp[0][n-1]);
}

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

int solve(int n, vector<int> & dims){
    int dp[100][101] = {{0}};
    for (int span = 2; span != n + 1; ++span){
        for (int first = 0; first + span != n + 1; ++first){
            for (int last = first + span; last != n + 1; ++last){
                int record = 2000000000;
                for (int mid = first + 1; mid != last; ++mid){
                    record = min(record, dp[first][mid] + dp[mid][last] + dims[first] * dims[last] * dims[mid]);
                }
                dp[first][last] = record;
            }
        }
    }
    return dp[0][n];
}


int main()
{
    int n = 0;
    cin >> n;
    vector<int> dims(n + 1);
    int r = 0;
    int c = 0;
    for (int i = 0; i != n; ++i){
        cin >> r >> c;
        dims[i] = r;
    }
    dims[n] = c;
    cout << solve(n, dims) << endl;
    return 0;
}

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;
}