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>

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    int n;
    cin>>n;
    int p[101],m[101][101];
    rep(i,1,n+1)cin>>p[i-1]>>p[i];
    rep(i,1,n+1)m[i][i]=0;
    rep(l,2,n+1){
        for(int i=1;i<=n-l+1;i++){
            int j=i+l-1;
            m[i][j]=INF;
            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]<<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<iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int d[n+1];
    for(int i=0;i<n;++i) cin>>d[i]>>d[i+1];
    int a[n][n];
    fill(a[0],a[n],1<<28);
    for(int i=0;i<n;++i) a[i][i]=0;
    for(int l=1;l<n;++l)
        for(int i=0;i<n-l;++i){
            int j=i+l;
            for(int k=i;k<j;++k)
                a[i][j]=min(a[i][j],a[i][k]+a[k+1][j]+d[i]*d[k+1]*d[j+1]);
        }
    cout<<a[0][n-1]<<endl;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define INF (1<<21)
using namespace std;

int main()
{
  int n;
  cin >> n;

  vector<int> p(105);
  int m[105][105];

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

  for(int i = 2; i <= n; i++){
    for(int j = 1; j <= n-i+1; j++){
      int x = i + j - 1;
      m[j][x] = INF;

      for(int k = j; k <= x-1; k++){
	m[j][x] = min(m[j][x], m[j][k]+m[k+1][x] + p[j-1]*p[k]*p[x]);
      }
    }
  }

  cout << m[1][n] << endl;

  return 0;

}

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


int main() {
	int n, p[101], m[101][101];
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];
	
	int i, j, k, l;
	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;

	
}

C++: #include <iostream>
#include <vector>
using namespace std;
const int INF = 1001001001;

int main(){
    int n;
    cin >> n;
    vector<int> rnum(n+1);
    for(int i = 0; i < n; i++){
        cin >> rnum[i] >> rnum[i+1];
    }

    vector<vector<int>> memo(n, vector<int>(n, INF));
    for(int i = 0; i < n; i++) memo[i][i] = 0;

    for(int i = n-1; i >= 0; i--){
        for(int j = i; j < n; j++){
            for(int k = i; k+1 < n; k++){
                if(memo[i][j] > memo[i][k] + memo[k+1][j] + rnum[i]*rnum[k+1]*rnum[j+1]){
                    memo[i][j] = memo[i][k] + memo[k+1][j] + rnum[i]*rnum[k+1]*rnum[j+1];
                }
            }
        }
    }

    cout << memo[0][n-1] << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
long long dp[1005][1005];
long long a[1005];
long long b[1005];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//	freopen("a.txt","r",stdin);
	int n;cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i];
	memset(dp,0xc,sizeof(dp));
	for(int i=1;i<=n;i++)dp[i][i]=0;
	for(int l=1;l<n;l++){
		for(int i=1;i<=n;i++){
			int j=i+l;
			if(j>n)continue;
			for(int k=i;k<j;k++)
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+a[i]*a[k+1]*b[j]);
		}
	}		
	cout<<dp[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;
}