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 INFTY 1 << 21
using namespace std;

static const int N = 100;

int main(){
    int n;
    cin >> n;
    int p[N+1], m[N+1][N+1];
    for(int i = 1; i <= n; i++){
        scanf("%d %d", &p[i-1], &p[i]);
    }
    int i, j, l;
    for(i = 1; i <= n; i++){
        m[i][i] = 0;
    }   // 初期化
    for(l = 2; l <= n; l++){
        for(i = 1; i <= n - l + 1; i++){
            j = i + l - 1;
            m[i][j] = INFTY;
            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 <cstdio>
#include <algorithm>
using namespace std;

const int INF = 1000000000;

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

  int m[n + 1][n + 1], p[n + 1];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      m[i][j] = INF;

  for (int i = 0; i <= n; i++)
    m[i][i] = 0;

  scanf("%d%d", &v1, &v2);
  p[0] = v1;
  p[1] = v2;
  for (int i = 1; i < n; i++)
  {
    scanf("%d%d", &v1, &v2);
    p[i + 1] = v2;
  }

  for (int l = 2; l <= n; l++)
    for (int i = 1; i <= n - l + 1; i++)
    {
      int j = i + l - 1;
      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]);
    }

  printf("%d\n", m[1][n]);
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF 1e15

#define MAX_N 1000

int n;
ll p[111],m[111][111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	repl(i,1,n+1){
		cin>>p[i-1]>>p[i];
	}
	repl(l,2,n+1)repl(i,1,n-l+2){
		int j=i+l-1;
		m[i][j]=INF;
		repl(k,i,j)minch(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 <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e7;
const ll MOD = 1e9 + 7;
const int MAX = 101;

int n; // 行列の数
int m[MAX][MAX]; // m[i][j] := 行列iと行列jの最小の演算数
int p[MAX]; // p[i] := 行列iの行数(縦の長さ)

int main()
{
    ios_base::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;
    }
    for (int l = 2; l <= n; ++l) { // 行列のlengthは2~n
        for (int i = 1; i <= n-l+1; ++i) { // iからn-l+1まで
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k < j; ++k) { // m[i][j]を求める
                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++: //============================================================================
// Name        : MatrixChainMultiplication.cpp
// Author      : Ken
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <map>
using namespace std;

struct Matrix{
	int row;
	int col;
};

class MatrixList{
public:
	vector<Matrix> matrices;
	map<string, int> minProcess;
	map<string, int>::iterator p;
	MatrixList():matrices(), minProcess(){}

	void insert(const Matrix& mat){
		matrices.push_back(mat);
	}

	int calcMinProcess(int i, int j){
		if(not(i>=0 and i<j and j<=matrices.size())){
			cout << "calcMinProcess: i and j are invalid\n";
			return -1;
		}

		string key = to_string(i) + ":" + to_string(j);

		p = minProcess.find(key);
		if(p != minProcess.end()){
			return minProcess[key];
		}

		if(j == i+1){
			return 0;
		}

		int min = 100000000;

		for(int k=i+1; k<j; k++){
			int tmp = calcMinProcess(i, k) + calcMinProcess(k, j) + matrices.at(i).row * matrices.at(k-1).col * matrices.at(j-1).col;
			if(tmp < min){
				min = tmp;
			}
		}

		minProcess[key] = min;
		return min;
	}

	void writeMatList(){
		for(int i=0; i<matrices.size(); i++){
			cout << matrices.at(i).row << " " << matrices.at(i).col << "\n";
		}
	}
};

int main() {
	int n, row, col;
	cin >> n;
	MatrixList matList;

	for(int i=0; i<n; i++){
		cin >> row >> col;
		Matrix mat = {row, col};
		matList.insert(mat);
	}

	//matList.writeMatList();
	cout << matList.calcMinProcess(0, matList.matrices.size()) << "\n";

	return 0;
}