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 <vector>

using namespace std;

struct matrix {
  int r;
  int c;
};

// 連鎖行列積問題
int main() {
  vector<matrix> mat;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp1,tmp2;
    cin >> tmp1 >> tmp2;
    matrix m = {tmp1, tmp2};
    mat.push_back(m);
  }
  
  int** memo = new int*[n];
  for (int s = 0; s < n; s++) {
    memo[s] = new int[n];
  }

  for (int l = 1; l < n; l++) {
    for (int s = 0; s < n; s++) {
      if (s + l >= n) {
        break;
      }
      
      int minval = (1 << 21);
      int sum = 0;
      for (int i = 0; i < l; i++) {
        sum = memo[s][s+i] + memo[s+i+1][s+l];
        matrix m1 = mat[s];
        matrix m2 = mat[s+i];
        matrix m3 = mat[s+l];

        sum += m1.r * m2.c * m3.c;

        minval = min(minval, sum);
      }
      memo[s][s+l] = minval;
    }
  }

  cout << memo[0][n-1] << endl;
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

vector<int> R;
vector<int> C;
vector<vector<int>> dp;

long long int rec(int l,int r){
  if(dp[l][r]!=-1) return dp[l][r];
  if(abs(r-l)<=1)return 0;
  long long int res=10000007;
  for(int mid=l+1;mid<r;mid++){
    res=min(res,rec(l,mid)+rec(mid,r)+R[l]*C[mid-1]*C[r-1]);
  }
  return dp[l][r]=res;
}

int main(){

  int n;
  cin >> n;

  dp.resize(n+1);
  for(int i=0;i<n+1;i++)dp[i].resize(n+1);

  for(int i=0;i<n+1;i++){
    for(int j=0;j<n+1;j++){
      dp[i][j]=-1;
    }
  }

  R.resize(n);
  C.resize(n);
  for(int i=0;i<n;i++)cin >> R[i] >> C[i];

  int c=rec(0,n);

  cout << c << endl;


}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int INF = 1001001001;
int main() {
    int n;
    int p[110];
    int dp[110][110];
    cin >> n;
    for(int i = 1;i<=n;i++) cin >> p[i-1] >> p[i];
    for(int i = 0;i<=n;i++) dp[i][i] = 0;
    for(int l = 2;l<=n;l++) {
        for(int i = 1;i <= n-l+1;i++) {
            int j = i+l-1;
            dp[i][j] = INF;
            for(int k = i;k<j;k++) {
                chmin(dp[i][j],dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }
    cout << dp[1][n] << endl;
}

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

static const long N = 100;

int main(){
	long n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for (long i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];
	for (long i = 1; i <= n; i++) m[i][i] = 0;
	for (long l = 2; l <= n; l++){
		for (long i = 1; i <= n - l + 1; i++){
			long j = i + l - 1;
			m[i][j] = (1 << 21);
			for (long 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;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define RFOR(i,e,s) for(int (i)=(e)-1;(i)>=(int)(s);(i)--)
#define RREP(i,e) RFOR(i,e,0)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;
typedef priority_queue<int> PQI;
typedef priority_queue<PII> PQII;

const double EPS = 1e-10;
const int INF = 1e9;
const int N = 100;
int n;
int r[N], c[N];
int dp[N+1][N];

int main() {
  scanf("%d ", &n);
  REP(i,n) scanf("%d%d ", r+i, c+i);

  REP(i,n+1) REP(j,n) dp[i][j] = INF;
  REP(j,n) dp[1][j] = 0;
  FOR(i,2,n+1) REP(j,n-i+1) FOR(k,1,i)
    dp[i][j] = min(dp[i][j], dp[k][j] + r[j]*c[j+k-1]*c[i+j-1] + dp[i-k][j+k]);

  printf("%d\n", dp[n][0]);

  return 0;
}

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];
    int i, l, j, k;

    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 = 2; 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 <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)

const int MAX_N = 100;
const int INF = 0x3f3f3f3f;

int main() {
  int n, p[MAX_N + 1], m[MAX_N + 1][MAX_N + 1] = {0}; 

  cin >> n;
  REP(i, n) cin >> p[i] >> p[i + 1];

  REP(i, n) REP(l, n - i) {
    if (i == 0) continue;
    int r = l + i;
    m[l][r] = INF;
    FOR(j, l, r) m[l][r] = min(m[l][r], m[l][j] + m[j + 1][r] + p[l] * p[j + 1] * p[r + 1]);
  }
  cout << m[0][n - 1] << endl;

  return 0;
}

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

int r[105];
int c[105];
int cache[105][105];

int f(int a, int b) {
    if (a == b) return 0;
    if (cache[a][b] == -1) {
        cache[a][b] = 2000000000;
        for (int i = a; i < b; i++) {
            int res = f(a, i) + f(i + 1, b) + r[a] * c[i] * c[b];
            if (res < cache[a][b]) cache[a][b] = res;
        }
    }
    return cache[a][b];
}

int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> r[i];
        cin >> c[i];
    }
    memset(cache, -1, sizeof(cache));
    cout << f(0, n-1) << endl;
}