Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for k := i; k <= j-1; k++ {
				dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

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