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 <cstdio>

struct Matrix
{
  int row;
  int column;
  int multiple_time;

  Matrix():
    row(0), column(0), multiple_time(0)
  {}

  Matrix(int r, int c, int m):
    row(r), column(c), multiple_time(m)
  {}
};

Matrix multiple(Matrix mat1, Matrix mat2)
{
  return Matrix(mat1.row,
                mat2.column,
                mat1.multiple_time + mat2.multiple_time + mat1.row * mat1.column * mat2.column);
}

Matrix matrices[100];
Matrix multiplication[100][100];

Matrix minimum_multiple_time(int i, int j)
{
  if (i == j)
    return matrices[i];

  Matrix min = multiple(multiplication[i][i], multiplication[i + 1][j]);

  for (int k = 1; k < j - i; ++k)
  {
    Matrix cur_matrix = multiple(multiplication[i][i + k], multiplication[i + k + 1][j]);
    if (min.multiple_time > cur_matrix.multiple_time)
      min = cur_matrix;
  }

  return min;
}

int main()
{
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; ++i)
    scanf("%d%d", &matrices[i].row, &matrices[i].column);

  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; i + j < n; ++j)
    {
      multiplication[j][i + j] = minimum_multiple_time(j, i + j);
    }
  }

  printf("%d\n", multiplication[0][n - 1].multiple_time);

  return 0;
}

C++: #include<cstdio>
#include <cstring>
using namespace std;

int r[105];
int c[105];
int cache[105][105];

int f(int a, int b) {
    if (a == b) return 0;
    if (cache[a][b] == -1) {
        cache[a][b] = 2000000000;
        for (int i = a; i < b; i++) {
            int res = f(a, i) + f(i + 1, b) + r[a] * c[i] * c[b];
            if (res < cache[a][b]) cache[a][b] = res;
        }
    }
    return cache[a][b];
}

int main(void) {
    int n;
    scanf("%d",&n);
    for (int i = 0; i < n; i++) scanf("%d %d",&r[i], &c[i]);
    memset(cache, -1, sizeof(cache));
    printf("%d\n",f(0,n-1));
}

C++: #include<iostream>
using namespace std;
int dp[101][101];
class point {
public: int x, y;
};
point p[101];
int n;
int solve(int left, int right) {
	if (left == right) return dp[left][right] = 0;
	if (dp[left][right]) return dp[left][right];
	else
	{
		int min = 1<<29;
		for (int i = left; i < right; i++) {
			int k = dp[left][i] + dp[i + 1][right] + p[left].x * p[i + 1].x * p[right].y;
			if (k < min) min = k;
		}
		 dp[left][right] = min;
		 return min;
	}
}
int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i].x>>p[i].y;
	}
	for(int l=1;l<n; l++)
	for (int i = 0; i < n; i++) {
		if (i + l < n)
		{
			solve(i, i + l);
		}
	}
	cout << dp[0][n - 1]<<endl;
}

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

#define int long long
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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 (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)



void solve(){
    int N;
    cin >> N;
    vector<int> p(N+1,0);
    for(int i=0; i<N; i++)
        cin >> p[i] >> p[i+1];
    
    vector<vector<int>> dp(N+1, vector<int>(N+1,0));
    
    for(int w=2; w<=N; w++){
        for(int i=1; i<=N-w+1; i++){
            int j=i+w-1;
            dp[i][j] = INF;
            for(int 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]);
            }
        }
    }
    cout << dp[1][N] << endl;
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}

C++: #include <cstdio>
#include <cstdlib>
#include <cassert>
#include <memory.h>
#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <cassert>
typedef unsigned long long ull;
typedef unsigned long ul;
#define rep(i,n) for(unsigned long long i = 0;i<n;i++)
#define clear(c) memset(c,0,sizeof(c))
#define clearm(c) memset(c,-1,sizeof(c))
using namespace std;

int main(){
	int n;

	cin >> n;
	ull dp[10+1][10+1];
	clearm(dp);
	ull r[n],c[n];
	rep(i,n){
		int rr,cc;
		cin >> rr >> cc;
		r[i] = rr;
		c[i] = cc;
	}
	rep(i,n-1){
		dp[i][i+1] = r[i] * c[i+1] * r[i+1];
	}
	rep(i,n){
		dp[i][i] = 0;
	}
	for(int dif = 2;dif<n;dif++){
		for(int i = 0;i + dif<n;i++){
			for(int j = i + 1;j <= i +dif - 1;j++){
				dp[i][i+dif] = min(dp[i][i+dif],dp[i][j] + dp[j+1][i+dif] + r[i] * c[j] * c[i+dif]);
			}
		}
	}
	cout << dp[0][n-1] << endl;
	return 0;
}

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

#define N 100

int M[101][101], p[101], n;

int solve()
{
	int l, i, j, k;
	for (l = 2; l <= n; l++) {
		for (i = 1; i <= n - l + 1; i++) {
			j = i + l - 1;
			M[i][j] = 1 << 30;
			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]);
		}
	}
	return M[1][n];
}

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

	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;

	cout << solve() << endl;
	return 0;
}