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 <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 998244353;
const ll maxn=1e3+5;
ll pw(ll x, ll p){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=mod;
        }
        x*=x;
        x%=mod;
        p>>=1;
    }
    return ret;
}
ll inv(ll x){
    return pw(x, mod-2);
}
int cosst(pii x, pii y, pii z){
    return x.f*y.s*z.s;
}
signed main(){
    IOS();
    int n; cin>>n;
    vector<pii> vc(n);
    REP(i,n) cin>>vc[i].f>>vc[i].s;
    vector<int> dp[n+2];
    REP(i,n+2){
        dp[i].resize(n+2);
    }
    //cout<<endl;
    for (int i=n;i>=1;i--){
        FOR(j,i+1,n+1){
            dp[i][j]=inf;
            FOR(k,i,j){
                dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]+cosst(vc[i-1], vc[k-1], vc[j-1]));
            }
            //cout<<i<<' '<<j<<endl;
            //cout<<dp[i][j]<<endl;
        }
    }
    /*REP1(i,n){
        REP1(j,n){
            cout<<i<<' '<<j<<endl;
            cout<<dp[i][j]<<endl;
        }
    }
    */
    cout<<dp[1][n]<<endl;

}

C++: #include<bits/stdc++.h>
#include<limits.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

static const int N = 100;

int main(){
    int n;
    vector<int> p(N+1);
    vector<vector<int>> m(N+1, vector<int>(N+1, 0));
    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> p.at(i - 1) >> p.at(i);
    }
    for(int l = 2; l <= n; l++){
        for(int i = 1; i <= n - l + 1; i++){
            int j = i + l - 1;
            m.at(i).at(j) = (1 << 21);
            for(int k = i; k <= j - 1; k++){
                m.at(i).at(j) = min(m.at(i).at(j), m.at(i).at(k) + m.at(k + 1).at(j) + p.at(i - 1) * p.at(k) * p.at(j));
            }
        }
    }
    cout << m.at(1).at(n) << endl;


}

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

static const int N = 105;

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 <cstdlib>
#include <cstdio>

using namespace std;

typedef struct matrix{
  int row;
  int column;
  struct matrix *next;
  struct matrix *back; 
}Matrix;

Matrix *push_back(Matrix *begin, int row, int column) {
  Matrix *p = (Matrix*)malloc(sizeof(Matrix));
  p->row = row;
  p->column = column;
  p->next = NULL;
  p->back = NULL;
  if(begin == NULL) return p;
  Matrix *p2 = begin;
  while(p2->next != NULL) p2 = p2->next;
  p2->next = p;
  p->back = p2;
  return begin;
}

Matrix *product_count(Matrix *x, int type, int *count) {
  Matrix *a,*b;
  if(type == 0) {
    a = x->back;
    b = x;
  }
  else {
    a = x;
    b = a->next;
  }
  *count = 0;
  if(a == NULL || b == NULL) return x;
  *count += a->row * a->column * b->column;
  Matrix *c = (Matrix*)malloc(sizeof(Matrix));
  c->row = a->row;
  c->column = b->column;
  c->next = b->next;
  c->back = a->back;
  if(a->back != NULL) a->back->next = c;
  if(b->next != NULL) b->next->back = c;
  free(a);
  free(b);
  return c;
}

Matrix *product_atob(Matrix *a, Matrix *b, int type,  long *sum) {
  int count;
  if(type == 0) {
    while(a->next != b) {
      b = product_count(b, 0, &count);
      *sum += count;
    }
  }
  else {
   while(a->next != b) {
      a = product_count(a, 1, &count);
      *sum += count;
    }
  }
  a = product_count(a, 1, &count);
  *sum += count;
  return a;
}

Matrix *solve(Matrix *x, long *sum) {
  if(x->next == NULL) return x;
  Matrix *min = x->next, *p = x->next;
  while (p->next != NULL) {
    if(min->column > p->column) min = p;
    p = p->next;
  }
  if(min->column < x->row) {
    x = product_atob(x, min, 0, sum);
  }
  else if(min->column > x->row) {
    x = product_atob(x, min, 1, sum);
  }
  else {
    Matrix *min2 = x->next;
    p = x->next;
    while (p != min) {
      if(min2->column > min->column && min2->column > p->column) min2 = p;
      p = p->next;
    }
    x = product_atob(x, min2, 1, sum);
  }
  if(x->next != NULL) {
    p = solve(x->next,sum);
    x = product_atob(x,p,0,sum);
  }
  return x;
}

int main()
{
  int i,n,r,c;
  Matrix *begin = NULL;
  scanf("%d",&n);
  for (i = 0; i < n; i++) {
    scanf("%d %d",&r,&c);
    begin = push_back(begin,r,c);

  }
  long sum = 0;
  begin = solve(begin, &sum);
  cout << sum << endl;
  
  return 0;
}

C++: #include<stdio.h>

#define N 101

int main(){
  int n;
  int p[N];
  int m[N][N];
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%d%d",&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;
      /*2<<21*/
      m[i][j]=2097152;
      for(int 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;


  }