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


int main() {
  int n;
  cin >> n;
  vector<int> RC(n+1);
  for(int i = 0;i < n;i++){
      cin >> RC.at(i) >> RC.at(i+1);
  }

  vector<vector<int>> cost(n+1,vector<int>(n+1));
  int min_cost;
  for (int l = 2;l <= n;l++){
      for (int i = 1;i <= n-l+1;i++){
          int j = i+l-1;
          for (int k = i;k < j;k++){
              if (k == i){
                  min_cost = cost.at(i).at(k)+cost.at(k+1).at(j)+RC.at(i-1)*RC.at(k)*RC.at(j);
              }else{
                  min_cost = min(min_cost,cost.at(i).at(k)+cost.at(k+1).at(j)+RC.at(i-1)*RC.at(k)*RC.at(j));
              }
          }
          cost.at(i).at(j) = min_cost;
      }
  }

  cout << cost.at(1).at(n) << endl;
  
}

C++: #include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
typedef long long ll;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define Rep(i,n) REP(i,0,n)
ll longinf=1ll<<60;

ll n,p[101],m[101][101];
int main(){
    cin>>n;
    Rep(i,n){
        cin>>p[i]>>p[i+1];
    }
    REP(i,1,n+1) m[i][i]=0;
    REP(l,2,n+1){
        REP(i,1,n-l+2){
            int j=i+l-1;
            m[i][j]=longinf;
            REP(k,i,j+1){
                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 <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>
#include <climits>
using namespace std;
typedef long long ll;

int dp[101][101];

void init() {
    for (int i=0; i<101; ++i) {
        for (int j=0; j<101; ++j) {
            if (i == j) {
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = INT_MAX;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<pair<int,int>> mat(n);
    for (int i=0; i<n; ++i) {
        cin >> mat[i].first >> mat[i].second;
    }

    init();

    for (int l=2; l<=n; ++l) {
        for (int i=0; i<n; ++i) {
            int j = i+l-1;
            if (j > n) continue;
            for (int k=i+1; k<=j; ++k) {
                dp[i][j] = min(dp[i][j], dp[i][k-1] + dp[k][j]
                               + mat[i].first * mat[j].second * mat[k].first);
            }
        }
    }
    cout << dp[0][n-1] << endl;

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[111][111];
signed main(){
  int n;
  cin>>n;
  int r[n],c[n];
  for(int i=0;i<n;i++) cin>>r[i]>>c[i];
  int INF=1LL<<55LL;
  for(int i=0;i<111;i++) fill_n(dp[i],111,INF);
  for(int i=0;i<n;i++) dp[i][i+1]=0;
  for(int i=2;i<=n;i++)
    for(int j=0;j<=n-i;j++)
      for(int k=1;k<i;k++)
	dp[j][j+i]=min(dp[j][j+i],dp[j][j+k]+dp[j+k][j+i]+(r[j]*r[j+k]*c[j+i-1]));
  cout<<dp[0][n]<<endl;
  return 0;
}

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

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<iostream>
#include<cstdio>
#include<algorithm>
#define inf 1 << 21
#define MAX 100
using namespace std;

int m[MAX + 1][MAX + 1], p[MAX + 1],n;

void MCM(){
    
    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] = inf;
            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]);
            }
        }
    }
    printf("%d\n",m[1][n]);
}

int main(){
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%d %d",&p[i-1],&p[i]);
    MCM();
    return 0;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vector<pii> mat;
vvi dp;
int rec(int l, int r){
    if(dp[l][r] != INF) return dp[l][r];
    if(l == r) return dp[l][r] = 0;
    int res = INF;
    REP(i,l,r){
        int x = mat[l].fi * mat[i].se * mat[r].se;
        res = min(res, x + rec(l,i) + rec(i+1,r));
    }
    return dp[l][r] = res;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    mat = vector<pii>(n);
    rep(i,n){
        int r, c; cin >> r >> c;
        mat[i] = pii(r, c);
    }
    dp = vvi(n, vi(n, INF));
    if(n == 1) cout << 0 << endl;
    else cout << rec(0, n-1) << endl;
    return 0;
}

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

static const int N = 100;

struct Matrix{int row, col;};
Matrix M[N];
int cost[N][N] = {0};

int prod(int begin, int end){
  int mincost = 100000000, l = end - begin;
  if(cost[begin][end] > 0){
    return cost[begin][end];
  } else {
    if(l == 0){
      mincost = 0;
    } else if(l == 1){
      cost[begin][end] = M[begin].row * M[begin].col * M[end].col;
      mincost = cost[begin][end];
    } else {
      int temp;
      for(int i = 0; i < l; i++){
        temp = prod(begin, begin + i) + prod(begin + i + 1, end);
        temp += M[begin].row * M[begin + i].col * M[end].col;
        mincost = min(mincost, temp);
      }
      cost[begin][end] = mincost;
    }
    return mincost;
  }
}

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> M[i].row >> M[i].col;
  }

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

  return 0;
}