Go: package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	P := make([]int, n+1)
	for i := 1; i <= n; i++ {
		l := nextInt(sc)
		P[i-1] = l
		m := nextInt(sc)
		P[i] = m
	}

	matrix := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		matrix[i] = make([]int, n+1)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n - l + 1; i++ {
			j := i + l - 1
			matrix[i][j] = (1 << 21)
			for k := i; k <= j-1; k++ {
				matrix[i][j] = min(matrix[i][j], matrix[i][k] + matrix[k+1][j] + P[i-1] * P[k] * P[j])
			}
		}
	}
	fmt.Println(matrix[1][n])
}

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

int n;

int m[101][101];

int p[101];


void matrix(){
  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] = 1000000;
      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]);
      }
    }
  }
}

int main(){

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

  matrix();

  cout << m[1][n] << endl;



  return 0;
}

C++: #include <iostream>
#include <string>
#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 <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

const int INF = 1e8;

int main() {
	int n;
	cin >> n;
	vector<int> r(n), c(n);
	rep(i, n) cin >> r[i] >> c[i];
	vector<vector<int>> dp(n + 1, vector<int>(n + 1, INF));
	rep(i, n + 1) dp[i][i] = 0;
	rep(i, n) dp[i][i + 1] = 0;
	for (int w = 2; w <= n; w++) {
		for (int i = 0; i <= n - w; i++) {
			int j = i + w;
			for (int m = i + 1; m < j; m++) {
				int t = r[i] * r[m] * c[j - 1];
				dp[i][j] = min(dp[i][j], dp[i][m] + dp[m][j] + t);
			}
		}
	}
	cout << dp[0][n] << endl;
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    //cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);N;
    int N; cin >> N;
    int r[N], c[N];
    REP(i,N){
        cin >> r[i] >> c[i];
    }

    /*if(N == 2){
        cout << r[0] * c[0] * c[1] << endl;
        return 0;
    }*/

    int dp[N][N];
    REP(i,N){
        REP(j,N){
            //dp[i][j] = INF;
            if(i == j) {dp[i][j] = 0;}
            else dp[i][j] = INF;
        }
    }
    //cout << dp[3][4] << endl;

    for(int w = 1; w < N; w++){
        for(int left = 0; left + w < N; left++){
            int right = left + w;
            //int mini = INF;
            for (int k = left;k < right; k++){
                int num = r[left] * r[k+1] * c[right];
                /*if(left == 3 && right == 4) {
                    cout << num << endl;
                    //cout << r[left] << " " << r[k+1] << " " << c[right] << endl;
                } */
                dp[left][left+w] = min(dp[left][left+w], dp[left][k] + dp[k+1][right] + num);
            }
        }   
    }

    cout << dp[0][N-1] << endl;
    
}

C++: #define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable: 4244) // 最悪をします
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <sstream>
#define BIT(nr) (1UL << (nr))
#define int long long
//#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }


using namespace std;

//デバッグ用カッコの有無
#ifdef DEBUG
template <class T>ostream &operator<<(ostream &o, const vector<T>&v)
{
	o << "{"; for (int i = 0; i<(int)v.size(); i++)o << (i>0 ? ", " : "") << v[i]; o << "}"; return o;
}
#endif // DEBUG

template <class T>ostream &operator<<(ostream &o, const vector<T>&v)
{
	for (int i = 0; i<(int)v.size(); i++)o << (i>0 ? " " : "") << v[i]; return o;
}

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int dxp[4] = { 0, 1 }; // x軸方向への変位(正のみ)
int dyp[4] = { 1, 0 }; // y軸方向への変位(負のみ)

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;

	// libalgo のものに追加、メンバを追加するだけなので互換性は崩さないはず、逆辺のG[e.dstの]インデックスを保持
	int rev;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph& g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph& g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

int dp[110][110];
signed main() {
	int n;
	cin >> n;

	vector<int> ro(n), co(n);
	rep(i, n) {
		cin >> ro[i] >> co[i];
	}

	rep(i, 100) rep(j, 100) dp[i][j] = LL_HALFMAX;

	// [l, r) における最適解
	function<int(int, int)> rec = [&](int l, int r) -> int {
		if (dp[l][r] != LL_HALFMAX) {
			return dp[l][r];
		}
		
		if (r - l == 1) {
			return dp[l][r] = 0;
		}

		int ret = LL_HALFMAX;

		REP(m, l + 1, r) {
			int cand = ro[l] * ro[m] * co[r - 1] + rec(l, m) + rec(m, r);
			chmin(ret, cand);
		}

		return dp[l][r] = ret;
	};

	cout << rec(0, n) << "\n";
}

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

int n;
int m[200][200];
int p[200];

int matrixChainMultiplication(){
    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] = 1001001001;
            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() {
    cin >> n;
    rep(i, n){
        int a, b; cin >> a >> b;
        p[i] = a;
        p[i+1] = b;
    }
    int ans = matrixChainMultiplication();

    cout << ans << endl;

    return 0;
}