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;

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];
????????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] << "\n";
????????return 0;
}

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

long int M[101][101];
long int a[100];
int n;
void solve(){
  for(int i=0;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]=INT_MAX;
       	  for(int k=i;k<j;k++){
	        long int tmp = M[i][k]+M[k+1][j]+a[i-1]*a[k]*a[j];
		if(M[i][j]>tmp){
		    M[i][j] = tmp;	
		}
	    }
	}
    }
}

int main(){ 
   cin>>n;
   for(int i=0;i<n;i+=2){
	cin>>a[i]>>a[i+1];
   }
   solve();
   for(int i=0;i<=n;i++){
	for(int j=0;j<=n;j++){
//	    cout<<"("<<i<<","<<j<<")"<<M[i][j]<<" ";
	}
//	cout<<endl;
   }
   cout<<M[1][n-1]<<endl;
   return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int n,a;
    cin>>n;
    int p[n+1];
    for(int i=0;i<=n;i++){
        cin>>p[i]>>p[i+1];
    }
    int m[n+1][n+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=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;
                }
            }
        }
    }
    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[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;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

ll n;
ll r[105],c[105];
ll dp[105][105];
ll f(ll lx,ll rx){
    if(rx-lx==1)return 0;
    if(dp[lx][rx]!=-1)return dp[lx][rx];
    ll ret=LINF;
    fore(i,1,rx-lx-1){
        chmin(ret,f(lx,lx+i)+f(lx+i,rx)+r[lx]*r[lx+i]*c[rx-1]);
    }
    return dp[lx][rx]=ret;
}
void solve(){
    cin>>n;
    rep(i,n)cin>>r[i]>>c[i];

    rep(i,n+1)rep(j,n+1)dp[i][j]=-1;
    cout<<f(0,n)<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;


ll dp[110][110];
bool flag[110][110];
int n;
vector<ll>p;

ll rec(ll left,ll right){
    if(flag[left][right])return dp[left][right];
    if(left == right){
        flag[left][right]=true;
        return dp[left][right]=0;
    }
    if(left>right){
        return 0;
    }
    if(right -left ==1){
        flag[left][right]=true;
        return dp[left][right] = p[left]*p[left+1]*p[left+2];
    }
    ll Min = INF;
    for(ll l=left;l<right;l++){
        Min =min(Min,rec(left,l)+rec(l+1,right)+p[left]*p[l+1]*p[right+1]);
    }
    flag[left][right]=true;
    return dp[left][right]=Min;
}

int main(void){
    cin>>n;
    vector<int>r(n),c(n);
    for(int i=0;i<n;i++)cin>>r[i]>>c[i];
    p.resize(n+2);
    p[1]=r[0];
    for(int i=2;i<=n+1;i++)p[i]=(c[i-2]);
    //dp[l][r]をl,l+1,...,r-1と定める
    cout<<rec(1,n)<<endl;
    
    return 0;
}