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 <stdio.h>
#include <algorithm>

const int N = 100;
int n, p[N + 1], dp[N + 1][N + 1];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &p[i - 1], &p[i]);

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

	for (int k = 2; k <= n; k++)
	{
		for (int i = 1; i <= n - k + 1; i++)
		{
			int j = i + k - 1;
			dp[i][j] = 1 << 20;
			for (int s = i; s <= j - 1; s++)
				dp[i][j] = std::min(dp[i][j], dp[i][s] + dp[s + 1][j] + p[i - 1] * p[s] * p[j]);
		}
	}
	printf("%d\n", dp[1][n]);

	return 0;
}

C++: #include <iostream>
using namespace std;
#define INF 10000000

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

int main() {
  int n; 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] = INF;
      for ( int k = i; k <= j-1; k++ ) {
	int q = M[i][k] + M[k+1][j] + p[i-1]*p[k]*p[j];
	M[i][j] = min(M[i][j],q);
      }
    }
  }
  cout << M[1][n] << endl;
  return 0;
}

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

#define INF (100 * 100 * 100 * 100)

int n, m[110][110];

void matrixChainOrder(int *p){
  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] = INF;
      for(int k = i;k <= j - 1;k++){
        int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
        m[i][j] = min(m[i][j], q);
      }
    }
  }
}

int main(){
  
  int p[110];
  
  cin >> n;
  
  for(int i = 0;i < n;i++){
    int r, c;
    
    cin >> r >> c;
    if(i) p[i + 1] = c;
    else{
      p[0] = r;
      p[1] = c;
    }
  }
  
  matrixChainOrder(p);
  
  cout << m[1][n] << endl;
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <climits>

using namespace std;

static const int N = 100;
static int m[N + 1][N + 1] = {}, p[N + 1] = {};

static inline void matrixChainMultiplication(int n) {
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n - l + 1; i++) {
      int j = i + l - 1;
      m[i][j] = INT_MAX;
      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]); 
      }
    }
  }
}

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

  matrixChainMultiplication(n);
  
  cout << m[1][n] << endl;

  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ll long long
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-l+1;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;
}

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 - l + 1; 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;
}

C++: // ALDS1_10_B Matrix Chain Multiplication
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define INF 900000000
bool debug = false;
std::vector<std::vector<int>> dp;

void MatrixChainMultiplication(std::vector<std::pair<int,int>> sequence) {
    dp.resize(sequence.size());
    for (int i=0; i<dp.size(); i++) dp.at(i).resize(sequence.size());

    /*
    example:
        aN is a matrix. 
        ... a3 (a4 a5 a6)*(a7 a8) a9 ...
        i = 5, j = 4, k = 3
    */

    /* i = length of set */
    for (int i=2; i<dp.size(); i++) {
        /* j = front point */
        for (int j=1; j<=dp.at(i).size()-i; j++) {
            /* initialization of dp.at(i).at(j) */
            dp.at(i).at(j) = INF;
            /* k = dividing point */
            for (int k=1; k<i; k++) {
                if (i == 2) {
                    dp.at(i).at(j) = sequence.at(j).first*sequence.at(j).second*sequence.at(j+1).second;
                } else {
                    dp.at(i).at(j) = std::min(dp.at(i).at(j),
                                              dp.at(k).at(j)+dp.at(i-k).at(j+k)+sequence.at(j).first*sequence.at(j+k-1).second*sequence.at(i+j-1).second);
                    
                }
            }
            if (debug) {
                std::cout << "dp.at(" << i << ").at(" << j << ") = " << dp.at(i).at(j) << ":";
                for (int n=j; n<i+j; n++) std::cout << " " << n;
                std::cout << "\n";
            }
        }
    }
    std::cout << dp.back().at(1) << "\n";
}

int main() {
    int total; std::cin >> total;
    std::vector<std::pair<int,int>> sequence;
    sequence.resize(total+1);
    for (int i=1; i<sequence.size(); i++) {
        std::cin >> sequence.at(i).first >> sequence.at(i).second;
    }
    MatrixChainMultiplication(sequence);
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef float fl;
typedef long long ll;

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 - l + 1; 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;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

int main(){
	int n;
	cin >> n;
	int i, t, A[n+1];
	cin >> A[0] >> A[1];
	for(i = 2; i <= n; i++){
		cin >> t >> A[i];
	}

	//dp[l][r] -> min(A[l]*...*A[r])
	int dp[n][n+1]{}, dplr, l, r;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < n-i; j++){
			l = j;
			r = j+i;
			dplr = INT_MAX;
			for(int k = l; k < r; k++){
				dplr = min(dplr, dp[l][k] + dp[k+1][r] + A[l]*A[k+1]*A[r+1]);
			}
			dp[l][r] = dplr;
			//printf("[%d, %d]=%d ", l, r, dplr);
		}
		//printf("\n");
	}

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