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++: /*
 * chain_matrix.cpp
 *
 *  Created on: 2017/07/11
 *      Author: LitMc
 */

//#define MYDEBUG
#include <bits/stdc++.h>

#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(w,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
#define EPS = 1e-14;
using std::vector;
using std::cout;
using std::cin;
using std::endl;
using std::max;
using std::min;
using std::swap;
using std::string;
using std::fill;
using std::pair;
using std::sort;
using std::reverse;
using std::pair;
using std::greater;
using std::priority_queue;
using std::ostream;

template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i] << endl;
  }
  return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last) {
      out << ",";
    }
  }
  out << "]";
  return out;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

typedef pair<int, int> P;
bool cmp(const P &p1, const P &p2) {
  if (p1.first == p2.first) {
    return p1.second > p2.second;
  } else {
    return p1.first < p2.first;
  }
}
typedef pair<int, int> P;
static const int MAX_N = 110;
static const int INF = 100000000;
int n, r, c;
P M[MAX_N];
int dp[MAX_N][MAX_N];

//dp[i][j]: M[i]??????M[j]?????§??????????????????????°??????°
//dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + prod)
//k = [i, j)
//prod = M[i].row * M[k].col * M[j].col

void solve() {
  cin >> n;
  rep(i,0,n)
  {
    cin >> M[i].first >> M[i].second;
    dp[i][i] = 0;
  }
  for (int i = 0; i + 1 < n; ++i) {
    dp[i][i + 1] = M[i].first * M[i].second * M[i + 1].second;
    dbp4(i, M[i], M[i + 1], dp[i][i + 1]);
  }
  for (int num_matrix = 3; num_matrix <= n; ++num_matrix) { //number of matrix A*B*C -> 3
    for (int i = 0, j = i + num_matrix - 1; j < n; ++i, ++j) {
      dbp4(i, M[i], M[j], dp[i][j]);
      int mini = INT_MAX;
      for (int k = i; k + 1 <= j; ++k) {
        int prod = M[i].first * M[k].second * M[j].second;
        mini = min(mini, dp[i][k] + dp[k + 1][j] + prod);
      }
      dp[i][j] = mini;
      dbp4(i, M[i], M[j], dp[i][j]);dbp("----------");
    }
  }
  cout << dp[0][n - 1] << endl;
}

int main() {
  solve();
}

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

using namespace std;

int main () {

    int i, j, k, l, n, p[101], m[101][101];

    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] = (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, 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[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;
int p[105];
int m[110][110];
int n;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i - 1];
		cin >> p[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] = (i << 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] << "\n";
	return 0;
}

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

int	main()
{
	int	cnt[100][100];
	int	n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j)
			cnt[i][j] = -1;
		cnt[i][i] = 0;
	}
	vector<int>	r_vec(n), c_vec(n);
	for (int i = 0; i < n; ++i)
		cin >> r_vec.at(i) >> c_vec.at(i);
	for (int i = 1; i < n; ++i) {
		int	k;
		for (int j = 0; (k = i + j) < n; ++j) {
			for (int l = j; l < k; ++l) {
				int	tmp_cnt = cnt[j][l] + cnt[l + 1][k];
				tmp_cnt += r_vec.at(j) * c_vec.at(l) * c_vec.at(k);
				if (cnt[j][k] == -1 || cnt[j][k] > tmp_cnt)
					cnt[j][k] = tmp_cnt;
			}
		}
	}
	cout << cnt[0][n - 1] << endl;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
static const int N=100;
int main(){
  int n,p[N+1],m[N+1][N+1];
  scanf("%d",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-1+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]);
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}