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++: const int MAX_SIZE = 101;

int dp[MAX_SIZE][MAX_SIZE];

int solve(int p[], int begin,int end) {
	if (dp[begin][end] != -1)return dp[begin][end];
	if (begin >= end - 1)return 0;
	int res = -1;
	for (int i = begin + 1; i < end; i++) {
		int temp = solve(p, begin, i) + solve(p, i, end) + (p[begin] * p[i] * p[end]);
		if (res != -1) {
			res = min(temp, res);
		}
		else {
			res = temp;
		}
	}
	return dp[begin][end] = res;
}

int main() {
	int N;
	int p[MAX_SIZE + 1];

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

	for (int i = 0; i < MAX_SIZE; i++) {
		for (int j = 0; j < MAX_SIZE; j++) {
			dp[i][j] = -1;
		}
	}

	cout << solve(p, 0, N) << endl;
	return 0;
}

C++: #include <stdio.h>

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

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

static const int N = 101;

int main(){
    //配列mにはn以下の行列連鎖積の最小回数が格納される
    int n,p[N],m[N][N];
    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++){
            //i,j,kは行列の範囲を表す
            //i<=k<j
            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;
}

C++: //?????????B 
#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>
using namespace std;

static const int N = 100;

int main()
{
    int n,p[N+1],m[N+1][N+1],i,l,j,k;
    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++)
        {
        j = i+l-1;
        m[i][j] = (i << 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 <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <climits>
using namespace std;

int mcm(vector<int>& p)
{
    vector<vector<int> > m(p.size() - 1, vector<int>(p.size() - 1));
    for (int i = 0; i < m.size(); i++) {
        m[i][i] = 0;
    }
/*
 * l == number of targets
 * i == left most of targets
 */
    for (int l = 2; l <= m.size(); l++) {
        for (int i = 0; i < m.size() - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = INT_MAX;
            for (int k = i; k < j; k++) {
                m[i][j] =
                    min(m[i][j],
                        m[i][k] + m[k + 1][j] + p[i] * p[k + 1] * p[j + 1]);
            }
        }
    }
    return m[0][m.size() - 1];
}

int main()
{
    int n, x, y;
    cin >> n;
    vector<int> p(n + 1);
    for (int i = i; i < n + 1; i++) {
        cin >> p.at(i - 1) >> p.at(i);
    }
    cout << mcm(p) << endl;
    return 0;
}

C++: #include<iostream>
#include<string>
#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];
  }

  // M[i][j] i=j ならばその掛け算の回数は0回
  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 f[101][101];
int p[10001];
int n;
int doit(int i,int j){
	 if (f[i][j]!=0x1f1f1f1f)
	    return f[i][j];
	 for (int k=i; k<j; k++)
	 	 f[i][j]=min(f[i][j],doit(i,k)+doit(k+1,j)+p[i-1]*p[k]*p[j]);
	 return f[i][j];
}
    
int main(){
	cin>>n;
	for (int i=1; i<=n; i++)
	    cin>>p[i-1]>>p[i];
	memset(f,0x1f1f1f1f,sizeof(f));
	for (int i=1; i<=n; i++)
	    f[i][i]=0;
	doit(1,n);
    cout<<f[1][n]<<endl;
	return 0;
}

C++: #include<bits/stdc++.h>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;


void printv(vvi v){
	for(int i = 0; i < v.size(); i++){
		for(int j = 0; j < v.size(); j++){
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	return ;
}


signed main() {
	
	cin1(n);

	vi p(n+2);
	rep(i,1,n+1) {
		cin2(p[i-1],p[i]);
	}

	
	vvi dp(n,vi(n,0));
	for (int i = 2; i <= n; i++) { //???????????°
		for (int j = 0; j < n - i + 1; j++) { //??´???(??????)
			dp[j][j+i-1] = INF;
			for (int k = j; k < j + i - 1; k++ ) { //?????????
				dp[j][j+i-1] = min(dp[j][j+i-1],dp[j][k] + dp[k+1][j+i-1] + p[j] * p[k+1] * p[j+i]);
			}
		}
	}
	//printv(dp);
	cout(dp[0][n-1]);
		
	return 0;
}