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++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define Lens 105

using namespace std;
int p[Lens];
int C[Lens][Lens];
int N;

int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> p[i - 1] >> p[i];
		C[i][i] = 0;
	}
	for (int k = 1; k < N; k++)
	{
		for (int i = 1; i <= N-k; i++)
		{
			int j = i + k;
			C[i][j] = C[i][i] + C[i + 1][j]+p[i-1]*p[i]*p[j];
			for (int t = i+1; t < j; t++)
			{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
				C[i][j] = min(C[i][j], C[i][t] + C[t+1][j] + p[i - 1] * p[t] * p[j]);
			}
		}
	}
	cout << C[1][N]<<endl;

	return 0;

}

C++: // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const ll INF = 1000000007;

vector< vector<ll> > M(110, vector<ll>(110, 0));
vector<ll> P(110);
int N;

ll multiplication(){
    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 * 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]);
            }
        }
    }
    return M[1][N];
}

int main(){
    cin >> N;
    rep(i, N){
        cin >> P[i] >> P[i+1];
    }
    cout << multiplication() << endl;
}

C++: #include <iostream>

using namespace std;

int p[101], dp[101][101];

int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) cin >> p[i - 1] >> p[i];
	for (int i = 2; i <= n; ++i) {
		for (int j = 1; j <= n - i + 1; ++j) {
			int k = i + j - 1;
			dp[j][k] = 1e9;
			for (int l = j; l <= k - 1; ++l)
				dp[j][k] = min(dp[j][k], dp[j][l] + dp[l + 1][k] + p[j - 1] * p[l] * p[k]);
		}
	}
	cout << dp[1][n] << endl;

	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  vector<vi> dp(n + 1, vi(n, 0));
  vi p(n + 1);
  REP(i, n) cin >> p[i] >> p[i + 1];
  FOR(s, 2, n + 1) {     // 掛ける個数
    REP(l, n - s + 1) {  // 掛け始めるidx
      dp[s][l] = INF;
      FOR(ls, 1, s) {  // 分割
        auto r = l + ls;
        auto rs = s - ls;
        dp[s][l] =
            min(dp[s][l], dp[ls][l] + dp[rs][r] + p[l] * p[r] * p[l + s]);
      }
    }
  }
  cout << dp[n][0] << endl;
}

C++: #include <stdio.h>
#include <limits.h>
 
#define MAX 100
 
int A[MAX],B[MAX][MAX],n;
    
main(){
  int i,r,c;
 
  scanf("%d",&n);
 
  for(i=0; i<n; i++)
    {
      scanf("%d %d",&r,&c);
      A[i]=r;
      A[i+1]=c;
    }
 
  MatrixChain();
 
  return 0;
}

void MatrixChain()
{
 
  int i,j,k,l,cost;
 
  for(i=1; i<=n; i++)
    {
      B[i][i]=0;
    }
 
  for(l=2; l<=n; l++)
    {
      for(i=1; i<=n-l+1; i++)
    {
      j=i+l-1;
      B[i][j]=INT_MAX;
 
      for(k=i; k<=j-1; k++)
        {
          cost=B[i][k]+B[k+1][j]+A[i-1]*A[k]*A[j];
          if(cost < B[i][j])
        {
          B[i][j]=cost;
        }
        }
    }
    }
  printf("%d\n",B[1][n]);
}