Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	mm := make([]int, n+1)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, n+1)
	}
	for i := 0; i < n; i++ {
		mm[i] = getNextInt(scanner)
		mm[i+1] = getNextInt(scanner)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			for k := i; k <= j-1; k++ {
				d := dp[i][k] + dp[k+1][j] + mm[i-1]*mm[k]*mm[j]
				if dp[i][j] == 0 || dp[i][j] > d {
					dp[i][j] = d
				}
			}
		}
	}

	fmt.Fprintln(writer, dp[1][n])

	writer.Flush()
}

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

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

int n;
int r[100], c[100];
int dp[100][100];
const int INF = 1000000000;

int main() {
  cin >> n;
  rep(i, n) {
    cin >> r[i] >> c[i]; 
  }
  rep(i, 100) {
    rep(j, 100) {
      if(i == j) dp[i][j] = 0;
      else dp[i][j] = INF;
    }
  }

  for(int w = 1; w < n; w++) {
    for(int i = 0; i + w < n; i++) {
      int j = i + w;
      for(int k = 0; k < j; k++) {
        int num_prod = r[i] * c[k] * c[j];
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + num_prod);
      }
    }
  }

  cout << dp[0][n-1] << endl;
  return 0;
}

C++: #include <iostream>
#include <algorithm>
const int MAX_N = 100;
const int INF = 999999999;
using namespace std;

int dp[MAX_N+1][MAX_N+1];
int p[MAX_N+1];

int main(void) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        dp[i][i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        cin >> p[i-1] >> p[i];
    }

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

    return 0;
}

C++: #include <iostream>
using namespace std;
int n,a[100],b[100],dp[100][100];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            if(i!=j)dp[i][j]=1e9;
        }
    }
    for(int j=1;j<n;j++){
        for(int i=0;i+j<n;i++){
            for(int k=i;k<i+j;k++){
                dp[i][i+j]=min(dp[i][i+j],dp[i][k]+dp[k+1][i+j]+a[i]*b[i+j]*b[k]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
}