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++: #define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








int main(){
    int n; std::cin >> n;
    std::vector<int> r(n), c(n);
    for(int i(0); i < n; ++i) std::cin >> r[i] >> c[i];
    //dp[i][j] := iからjまでの計算に必要な回数
    std::vector<std::vector<int>> dp(n, std::vector<int>(n, 0));
    for(int d(1); d < n; ++d){
        for(int i(0), i_len(n - d); i < i_len; ++i){
            int j(i + d);
            dp[i][j] = INF;
            for(int k(i); k < j; ++k){
                chmin(dp[i][j], dp[i][k] + dp[k+1][j] + r[i]*c[k]*c[j]);
            }
        }
    }
    std::cout << dp[0][n-1] << std::endl;
    return 0;
}

C++: // ALDS 1_10_B
#include<cstdio>
#include<cstring>
#include<vector>
#define rep(i,a) for( int i = 0; i != (a); ++i )
#define repi(i,a,b) for( int i = (a); i != (b); ++i )

const int INF = 1<<28;

int n;
std::vector<int> r(100);
std::vector<std::vector<int> > dp( 100, std::vector<int>( 100, INF ) );

int main()
{
	scanf( "%d", &n );
	rep( i, n )
		scanf( "%d%d", &r[i], &r[i+1] );

	rep( i, n )
		dp[i][i] = 0;

	repi( k, 1, n ) rep( i, n-k ) repi( j, i, i+k )
		dp[i][i+k] = std::min( dp[i][i+k], dp[i][j]+dp[j+1][i+k]+r[i]*r[j+1]*r[i+k+1] );	

	printf( "%d\n", dp[0][n-1] );

	return 0;
}

C++: #include <iostream>
#include <limits>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
        int r, c;
        cin >> r >> c;
        v.emplace_back(r, c);
    }

    vector<vector<int>> dp(n, vector<int>(n, numeric_limits<int>::max()));

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

    auto cost = [&v](int i, int k, int j) {
        return v[i].first * v[k].second * v[j].second;
    };

    // auto p = [&dp, n] {
    //    for (int i = 0; i < n; ++i) {
    //        for (int j = 0; j < n; ++j) {
    //            cout << dp[i][j] << ' ';
    //        }
    //        cout << endl;
    //    }
    //    cout << endl;
    //};
    for (int l = 2; l <= n; ++l) {
        for (int i = 0; i < n - l + 1; ++i) {
            int j = i + l - 1;
            for (int k = i; k < j; ++k) {
                dp[i][j] =
                    min(dp[i][j], dp[i][k] + dp[k + 1][j] + cost(i, k, j));
            }
        }
    }
    cout << dp[0][n - 1] << endl;
}

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

#define INF 100000001

using namespace std;

int DP[101][101];
int *p;

int rec(int r, int c){
  int Min = INF;
  int num = c-r;

  for (int i = 0; i < num; i++){
    Min = min(Min, DP[r][r+i] + DP[r+i+1][c] + p[r-1]*p[r+i]*p[c]);
  }
  return Min;
}
  int main(){
    int N;
    cin >> N;
    for(int i = 1; i <= N; i++) DP[i][i] = 0;

    p = (int *)malloc(sizeof(int)*(N+1));

    cin >> p[0];
    cin >> p[1];
      int bb;
    for(int i = 2; i <= N; i++){
      cin >> bb;
      cin >> p[i];
    }

    for(int i = 1; i < N; i++) DP[i][i+1] = p[i-1]*p[i]*p[i+1];

    for(int j = 0; j <= N-3; j++){
      for(int i = 3+j; i <= N; i++){
	DP[i-2-j][i] = rec(i-2-j,i);
      }
    }

    cout << DP[1][N] << endl;

    return 0;
  }

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

static const int N = 100;

int main()
{
	int n;
	int p[N + 1];
	int 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 << 27);
			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;

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