Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	m := make([][]int, n)
	sizes := make([][]int, n)
	for i := 0; i < n; i++ {
		sizes[i] = []int{nextInt(), nextInt()}
		m[i] = make([]int, n)
	}
	// fmt.Println(sizes)

	for w := 1; w < n; w++ {
		for i := 0; i < n-w; i++ {
			j := i + w
			minBetweenIandJ := 10000000
			for k := i; k < j; k++ {
				// fmt.Println(i, j, k, m[i][k], m[k+1][j], sizes[i][0]*sizes[k][1]*sizes[j][1])
				minBetweenIandJ = min(minBetweenIandJ, m[i][k]+m[k+1][j]+sizes[i][0]*sizes[k][1]*sizes[j][1])
			}
			m[i][j] = minBetweenIandJ
		}
	}
	// for i := 0; i < len(m); i++ {
	// 	fmt.Println(stringifyArray(m[i]))
	// }
	fmt.Println(m[0][n-1])
}

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