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>
#include <cstring>
#include <vector>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define NIL -1
#define MAX 1000

static const int N = 1000;

int main()
{
    int n, m[N+1][N+1], p[N+1];

    cin >> n;
    rep(i, n){
        cin >> p[i] >> p[i+1];
    }

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

void DP(int i, int j, long long dp[101][101], int r[], int c[]){
    if(i == j) dp[i][j] = 0;
    else if (j - i == 1){
        dp[i][j] = r[i] * c[i] * c[j];
    } else {
        int tmp = i;
        dp[i][j] = dp[i][tmp] + dp[tmp+1][j] + r[i] * r[tmp+1] * c[j];
        // cout <<  "i: "<< i <<" tmp: " << tmp <<" " << r[i] * r[tmp+1] * c[j] <<endl;
        tmp++;
        while(tmp != j){
            dp[i][j] = min(dp[i][j], dp[i][tmp] + dp[tmp + 1][j] + r[i] * r[tmp+1] * c[j]);
            // cout <<  "i: "<<i<<" tmp: " << tmp <<" " << r[i] * r[tmp+1] * c[j] <<endl;
            tmp++;
        }
    }
    
    // cout << "i, j: " << i << ", " << j << " " <<  dp[i][j] << endl;
}

void solve(){
    int n; cin >> n;
    int r[n+1], c[n+1];
    r[0] = 0; c[0] = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> r[i] >> c[i];
    }
    long long dp[101][101] = {};
 
    for(int i = 1; i < n; i ++){
        int tmp = 1;
        for(int j = i + tmp; j <= n; j++, tmp++){
            DP(tmp, j, dp, r, c);
        }
    }
    cout << dp[1][n] << endl;
}

int main (){
    solve();
    return 0;
}

C++: def edit_distance(d)
 n =len(d)
 A=[[0 for i inrange(n)] for j in range(n)]
 for long in range(0,n+1-long):
  k=i-1+long
  def f(i,j,k):
   return A[i][j-1]+A[j][k]+]+M[i][0]*M[j-1][1]*M[k][1]
   A[i][k] = min([f(i,j,k) for j in range(i+1,k+1)])
 return A[0][n-1]
n = input()
M = []
for i in range(n):
 M.append(map(int, raw_input().split()))
print edit_distance (M)

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

const int INF = INT_MAX/3;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
    int n;cin>>n;
    vector<pii> p(n+1);
    for(int i=0;i<n;i++) cin>>p[i].first>>p[i].second;

    vector<vi> mat(n+1,vi(n+1,INF));    //mat[i][j] : Mi*...*Mj???????°??????°
    for(int i=0;i<n;i++) mat[i][i] = 0;

    for(int sz=2;sz<=n;sz++){
        /*
         * mat[i][j] = min( mat[i][k]+mat[k+1][j]+Mi.first*Mk+1.first*Mk+1.second )
         */
        for(int i=0;i<=n-sz;i++){
            int j = i + sz - 1;

            for(int k=i;k<=j-1;k++){
                mat[i][j] = min(mat[i][j] , mat[i][k] + mat[k+1][j] + p[i].first * p[k+1].first * p[j].second);
            }
        }
    }
    cout << mat[0][n-1] << endl;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
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 -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>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

// O(n^3)
// dp[i][j] := [i,j]????????????????????????????°?????????????????????°
// i??????????????????(?????°????????°)??????(p[i - 1], p[i])
int matrixChainMultiplication(int n, int p[105]){
    int dp[105][105] = {{0}};
    range(seg, 2, n + 1){ //?¨????????????????????????°
        range(i, 1, n - seg + 2){
            int j = i + seg - 1;
            dp[i][j] = INT_MAX;
            range(k,i,j){
                int cost = dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j];
                dp[i][j] = min(dp[i][j], cost);
            }
        }
    }
    return dp[1][n];
}

int main(){
    int n;
    cin >> n;

    int p[105];
    rep(i,n){
        cin >> p[i] >> p[i + 1];
    }
    cout << matrixChainMultiplication(n, p) << endl;
}

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<iostream>
#include<algorithm>
using namespace std;

int nlist[110];
int dp[110][110];

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>nlist[i]>>nlist[i+1];
  }
  for(int i=1;i<n;i++){
    for(int j=0;j<n-i;j++){
      dp[j][j+i]=1<<30;
      for(int k=0;k<i;k++){
	dp[j][j+i]=min(dp[j][j+i],dp[j][j+k]+dp[j+k+1][j+i]+nlist[j]*nlist[j+k+1]*nlist[j+i+1]);
      }
    }
  }
  cout<<dp[0][n-1]<<endl;
  return 0;
}

C++: #include <iostream>

using namespace std;

int m[124][124] = {{}};
int p[124] = {};
int n;

void chain(){
  for(int i = 0 ;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;

}


int main(){

  cin >> n;

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

  chain();

}

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

static const int N=100;

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