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++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int num = 105;
int p[num];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &p[i-1], &p[i]);
	}
	int m[num][num];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			m[i][j] = 999999999999;
		}
	}
	for (int i = 1; i <= n; i++) m[i][i] = 0;
	for (int l = 1; l < n; l++) {
		for (int i = 1; i < n - l + 1; i++) {
			int j = i + l;
			for (int k = i; k < j; 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;

constexpr 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; 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;
}

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

using namespace std;

static const int N = 100;
static int m[N + 1][N + 1] = {}, p[N + 1] = {};

static inline void matrixChainMultiplication(int n) {
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n - l + 1; i++) {
      int j = i + l - 1;
      m[i][j] = INT_MAX;
      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]); 
      }
    }
  }
}

int main() {
  int n;
  cin >> n;
  
  for (int i = 1; i <= n; i++) {
    cin >> p[i - 1] >> p[i];
  }

  matrixChainMultiplication(n);
  
  cout << m[1][n] << endl;

  return 0;
}

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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  vector<int> p(n+1);
  cin >> p[0] >> p[1];
  for(int i = 0; i < n-2; i++){
    int a, b; cin >> a >> b;
    p[i+2] = b;
  }
  {
    int a, b; cin >> a >> b;
    p[n] = b;
  }

  int dp[101][101];
  memset(dp, 0, sizeof(dp));

  n = p.size() - 1;
  for(int l = 2; l <= n; l++){
    for(int i = 1; i <= n-l+1; i++){
      int j = i+l-1;
      dp[i][j] = INT_MAX/10;
      for(int k = i; k < j; k++){
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j]);
      }
    }
  }
  cout << dp[1][n] << endl;
  return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

vector<pair<ll,ll>> P;
vvll memo;

ll dfs(int l,int r){
	if(memo[l][r]>=0) return memo[l][r];
	if(r-l<2){
		return 0;
	}
	
	ll V=1LL<<60;
	for(int i=l+1;i<r;i++){
		V = min(V,dfs(l,i)+dfs(i,r)+P[l].first*P[i].first*P[r-1].second);
	}
	memo[l][r] = V;
	return V;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	P.resize(N);
	memo.resize(N+1,vll(N+1,-1));
	REP(i,N){
		P[i].first=in();
		P[i].second=in();
	}
	
	out(dfs(0,N));
	return 0;
}

C++: // input: alds1_10_b.in
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

#define NIL -1

struct Matrix {
  Matrix(int r, int c)
    : r(r), c(c){
  }
  int r;
  int c;
};

int costs[101][101];

void init_costs() {
  for(int i=0; i<101; i++) {
    for(int j=0; j<101; j++) {
      costs[i][j] = NIL;
    }
  }
}

int cost(vector<Matrix>& ms, int start, int end) {
  if(costs[start][end] != NIL) {
    return costs[start][end];
  }

  if(start == end) {
    costs[start][end] = 0;
    return 0;
  }

  if(end - start == 1) {
    Matrix s = ms.at(start);
    Matrix e = ms.at(end);
    int c = s.r * s.c * e.c;
    costs[start][end] = c;
    return c;
  }

  vector<int> cs;
  for(int i=start; i<end; i++) {
    int c1 = cost(ms, start, i);
    int c2 = cost(ms, i+1, end);
    int c3 = ms.at(start).r * ms.at(i).c * ms.at(end).c;
    cs.push_back(c1 + c2 + c3);
  }
  int c = *min_element(cs.begin(), cs.end());
  costs[start][end] = c;

  return c;
}

int solve(vector<Matrix>& ms) {
  return cost(ms, 0, ms.size()-1);
}

int main() {
  init_costs();

  int n;
  cin >> n;

  vector<Matrix> ms;

  for(int i=0; i<n; i++) {
    int r, c;
    cin >> r >> c;

    ms.push_back(Matrix(r, c));
  }

  cout << solve(ms) << endl;
}