Go: package main

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

const N = 100

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

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, N+1)
	m := make([][]int, N+1)
	for i := range m {
		m[i] = make([]int, N+1)
	}
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 1; i <= n; i++ {
		scanner.Scan()
		p[i-1], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		p[i], _ = strconv.Atoi(scanner.Text())
	}
	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] = 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])
			}
		}
	}
	fmt.Println(m[1][n])
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	int n, p[101], m[101][101];
  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; 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;

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 <algorithm>
#include <vector>
#include <climits>
#define range(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
using namespace std;

int n;
int m[110][110];
int p[110];

int matrixChainMultiplication() {
  rep1(i, n) m[i][i] = 0;

  range(l, 2, n) {
    rep1(i, n - l + 1) {
      int j = i + l - 1;
      m[i][j] = INT_MAX;
      range(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]);
      }
    }
  }
  return m[1][n];
}

int main() {
  cin >> n;
  rep1(i, n) {
    cin >> p[i - 1] >> p[i];
  }
  cout << matrixChainMultiplication() << endl;
  return 0;
}

C++: //ALDS1_10B Matrix Chain Multiplication
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

static const int N=100;
vector<int> p(N+1);
vector< vector<int> > m(N+1,vector<int>(N+1));

int main(){
 int n;
 cin >> n;
 for(int i=1;i<=n;i++){
 cin>>p[i-1]>>p[i];
 }
 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<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int dp[100][100];
	int P[101];

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

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; (j + i) < n; j++)
		{
			if (i == 0)
			{
				dp[j][j + i] = 0;
			}
			else if (i == 1)
			{
				dp[j][j + i] = P[j] * P[j + 1] * P[j + 2];
			}
			else
			{
				int mini = 10000000;
				for (int k = 0; k < i; k++)
				{
					mini = min(mini, dp[j][j + k] + dp[j + k + 1][j + i] + P[j] * P[j + k + 1] * P[j + i + 1]);
				}
				dp[j][j + i] = mini;
			}
		}
	}

	cout << dp[0][n - 1] << endl;

	return 0;
}

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

using namespace std;
static const int N = 100;

int main(){
  //int i,j,k,l;
  int n,p[N+1],m[N+1][N+1];
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> p[i-1];
    cin >> 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] = INFINITY;
      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 rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

vl R, C;

vector<vl> dp;

ll calc(int l, int r) {
    if(dp[l][r] != INF) return dp[l][r];
    auto& ret = dp[l][r];
    if(r - l == 1) return ret = 0;
    if(r - l == 2) return ret = R[l] * C[l] * C[l+1];
    for(int m = l + 1; m < r; ++m) {
        chmin(ret, R[l] * C[m-1] * C[r-1] + calc(l, m) + calc(m, r));
    }
    return ret;
}

int main(){
    int n;
    cin >> n;
    R.resize(n);
    C.resize(n);
    rep(i, n) cin >> R[i] >> C[i];
    dp = vector<vl>(n+1, vl(n+1, INF));
    cout << calc(0, n) << endl;
    return 0;
}

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

#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)printf("M%d",i);
	else{
		printf("(");
		order( i, B[i][j]-1 ); order(B[i][j], j);
		printf(")");
	}
}

void input(){
	scanf("%d",&N);
	int z,i=0;
	for(;i<N;i++)scanf("%d%d",R+i,z);
	R[i]=z;
}

void output(){
	printf("%d\n",C[0][N-1]);
	//order(0, N);
	//puts("");
}

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