Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for 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])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define N 100
int main(){
	int n,p[N+1],m[N+1][N+1];
	cin>>n;
	for(int i=0;i<n;i++)	cin>>p[i]>>p[i+1];
	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=l+i-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 <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll n;
V< P<ll, ll> > rc;
vvll dp;

ll rec(ll l, ll r) {
    if (l == r) return dp[l][r] = 0;
    if (dp[l][r] != HIGHINF) return dp[l][r];
    for (ll i = l; i <= r - 1; i++) {
        chmin(dp[l][r], rec(l, i) + rec(i + 1, r) + rc[l].first * rc[i].second * rc[r].second);
    }
    return dp[l][r];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rc.resize(n);
    for (ll i = 0; i < n; i++) cin >> rc[i].first >> rc[i].second;
    dp.resize(n, vll(n, HIGHINF));
    cout << rec(0, n - 1) << '\n';

    // for (ll i = 0; i < n; i++) DEBUG_VLL(dp[i])
    return 0;
}

C++: #include <iostream>
using namespace std;

const int INF = 1 << 28;

int n;
int memo[101][101];
int r[102];

int dfs(int i, int j){
    int res = INF;
    
    if(memo[i][j] != -1) return memo[i][j];
    
    if(i == j){
        return 0;
    }
    
    for(int k = i; k < j; ++k){
        res = min(res, dfs(i,k) + dfs(k + 1, j) + r[i] * r[k + 1] * r[j + 1]);    
    }
    
    return memo[i][j] = res;
}


int main()
{

    cin >> n;
    fill((int*)memo, (int*)(memo + n), -1);
    for(int i = 0; i < n; ++i){
        cin >> r[i] >> r[i + 1];
    }
    
    cout << dfs(0, n-1) << endl;
    
}

C++: #include<cstdio>
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#define _USE_MATH_DEFINES // M_PI????????????????????????
#include<math.h>
#pragma warning(disable:4996)
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][k],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}
	cout << m[1][n] << "\n";
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1010;

int p[N];

int f[N][N];

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)	scanf("%d%d", &p[i - 1], &p[i]);
	
	for(int len = 2; len <= n; len++)
	{
		for(int i = 1; i + len - 1 <= n; i++)
		{
			int j = i + len - 1;
			
			f[i][j] = INF;
			
			for(int k = i; k < j; k++)
			{
				f[i][j] = min(f[i][j], f[i][k] + f[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	
	
	printf("%d\n", f[1][n]);
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int m[1000][1000];
int maxchainorder(int p[],int a){
    int n=a;
    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]=100000000;
            for(int k=i;k<=j-1;k++){
                int q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
                if(q<m[i][j]){
                    m[i][j]=q;
                }
            }
        }
    }
    return m[1][n];
}
int main(){
    int n,p[100000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i]>>p[i+1];
    }
    cout<<maxchainorder(p,n)<<endl;
    return 0;
}

C++: //compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF =2e9;
ll matrixchainorder(int *a, int n){
	int i;
	static ll dp[150][150];
	repx(i, n, 1) dp[i][i] = 0;
	for(int l = 2;l<=n;l++){
		for(i = 1;i<=n-l+1;i++){
			int j = i+l-1;
			dp[i][j] = INF;
			for(int k = i; k<j;k++){
				ll x = dp[i][k] + dp[k+1][j] + (a[i-1]*a[k]*a[j]);
				dp[i][j] = min(dp[i][j], x);
			}
		}
	}
	return dp[1][n];	
}

int main(){
	int n;
	int i;
	cin >> n;
	int a[n+3];
	for(i=1;i<=n;i++){
		cin >> a[i-1] >> a[i];
	}
	cout <<	matrixchainorder(a, n) <<endl;
}