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 <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++: #include<bits/stdc++.h>
using namespace std;

const int N=505;
int mat[N][2];
int mem[N][N];

int mcm(int l, int r){
  if(l==r)  return mem[l][r]=0;
  if(mem[l][r]!=-1) return mem[l][r];
  int ret = INT_MAX;
  for (int i = l; i < r; ++i){
    int now = mcm(l, i);
    now += mcm(i+1, r);
    now += mat[l][0]*mat[i][1]*mat[r][1];
    ret = min(ret, now);
  }
  return mem[l][r]=ret;
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  int n;  cin >> n;
  for (int i = 0; i < n; ++i){
    cin >> mat[i][0] >> mat[i][1];
  }
  memset(mem, -1, sizeof(mem));
  cout << mcm(0, n-1) << "\n";
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i< (n);i++)
using namespace std;
typedef long long ll;
const int INF = (1e+9)+7;

int main(){
    int n;cin>>n;
    vector<vector<int>> C(n+1,vector<int>(n+1,0));
    //↑pの為に一つ多く作った。index番号が行列の番号と一致。
    vector<int> p(n+1);
    rep(i,n){
        int a,b;cin>>a>>b;
        if(i == 0){
            p[0] = a;
            p[1] = b;
        }else{
            p[i+1] = b;
        }
    }
    for(int l = 2;l<=n;l++){
        //lは行列の個数.
        for(int i = 1; i+l-1 <= n; i++){
            int j = i+l-1;//左端のindex
            int mn = INF;
            for(int k = i;k<j;k++){
                mn = min(mn,C[i][k]+C[k+1][j]+p[i-1]*p[k]*p[j]);
            }
            C[i][j] = mn;
        }
    }
    cout<<C[1][n]<<endl;
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>



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

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

int main(){
  int n, p[101], m[101][101], i, j, k, l;
  cin >> n;
  for(i = 1;i <=n;i++){
    cin >> p[i-1] >> p[i];
  }

  for(i = 1;i <= n;i++) m[i][i] = 0;
  for(l = 1;l <= n;l++){
    for(i = 1;i <= n - l + 1;i++){
      j = i + l - 1;
      m[i][j] = (1 << 21);
      for(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 <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;
// const double PI = M_PI;

int N;
vector<int> R, C;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  R.resize(N);
  C.resize(N);
  rep(i, N) { cin >> R[i] >> C[i]; }

  int dp[N][N + 1];
  rep(i, N) { fill(dp[i], dp[i] + N + 1, 0); }

  for (int i = 2; i <= N; i++) {
    for (int l = 0; l < N; l++) {
      int r = l + i;
      if (r > N) {
        continue;
      }
      dp[l][r] = INF;
      for (int k = l + 1; k < r; k++) {
        dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r] + R[l] * R[k] * C[r - 1]);
      }
    }
  }
  cout << dp[0][N] << endl;
  return 0;
}

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

const int N=100;

int main(){
	int n;
	long m[N+1][N+1], p[N+1];
	
	scanf(" %d", &n);
	for(int i=1; i<=n; ++i)
		scanf(" %ld %ld", &p[i-1], &p[i]);
		
	//for(int i=0; i<=n; ++i) printf("p[%d]=%ld\n", i, p[i]);
		
	for(int i=1; i<=n; ++i) m[i][i]=0;
	
	for(int s=2; s<=n; ++s){ //s??????????????????
		for(int i=1; i+s-1<=n; ++i){ //?§????i
			int j=i+s-1; //??????j
			m[i][j]=100000000; //????????§???????????§?????????
			for(int k=i; k<=j-1; ++k){ //?????????k
				m[i][j]=min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
				//printf("go %d %d %d\n",i, j, k);
			}
		}
	}
	
	printf("%ld\n", m[1][n]);
}

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