Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	mm := make([]int, n+1)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, n+1)
	}
	for i := 0; i < n; i++ {
		mm[i] = getNextInt(scanner)
		mm[i+1] = getNextInt(scanner)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			for k := i; k <= j-1; k++ {
				d := dp[i][k] + dp[k+1][j] + mm[i-1]*mm[k]*mm[j]
				if dp[i][j] == 0 || dp[i][j] > d {
					dp[i][j] = d
				}
			}
		}
	}

	fmt.Fprintln(writer, dp[1][n])

	writer.Flush()
}

C++: // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const ll INF = 1000000007;

vector< vector<ll> > M(110, vector<ll>(110, 0));
vector<ll> P(110);
int N;

ll multiplication(){
    for(int l = 2; l <= N; l++){
        for(int i = 1; i <= N - l + 1; i++){
            int j = i + l - 1;
            M[i][j] = INF * INF;
            for(int k = i; k < j; 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){
        cin >> P[i] >> P[i+1];
    }
    cout << multiplication() << endl;
}

C++: #include <iostream>

using namespace std;

int p[101], dp[101][101];

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

	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  vector<vi> dp(n + 1, vi(n, 0));
  vi p(n + 1);
  REP(i, n) cin >> p[i] >> p[i + 1];
  FOR(s, 2, n + 1) {     // 掛ける個数
    REP(l, n - s + 1) {  // 掛け始めるidx
      dp[s][l] = INF;
      FOR(ls, 1, s) {  // 分割
        auto r = l + ls;
        auto rs = s - ls;
        dp[s][l] =
            min(dp[s][l], dp[ls][l] + dp[rs][r] + p[l] * p[r] * p[l + s]);
      }
    }
  }
  cout << dp[n][0] << endl;
}

C++: #include <stdio.h>
#include <limits.h>
 
#define MAX 100
 
int A[MAX],B[MAX][MAX],n;
    
main(){
  int i,r,c;
 
  scanf("%d",&n);
 
  for(i=0; i<n; i++)
    {
      scanf("%d %d",&r,&c);
      A[i]=r;
      A[i+1]=c;
    }
 
  MatrixChain();
 
  return 0;
}

void MatrixChain()
{
 
  int i,j,k,l,cost;
 
  for(i=1; i<=n; i++)
    {
      B[i][i]=0;
    }
 
  for(l=2; l<=n; l++)
    {
      for(i=1; i<=n-l+1; i++)
    {
      j=i+l-1;
      B[i][j]=INT_MAX;
 
      for(k=i; k<=j-1; k++)
        {
          cost=B[i][k]+B[k+1][j]+A[i-1]*A[k]*A[j];
          if(cost < B[i][j])
        {
          B[i][j]=cost;
        }
        }
    }
    }
  printf("%d\n",B[1][n]);
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  int n;
  cin>>n;
  vector<ll>r(n),c(n);
  rep(i,n)cin>>r[i]>>c[i];
  vector<vector<ll>>dp(n+1,vector<ll>(n+1,INF));
  rep(i,n)dp[i][i+1]=0;
  REP(w,2,n+1){
    rep(i,n){
      int j=i+w;
      if(j>n)continue;
      for(int k=i+1;k<j;++k){
        chmin(dp[i][j],dp[i][k]+dp[k][j]+r[i]*r[k]*c[j-1]);
      }
    }
  }
  cout<<dp[0][n]<<"\n";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

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

int main(){
  int n,b[200],bb[200][200],a,c,min;
  cin>>n;
  for(int i=1;i<n;i++){
    cin>>a>>c;
    b[i]=a;
  }
  cin>>a>>c;
  b[n]=a;
  b[n+1]=c;
  for(int i=1;i<=n;i++){
    bb[i][i]=0;
    if(i<n)bb[i+1][i]=b[i]*b[i+1]*b[i+2];
  }
  for(int i=2;i<=n-1;i++){
    for(int j=1;j<=n-i;j++){
      min=1000000000;
      for(int l=j;l<j+i;l++){
	if(min>bb[l][j]+bb[j+i][l+1]+b[j]*b[l+1]*b[j+i+1])
	  min=bb[l][j]+bb[j+i][l+1]+b[j]*b[l+1]*b[j+i+1];
      }
      bb[j+i][j]=min;
    }
  }

  cout<<bb[n][1]<<endl;
  return 0;
}

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

*/