Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

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

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	m := make([][]int, n)
	sizes := make([][]int, n)
	for i := 0; i < n; i++ {
		sizes[i] = []int{nextInt(), nextInt()}
		m[i] = make([]int, n)
	}
	// fmt.Println(sizes)

	for w := 1; w < n; w++ {
		for i := 0; i < n-w; i++ {
			j := i + w
			minBetweenIandJ := 10000000
			for k := i; k < j; k++ {
				// fmt.Println(i, j, k, m[i][k], m[k+1][j], sizes[i][0]*sizes[k][1]*sizes[j][1])
				minBetweenIandJ = min(minBetweenIandJ, m[i][k]+m[k+1][j]+sizes[i][0]*sizes[k][1]*sizes[j][1])
			}
			m[i][j] = minBetweenIandJ
		}
	}
	// for i := 0; i < len(m); i++ {
	// 	fmt.Println(stringifyArray(m[i]))
	// }
	fmt.Println(m[0][n-1])
}

C++: // http://algorithms.blog55.fc2.com/blog-entry-66.html

#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>

#define M 100

int N,R[M+1],C[M][M],B[M][M];

void compute(){
	int i=0,j,k,cost;
	memset(C,99,sizeof(C));
	for(;i<N;i++)C[i][i]=0;
	for(j=1;j<N;j++)
		for(i=0;i<N - j; i++ ){
			for (k = i; k < i + j; k++ ){
				cost = C[i][k] + C[k+1][i+j] + R[i]*R[k+1]*R[i+j+1];
				if(cost<C[i][i+j])C[i][i+j]=cost,B[i][i+j]=k; 
			}
		}
	}
}

void order( int i, int j ){
	if ( i == j ) cout << "M" << i;
	else{
		cout << "(";
		order( i, B[i][j]-1 ); order(B[i][j], j);
		cout << ")";
	}
}

void input(){
	cin >> N;
	int z,i=0;
	for (; i < N; i++ ) cin >> R[i]>>z;
	R[i]=z;
	//SIZE++;
}

void output(){
	cout <<  C[0][N-1] << endl;
	//order(0, N);
	//cout << endl;
}

main(){
	input();
	compute();
	output();
}

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];  //??´?????????????¬¬i??????????????????p[i-1]*p[i]??????m[i][j]???????????????i??°j??????????????????????§£
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>p[i]>>p[i+1];

    //init
    for(int i=1;i<=n;i++) m[i][i]=0;
    for(int l=2;l<=n;l++) //?????????2????????????????§???????????????´????????°?????????n
    {
        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;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;
}

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 = 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] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
    cout << m[1][n] << endl;
    
    return 0;
}

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

int n;
int num[101][101];
int p[101];

void matrixChainMultiplication(){
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      num[i][j]=INT_MAX;
      for(int k=i;k<=j-1;k++)
	num[i][j]=min(num[i][j],num[i][k]+num[k+1][j]+p[i-1]*p[k]*p[j]);
    }   
  }
  cout<<num[1][n]<<endl;
}

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

C++: #include<iostream>
#include<cstdio>
#define INT_MAX 100000000
using namespace std;
int sentinel;
int Mi[1000][1000];

void calc(int p[]);

int main(){
  int p[1000],a,b;
  scanf("%d",&sentinel);
  for(int i=0;i<sentinel;i++){
    scanf("%d %d",&a,&b);
    p[i] = a;
    if(i == sentinel-1)p[i+1] = b;
  }

  sentinel = sentinel+1;
  calc(p);

  printf("%d\n",Mi[1][sentinel-1]);
  return 0;
}

void calc(int p[]){
  int n = sentinel-1,j,q,l,k;
  for(int i=1;i<=n;i++)Mi[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      j = i+l-1;
      Mi[i][j] = INT_MAX;
      for(int k=i;k<=j-1;k++){
        q = Mi[i][k] + Mi[k+1][j] + p[i-1]*p[k]*p[j];
        if(q<Mi[i][j]){
          Mi[i][j] = q;
        }
      }
    }
  }
}

C++: #include<iostream>
#include<algorithm>
using namescape 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=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;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 <vector>
#include <algorithm>
using namespace std;

#define INF 1e9

int main(void){
  int n, temp;
  cin >> n;

  vector<int> c(n+1);
  cin >> c[0] >> c[1];
  for(int i=2; i<n+1; i++)
    cin >> temp >> c[i];

  vector< vector<int> > dp(n, vector<int>(n+1, INF));
  for(int i=0; i<n; i++)
    dp[i][i+1] = 0;
  
  for(int i=2; i<n+1; i++)
    for(int j=0; j<n; j++)
      for(int k=1; k<i; k++)
	if(j+i < n+1)
	  dp[j][j+i] = min(dp[j][j+i],
			   dp[j][j+k]+dp[j+k][j+i]+c[j]*c[j+k]*c[j+i]);
  
  cout << dp[0][n] << endl;
  
  return 0;
}

C++: // ALDS1_10_B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

vector<int> r(110);
vector<int> c(110);
int inf=pow(10,9);
vector<vector<int>> dp(110,vector<int>(110,inf));
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    
    int n;
    cin>>n;
    rep(i,n) cin>>r[i]>>c[i];
    rep(i,n) dp[i][i]=0; //長さ1の計算量
    for(int L=2;L<=n;L++){ //長さ 短い長さからdpテーブルを埋めていく
        for(int i=0;i<=n-2;i++){ //始点
            int j=i+L-1; //終点
            if(n-1<j) break; //範囲オーバー 
            for(int k=i;k<=j-1;k++){ //i~k,k+1~jで区切る。区切ったブロックの長さは互いにL以下なので、すでに互いのブロックの最小コストはdpテーブルにある。
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*r[k+1]*c[j]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using ll = long long;
const int inf = 1e8;

int dp[105][105];

int main() {
    int n;
    cin >> n;
    vector<int> p(n+1);
    cin >> p[0] >> p[1];
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        p[i+2] = b;
    }
    rep(i,105)rep(j,105) dp[i][j] = inf;
    rep(i,n+1) dp[i][i] = 0;
    for (int i = n-1; i >= 1; i--) {
        for (int j = i+1; j <= n; j++) {
            if (j == i+1) dp[i][j] = p[i-1]*p[i]*p[i+1];
            else {
                for (int k = i; k <= j-1; 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;
}