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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1001001001001001;

int n;
ll r[111], c[111];
ll dp[111][111]; // dp[le][ri] = [le, ri) の最小回数

ll rec(int le, int ri) {
    if (dp[le][ri] != INF) return dp[le][ri];
    if (ri - le - 2 == 0) {
        return dp[le][ri] = min(dp[le][ri], r[le] * c[le] * c[ri - 1]);
    }
    if (le + 1 < ri - 1) dp[le][ri] = min(dp[le][ri], rec(le + 1, ri) + r[le] * c[le] * c[ri - 1]);
    if (le < ri - 2) dp[le][ri] = min(dp[le][ri], rec(le, ri - 1) + r[le] * c[ri - 2] * c[ri - 1]);
    for (int md = le + 1; md < ri - 1; md++) {
        dp[le][ri] = min(dp[le][ri], rec(le, md) + rec(md, ri) + r[le] * c[md - 1] * c[ri - 1]);
    }
    return dp[le][ri];
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> r[i] >> c[i];
    for (int i = 0; i < 111; i++) {
        for (int j = 0; j < 111; j++) {
            dp[i][j] = INF;
        }
    }
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    rec(0, n);
    cout << dp[0][n] << endl;
}

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

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;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 long N = 100;

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

	for (long i = 1; i <= n; i++) m[i][i] = 0;
	for (long l = 2; l <= n; l++){
		for (long i = 1; i <= n - l + 1; i++){
			long j = i + l - 1;
			m[i][j] = (1 << 21);
			for (long k = 0; k <= j - 1; k++){
				m[i][j] = min(m[i][j], m[i][k] + 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 <climits>

typedef struct{
    int r;
    int c;
}matrix;

int table[100][100];

int calc(matrix* m, int l, int r){
    if(r<=l+1)return 0;
    if(table[l][r]>0)return table[l][r];
    int i, tmp;
    int ans = INT_MAX;
    for(i=l+1;i<r;i++){
        tmp = m[l].r*m[i].r*m[r-1].c + calc(m,l,i) + calc(m,i,r);
        if(tmp<ans)ans = tmp;
    }
    table[l][r] = ans;
    return ans;
}

int main(){
    int i, j, n;
    matrix m[100];
    scanf("%d",&n);
    for(i=0;i<100;i++){
        for(j=0;j<100;j++){
            table[i][j] = 0;
        }
    }
    for(i=0;i<n;i++){
        scanf("%d %d",&(m[i].r),&(m[i].c));
    }
    printf("%d\n",calc(m,0,n));
    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[i][n] << endl;
	
	return 0;
}

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

struct mat{
  int row, col;
};

int m[101][101];
mat p[101];

int main(){
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> p[i].row >> p[i].col;
  for(int l = 2; l <= n; l++){
    for(int i = 1; i <= n - l + 1; i++){
      int j = i + l - 1;
      if(i == j) m[i][j] = 0;
      else{
	int minc = 1e9;
	for(int k = i; k < j; k++){
	  int x = m[i][k] + m[k+1][j] + p[i].row * p[k].col * p[j].col;
	  minc = minc < x ? minc : x;
	}
	m[i][j] = minc;
      }
    }
  }
  cout << m[1][n] << endl;
  return 0;
}