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 <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 )
         */
      //  cout << "size = " << sz << endl;
        for(int i=0;i<=n-sz;i++){

            int j = i + sz - 1;

       //     cout << i << " : " << j << endl;

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

    /*
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout << mat[i][j] << "\t";
        }
        cout << endl;
    }
    */

    cout << mat[0][n-1] << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = (s); i < (n); i++)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  int n;
  cin >> n;
  int dp[n+1][n+1];
  rep(i, 1, n+1) dp[i][i] = 0;
  int p[n+1];
  rep(i, 0, n) cin >> p[i] >> p[i+1];
  
  rep(l, 2, n+1) {
    rep(i, 1, n-l+2) {
      int j = i+l-1;
      dp[i][j] = 1000000007;
      rep(k, i, j) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j]);
      }
    }
  }
  
  cout << dp[1][n] << "\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 (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 <vector>
#include <limits>

using namespace std;

// M1, M2, M3, ... , Mn-1, Mn
// M[i,j] = 0 if i = j
// M[i,j] = min { M[i,j] = M[i,k] + M[k+1,j] + p_{i-1} * p_k * p_j } where i <= k < j

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

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

    int M[n+1][n+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 - l + 1; ++i) {
            int j = i + l - 1;
            M[i][j] = std::numeric_limits<int>::max();
            for (int k = i; k <= j - 1; ++k) {
                int q = M[i][k] + M[k+1][j] + P[i-1] * P[k] * P[j];
                M[i][j] = min(M[i][j], q);
            }
        }
    }
    cout << M[1][n] << endl;

    return 0;
}

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

int MatrixChainMaltiplication(int *p, int n) {
    int m[n+1][n+1];
    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-1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
    return m[1][n];
}

int
main()
{
    int n;
    scanf("%d", &n);
    int p[n+1];
    for (int i=0; i<n; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        if (i == 0) p[i] = a;
        p[i+1] = b;
    }
    printf("%d\n", MatrixChainMaltiplication(p, n));
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long llong;
#define MAX 100
#define INFTY 9999999

// 行列群を保持しておく
vector<int> vecMtr(MAX);
vector<vector<int>> dp(MAX,vector<int>(MAX));

int
MultipleMatrixChain(int size)
{
  for (int i = 1; i < size; i++)
  {
    dp[i][i] = 0;
  }
  
  for (int l = 2; l <= size; l++)
  {
    for (int i = 1; i <= size-l+1; i++)
    {
      int j = i + l - 1;
      dp[i][j] = INFTY;
      for (int k = i; k <= j-1; k++)
      {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j]+ vecMtr[i-1]*vecMtr[k]*vecMtr[j]);
      }
    }
  }
  return dp[1][size];
}

int main() {
  int n;
  cin >> n;
  
  int r = 0;
  int c = 0;

  for (int i = 1; i <= n; i++)
  {
      cin >> r >> c;
      vecMtr[i-1] = r;
      vecMtr[i] = c;
  }
  
  cout << MultipleMatrixChain(n) << "\n";
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int n, r[100], c[100], dp[100][101];
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d%d", &r[i], &c[i]), dp[i][i] = 0;
	for(int i = 1; i < n; i++) {
		for(int j = 0; i + j <= n; j++) {
			dp[j][i + j] = min(dp[j][i + j - 1], dp[j + 1][i + j]) + r[j] * c[i + j - 1];
		}
	}
	printf("%d\n", dp[0][n]);
	return 0;
}