Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	var n int
	var M [101][101]int

	n = nextInt()

	P := make([]int, n*2)

	for i := 1; i <= n; i++ {
		P[i-1] = nextInt()
		P[i] = nextInt()
	}
	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			M[i][j] = 1000000
			for k := i; k <= j-1; k++ {
				M[i][j] = int(math.Min(float64(M[i][j]), float64(M[i][k]+M[k+1][j]+P[i-1]*P[k]*P[j])))
			}
		}
	}
	fmt.Println(M[1][n])
}

C++: #include<iostream>
#include<vector>

const static int MAX = 1000;
const static int INF = 1001001001;

int M[MAX];
int C[MAX][MAX];

int main(void){
    int n;
    int trash;
    std::cin >> n;
    std::cin >> M[0];
    for(int i = 1; i <= n; i++){
	std::cin >> M[i];
	std::cin >> trash;
    }

    for(int i = 0; i < MAX; i++){
	for(int j = 0; j < MAX; j++){
	    C[i][j] = INF;
	}
    }

    for(int i = 0; i < MAX; i++){
	C[i][i] = 0;
    }


    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++){
		int tmp = C[i][k] + C[k+1][j] + M[i-1] * M[k] * M[j]; 
		if(tmp < C[i][j]){
		    C[i][j] = tmp;
		}
	    }
	}
    }

    std::cout << C[1][n] << std::endl;

    return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1000000000
typedef long long ll;
using namespace std;

int main()
{
	ll n;
	cin >> n;
	vector<ll> M(n + 1);
	cin >> M[0];
	for (int i = 1; i < n; i++) {
		cin >> M[i] >> M[i];
	}
	cin >> M[n];
	vector<vector<ll>> dp(n, vector<ll>(n, INF)), mon(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		dp[i][i] = 0;
		mon[i][i] = i;
	}
	for (ll k = 1; k < n; k++) {
		for (ll i = 0; i + k < n; i++) {
			for (ll j = 0; j <= i + k - 1; j++) {
				ll cost = dp[i][j] + dp[j + 1][i + k] + M[i] * M[j + 1] * M[i + k + 1];
				if (cost < dp[i][i + k]) {
					dp[i][i + k] = cost;
					mon[i][i + k] = j;
				}
			}
		}
	}
	cout << dp[0][n - 1] << endl;
	return 0;
}

C++: /*
 * ALDS1_10_B.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>
#include<algorithm>

using namespace std;

struct Mat {
	int row;
	int col;
};

long mcm(Mat* M, int n) {
	long dp[101][101];
	for(int i=2; i<=n; i++) {
		for(int j=0; j<=n-i; j++) {
			dp[i][j] = 99999999999L;
			for(int k=1; k<i; k++) {
				dp[i][j] = min(dp[k][j]+dp[i-k][j+k]+M[j].row*M[j+k].row*M[j+i-1].col, dp[i][j]);
			}
		}
	}
	return dp[n][0];
}

int main() {
	int n;
	Mat M[100];

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

	cout << mcm(M, 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 <iostream>
#include<climits>
using namespace std;
int m[100][100];

int MCM(int p[],int n) {
	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; i++) {
			int j = i + l - 1;
			m[i][j] = INT_MAX;
			for (int k = i; k <= j; k++) {
				int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
				if (m[i][j] > q) {
					m[i][j] = q;
				}

			}
		}

	}
	return m[0][n - 1];
}

int main() {
	int n, p[200];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[2*i] >> p[2*i + 1];
	}
	cout << MCM(p, n) << endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#define MAX 100
#define INFTY (1 << 21)
using namespace std;

int main() {
	int n, p[MAX + 1], mat[MAX + 1][MAX + 1];;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i - 1] >> p[i];
	}
	for (int i = 1; i <= n; i++) {
		mat[i][i] = 0;
	}
	for (int k = 2; k <= n; k++) {
		for (int i = 1; i <= n - k + 1; i++) {
			int j = i + k - 1;
			mat[i][j] = INFTY;
			for (int h = i; h <= j - 1; h++) {
				mat[i][j] = min(mat[i][j], mat[i][h] + mat[i][h] + mat[h + 1][j] + (p[i - 1] * p[h] * p[j]));
			}
		}
	}
	cout << mat[1][n] << endl;
	return 0;
}

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;

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define all(v) (v).begin(), (v).end()

const int inf = 1e9+100;
vector<vector<int>> dp;
vector<int> a, b;

int dfs(int l, int r) {
    int& res = dp[l][r];
    if (res != inf) return res;
    if (r - l == 1) return res = 0;
    reps(i, l+1, r) {
        int t = dfs(l, i) + dfs(i, r) + a[l] * a[i] * b[r-1];
        res = min(res, t);
    }
    return res;
}

int main() {
    int n; cin >> n;
    a.resize(n); b.resize(n);
    rep(i, n) cin >> a[i] >> b[i];
    dp.resize(n+1, vector<int>(n+1, inf));
    cout << dfs(0, n) << endl;
}