Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

type matrixSize struct{ row, col int }

func calcNum(i, j matrixSize) int {
	return i.row * j.col * i.col
}

func parseProblem() (int, []matrixSize) {
	n := scanInt(sc)
	sizes := make([]matrixSize, n)
	for i := 0; i < n; i++ {
		sizes[i] = matrixSize{row: scanInt(sc), col: scanInt(sc)}
	}
	return n, sizes
}

var dp [][]int

func initDP(n int) {
	dp = make([][]int, n+1)
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, n+1)
		for j := 0; j < len(dp[i]); j++ {
			dp[i][j] = math.MaxInt64
		}
	}
}

func resolve(n int, sizes []matrixSize) int {
	// TODO 復習
	initDP(n)
	_rec(sizes, 0, n)
	return dp[0][n]
}

func _rec(sizes []matrixSize, l, r int) int {
	if dp[l][r] != math.MaxInt64 {
		return dp[l][r]
	}
	if r-l <= 1 {
		dp[l][r] = 0
		return 0
	}
	num := math.MaxInt64
	for i := l + 1; i < r; i++ {
		v := _rec(sizes, l, i) + _rec(sizes, i, r) + calcNum(matrixSize{sizes[l].row, sizes[i].row}, matrixSize{sizes[i].row, sizes[r-1].col})
		if v < num {
			num = v
		}
	}
	dp[l][r] = num
	return dp[l][r]
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<iostream>
#include<cstdio>
#include<climits>
using namespace std;
  int n;

int m[101][101];
  int p[101];
void chain(){
  int n1;
  int j;
  int q;
  n1=n;
  //ok
  // cout <<"n1 "<<n1<<endl;
  for(int i=1;i<=n1;i++){
    m[i][i]=0;
  }
  for(int l=2;l<=n1;l++){
    for(int i=1;i<=n1-l+1;i++){
      j=i+l-1;
      m[i][j] = INT_MAX;
      for(int k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	//	cout<<"q "<<q<<endl;
	if(q<m[i][j]){
	  m[i][j]=q;
	  //	  cout<<s[i][j]<<endl;
	}
      }
    }
  }
}

int main(){

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

  //ok
  /*
 for(int i=0;i<=n;i++){
   cout<<"p "<<p[i]<<endl;
 }
  */
  chain();
  /*  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cout<<m[i][j]<<endl;
    }
   }
*/
  cout<<m[1][n]<<endl;

  return 0;
}

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

using namespace std;
int N = 100;

int main(){
  int i,j,k,l;
  int n,p[N+1],m[N+1][N+1];
  cin >> n;
  for(i = 1; i <= n; i++){
    cin >> p[i-1];
    cin >> 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++){
      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<iostream>
#include<algorithm>
using namespace std;
static const int N = 100;


int main() {
	int n;
	cin >> n;
	int p[N],m[N+1][N+1];
	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;
static const int N=100;
int main(){
  int j,i,k,n,l,p[N+1],m[N+1][N+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&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++){
      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[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
        }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
static const int MAX = 100;
#define INF (1 << 30);

int store[MAX][MAX] = {{}};

struct matrix {
  int row;
  int col;
};

int nMul(matrix x, matrix y) { return x.row * x.col * y.col; }

matrix mult(matrix x, matrix y) {
  matrix mat;
  mat.row = x.row;
  mat.col = y.col;
  return mat;
}

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

  int mcm[MAX][MAX] = {0};
  i         k         j
  for (int j = 1; j < n; j++) {
    for (int i = j-1; i >= 0; i--) {
      int minimum = INF;
      for (int k = i; k < j; k++) {
        int joint = nMul(mult(mat[i], mat[k]), mult(mat[k+1], mat[j]));
        int tmp = mcm[i][k] + mcm[k+1][j] + joint;
        minimum = min(minimum, tmp);
      }
      mcm[i][j] = minimum;
    }
  }

  cout << mcm[0][n-1] << endl;
}

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

#define MAX 1000
#define INFINITY 2000000000

int A[MAX];
int m[MAX][MAX];
int n;

void minimumCount() {
    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] = INFINITY;
            for (int k = i; k < j; ++k) {
                m[i][j] = std::min(m[i][j], m[i][k] + m[k+1][j] + A[i-1] * A[k] * A[j]);
            }
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d %d", &A[i - 1], &A[i]);
    }
    minimumCount();
    printf("%d\n", m[1][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=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] = (l<<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 rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void prarr(vector<vector<T>>& a){
rep(i, a.size()){
rep(j, a[i].size()){
cout << a[i][j]; printf(" ");}
printf("\n");} printf("\n");}

vector<ll> row, col;
arr<ll> dp;
ll ans = INFL;
int n; 

ll dfs(int l, int r){
    // printf("%lld %lld\n", l, r);
    if(dp[l][r]!=INFL) return dp[l][r];
    if(l==r) return dp[l][r] = 0;
    if(r==l+1) return dp[l][r] = row[l] * col[l] * col[r];

    ll tmp = INFL;
    FOR(k, l, r){
        chmin(tmp, dfs(l, k) + dfs(k+1, r) + row[l] * col[k] * col[r]);
    }

    return dp[l][r] = tmp;
}

int main()
{
    cin >> n;
    row.resize(n); col.resize(n);
    rep(i, n){
        cin >> row[i] >> col[i];
    }
    dp.assign(n, vector<ll>(n, INFL));

    ans = dfs(0, n-1);
    
    // prarr(dp);
    pr(ans);
    return 0;}