Go: package main

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

const N = 100

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

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, N+1)
	m := make([][]int, N+1)
	for i := range m {
		m[i] = make([]int, N+1)
	}
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 1; i <= n; i++ {
		scanner.Scan()
		p[i-1], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		p[i], _ = strconv.Atoi(scanner.Text())
	}
	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])
			}
		}
	}
	fmt.Println(m[1][n])
}

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;
}

C++: #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

ll n;
vector<vector<ll>> dp(n, vector<ll>(n, INF));  //dp[i][j] i to j min cost
vector<pair<ll,ll>> vec(n);

ll calc_mult(pair<ll,ll> a, pair<ll,ll> b){
    return a.first * a.second * b.second;
}

ll calc_sec(ll a, ll b){
    if(dp[a][b] != -1){
        return dp[a][b];
    }
    if(b == a){
        return 0;
    }
    if(b - a == 1){
        dp[a][b] = vec[a].first * vec[a].second * vec[b].second;
        return vec[a].first * vec[a].second * vec[b].second;
        //return 0;
    }


    ll res = INF;
    for(ll i = a; i < b; i++){
        res = min(res, calc_sec(a, i) + calc_sec(i+1, b) + vec[a].first * vec[i].second * vec[b].second);
    }

    dp[a][b] = res;
    return res;
}


int main() {
    std::cout << std::fixed << std::setprecision(15);
    cin >> n;

    vec.resize(n);
    rep(i, n) cin >> vec[i].first >> vec[i].second;

    if(n == 1){
        cout << 0 << endl;
        return 0;
    }

    
    dp.resize(n, vector<ll>(n));
    dp.assign(n, vector<ll>(n, -1));
    rep(i,n){
        dp[i][i] = 0;
    }

    /*
    cout << calc_sec(0, 1) << endl;
    cout << calc_sec(0, 2) << endl;
    cout << calc_sec(0, 5) << endl;
    */
    /*
    rep(i,n){
        rep(j,n){
            cout << dp[i][j] << " ";
        }
        br;
    }
    */

    cout << calc_sec(0, n-1) << endl;







}

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n),b(n);
    rep(i,n)std::cin >> a[i]>>b[i];
    vvector(dp,int,n+1,n+1,INF);
    rep(i,n+1)dp[i][i]=0;
    rep(i,n)dp[i][i+1]=0;
    rep(i,n-1){
        dp[i][i+2]=a[i]*b[i]*b[i+1];
     //   std::cout << dp[i][i+2] << std::endl;
    }
    
    rrep(i,3,n+1){
        rep(j,n-i+1){
            //dp[j][j+i]=min(dp[j][j+i-1]+a[j]*a[j+i-1]*b[j+i-1],dp[j+1][j+i]+b[j+i-1]*a[j]*b[j]);
            rrep(ii,j+1,i+j)chmin(dp[j][j+i],dp[j][ii]+dp[ii][j+i]+a[j]*b[j+i-1]*a[ii]);
        }
    }
    std::cout << dp[0][n] << std::endl;
    
}