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<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 100
#define ELE_NUM 2
// 無効な値の定義
const int INV = -1;

const int colNo = 0;
const int rowNo = 1;
const int IntMAX = 	2147483647;

int ChainedMatrixtMultiplication(int n, int m, int matrixData[][ELE_NUM]);

int main(void)
{

    int n, count;
    int matrix_data[MAX_N + 1][ELE_NUM];

    cin >> n;

    for(int i = 1; i <= n; i++)
    {
        // 行
        cin >> matrix_data[i][colNo];
        // 列
        cin >> matrix_data[i][rowNo];
    }

    count = ChainedMatrixtMultiplication(n, ELE_NUM, matrix_data);
    printf("%d\n", count);

    return 0;
}

// 連鎖行列積の最小の乗算回数を演算する関数
// n : 積を求める行列の数
// m : 行列の情報 : 0 - 行の情報, 1 - 列の情報
// matrixData[][] : 各行列の行、列情報を保持する配列
int ChainedMatrixtMultiplication(int n, int m, int matrixData[][ELE_NUM])
{

    // 第1要素 : 演算開始のNo., 第2要素 : 演算終了のNo.
    int dp[MAX_N + 1][MAX_N + 1];
    int calcResult = 0;

    // 配列の初期化
    for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j <= n; j++)
        {
            dp[i][j] = INV;

            if( i == j )
            {
                // 同じ要素同士の積は演算することが不可能
                dp[i][j] = 0;
            }
        }
    }

    // 行列の演算回数の計算
    // i : 行列の演算をする先頭の要素No.
    // j : 行列の演算をする最後の要素No.
    // k : i 〜 jまでの範囲を移動する変数
    for(int l = 2; l <= n; l++)
    {
        for(int i = 1; i <= n - l + 1; i++)
        {
            int j = i + l - 1;

            dp[i][j] = IntMAX;

            for(int k = i; k <= j - 1; k++)
            {
                calcResult = dp[i][k] + dp[k + 1][j]
                            + ( matrixData[i][colNo] * matrixData[k][rowNo] * matrixData[j][rowNo]);

                dp[i][j] = min( dp[i][j], calcResult );
            }
        }
    }

    return dp[1][n];
}

C++: #include <iostream>
#include <algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1e9;
int n;
int r[102],c[102];
int p[102];

int dp[102][102];
// [i,j)
int dfs(int i,int j) {
    //cout<<i<<", "<<j<<endl;
    if(dp[i][j]!=-1) return dp[i][j];
    if(j-i==1) return r[i]*c[i]*c[j-1];
    if(i==j) return 0;
    int ret=INF;
    for(int k=i+1;k<j;k++) {
        //ret=min(ret,dfs(i,k)+dfs(k,j)+r[i]*c[k]*c[j-1]);
        ret=min(ret,dfs(i,k)+dfs(k,j)+p[i]*p[k]*p[j]);
    }

    return dp[i][j]=ret;
}

int main() {
    memset(dp,-1,sizeof(dp));
    cin>>n;
    //rep(i,n) cin>>r[i]>>c[i];
    rep(i,n+1) if(i) cin>>p[i-1]>>p[i];
    cout<<dfs(0,n)<<endl;
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

using Lint=long long;
const int INF=1e9;

int main()
{
   int N; cin>>N;
   vector<int> row(N),col(N);
   for(int i=0;i<N;i++) cin>>row[i]>>col[i];

   vector<vector<int>> dp(N+1,vector<int>(N+1,INF));
   for(int i=0;i<N;i++) dp[i][i+1]=0;
   for(int len=2;len<=N;len++){
      for(int l=0;l+len<=N;l++){
         int r=l+len;
         for(int m=l+1;m<r;m++) dp[l][r]=min(dp[l][r],dp[l][m]+dp[m][r]+row[l]*row[m]*col[r-1]);
      }
   }
   cout<<dp[0][N]<<endl;
   return 0;
}

C++: #include <stdio.h>

#define MAX 101
#define INF 10000000;


void MatrixChainOrder();
int min(int,int);

int m[MAX][MAX];
int p[MAX];

int n;

int main(){

  int i,j,r,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    p[i]=r;
    p[i+1]=c;
  }

  MatrixChainOrder();

  printf("%d",m[1][n]);

  return 0;
}


void MatrixChainOrder(){

  int i,j,k,l,q;

  for(i=1;i<=n;i++) m[i][i]=0;

  for(l=2;l<=n;l++){

    for(i=1;n-l+1;i++){
      j=i+l-1;
      m[i][j]=INF;

      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j]=min(m[i][j],q);
}
}
}

}

int min(int x,int y){

  if(x<=y) return x;
  else return y;

}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxx=2000000000;

int n;
int p[110],dp[110][110];

int main (){
	cin>>n;
	for(int i=1;i<=n;i++){
		dp[i][i]=0;
		cin>>p[i-1]>>p[i];
	}
	for(int len=2;len<=n;len++){
		for(int i=1;i<=n-len+1;i++){
			int j=i+len-1;
			dp[i][j]=maxx;
			for(int k=i;k<j;k++) 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]<<endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INFTY 200000000000
long long dp[110][110];
int seen[110][110];
vector<int>ro(110),co(110);
long long ch(int l,int r){
    long long mn = dp[l][r];
    if(r==l) return dp[l][r] = 0;
    if(dp[l][r]!=INFTY) return dp[l][r];
    for (int k = l; k < r; k++)
    {
        long long sum = ch(l,k)+ch(k+1,r)+ro[l]*co[r]*ro[k+1];
        mn = min(mn,sum);
    }  
    return dp[l][r] = mn;
}
int main(){
    int n;cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> ro[i]>>co[i];
    }
    
    for (int i = 0; i < n;i++)
    {
        for(int j=0;j<n;j++){
            dp[i][j] = INFTY;
        }
        }
    long long ans = ch(0,n-1);
    cout << ans << endl;

    return 0;
}