Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		fmt.Scan(&a[i+1])
	}

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

	for d := 2; d <= n; d++ {
		for s := 0; s+d <= n; s++ {
			min := 1 << 30
			for j := s+1; j < s+d; j++ {
				val := m[s][j] + m[j][s+d] + a[s]*a[j]*a[s+d]
				if val < min {
					min = val
				}
			}
			m[s][s+d] = min
		}
	}
	fmt.Println(m[0][n])
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
const int N = 100;
int main()
{
	int n, dimen[N + 1], cost[N + 1][N + 1];
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> dimen[i - 1] >> dimen[i];
	for (int i = 1; i <= n; i++)
		cost[i][i] = 0;
	for (int cnt = 2; cnt <= n; cnt++)
	{
		for (int i = 1; i <= n - cnt + 1; i++)
		{
			int j = i + cnt - 1;
			cost[i][j] = (1 << 21);
			for (int k = i; k <= j - 1; k++)
				cost[i][j] = min(cost[i][j], cost[i][k]+cost[k + 1][j] + dimen[i - 1] * dimen[k] * dimen[j]);
		}
	}
	cout << cost[1][n] << endl;
}

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

const int N = 110;
int x[N],y[N];
int dp[N][N];

int matrix(int l,int r){
  if(dp[l][r] > -1) return dp[l][r];
  int res = (1 << 30);
  for(int i = l; i < r; i++){
    res = min(res,matrix(l,i)+matrix(i+1,r)+y[l]*x[i]*x[r]);
  }
  return dp[l][r] = res;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

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

  fill(dp[0],dp[N],-1);
  for(int i = 0; i < N; i++) dp[i][i] = 0;
  cout << matrix(0,n-1) << endl;

  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define Lens 105

using namespace std;
int p[Lens];
int C[Lens][Lens];
int N;

int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> p[i - 1] >> p[i];
		C[i][i] = 0;
	}
	for (int k = 1; k < N; k++)
	{
		for (int i = 1; i <= N-k; i++)
		{
			int j = i + k;
			C[i][j] = C[i][i] + C[i + 1][j]+p[i-1]*p[i]*p[j];
			for (int t = i+1; t < j; t++)
			{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
				C[i][j] = min(C[i][j], C[i][t] + C[t+1][j] + p[i - 1] * p[t] * p[j]);
			}
		}
	}
	cout << C[1][N]<<endl;

	return 0;

}

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