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;

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=0; 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<iostream>
#include<algorithm>
using namespace std;
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] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 200000001;
int m[101][101];
int p[101];

int main(void)
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> p[i] >> p[i + 1];
	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] = MAX;
			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 <iostream>
#include <algorithm>
using namespace std;

static const int N=100;

//求解矩阵链乘法的最优解
//p 用于存储矩阵的行和列的
//dp[i][j] 表示从矩阵i乘到矩阵j的最小乘法次数

int main(){
    int n;
    int p[N+1],dp[N+1][N+1];

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

    for(int i=1;i<n;i++){
        dp[i][i]=0;
    }
    for(int l=2;l<=n;l++){
        for(int i=1;i<=n-l+1;i++){
            int j=i+l-1;
            dp[i][j]=(1<<21);//取一个很大的值
            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>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> p(n+1);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    if(i != 0) p.at(i+1) = b;
    else{
      p.at(0) = a;
      p.at(1) = b;
    }
  }
  vector<vector<ll>> dp(n, vector<ll>(n, 0));
  rep2(l, 1, n){
    rep(i, n - l){
      int j = i + l;
      dp.at(i).at(j) = LLONG_MAX;
      rep2(k, i, j){
        ll add = dp.at(i).at(k) + dp.at(k+1).at(j) + p.at(i) * p.at(k+1) * p.at(j+1);
        dp.at(i).at(j) = min(dp.at(i).at(j), add);
      }
    }
  }
  // rep(i, n){
  //   rep(j, n){
  //     printf("%9d ", (int)dp.at(i).at(j));
  //   }
  //   cout << endl;
  // }
  cout << dp.at(0).at(n-1) << endl;
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
static const int N=100;

int main(){
  int n,i,l,k,p[N+1],m[N+1][N+1];
  cin>>n;
  for(i=1;i<=n;i++){
    cin>>p[i-1]>>p[i];
  }
  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      int 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]);
      }
    }
  }
  cout<<m[1][n]<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  vector<ll> rows(n + 5), cols(n + 5);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%lld %lld", &rows[i + 1], &cols[i + 1]);
  }
  vector<vector<ll> > dp(n + 5, vector<ll>(n + 5, 0));
  for (int l = 2; l <= n; ++l) {
    for (int i = 1; i <= n - l + 1; ++i) {
      int j = l + i - 1;
      dp[i][j] = std::numeric_limits<ll>::max();
      for (int k = i; k <= j - 1; ++k) {
        dp[i][j] = min(dp[i][j],
                       dp[i][k] + dp[k + 1][j] + rows[i] * cols[k] * cols[j]);
      }
    }
  }
  fprintf(stdout, "%lld\n", dp[1][n]);
  return 0;
}

C++: #include <stdlib.h>
#include <stdio.h>

int MCM(int n){
int i,j,k,l,m[101][101],p[101],x;

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]=10000000;
        for(k=i;k<=j;k++){
            x=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
            if(m[i][j]>x)m[i][j]=x;
            }
        }
    }
return m[i][j];
}

int main(){

int i,n,m[101];

scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d %d",&m[i],&m[i+1]);
   }
printf("%d\n",MCM(n));
return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
pii A[200];//firstは行secondを列とする
int dp[200][200];//dp[i][j]:=Ai...Ajの最小スカラー積とする
int n;
int f[200][200];//最適な括弧を挿入する位置
void solve(){
	for(int i =0;i < n;i++){
		for(int j =0;j < n;j++){
			if(i==j)dp[i][j]=0;
			else dp[i][j]=INF;
		}
	}
	
	for(int k =1;k <n;k++){//鎖の数
		for(int i =0;i <n-k;i++){//どこから始めるか
			for(int j =i;j <i+k;j++){//どこに括弧を挟むか
				int tmp =A[i].first*A[j].second*A[i+k].second;
				if(dp[i][i+k] >dp[i][j]+dp[j+1][i+k]+tmp){
					dp[i][i+k]=dp[i][j]+dp[j+1][i+k]+tmp;
					f[i][i+k] =j;
				}
			}
		}
	}
}

void print(int i,int j){//解を表示する
	if(i==j){
		cout <<"A"<<i;
	}else{
		cout <<"(";
		print(i,f[i][j]);
		print(f[i][j]+1,j);
		cout <<")";
	}
}


int main(){
	cin>>n;
	for(int i =0;i < n;i++){
		cin>>A[i].first>>A[i].second;
	}
	solve();
	cout <<dp[0][n-1]<<endl;
	//print(0,n-1);
	return 0;
}