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>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> R, C;
	int r, c;
	R.push_back(0);
	for (int i = 0; i < n; ++i) {
		cin >> r >> c;
		R.push_back(r);
	}
	R.push_back(c);

	int cost[100+1][100+1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			cost[i][j] = INT_MAX;
	for (int i = 1; i <= n; ++i)
		cost[i][i] = 0;

	for (int j = 1; j <= n - 1; ++j) {
		for (int i = 1; i <= n - j; ++i) {
			for (int k = i + 1; k <= i + j; ++k) {
				cost[i][i+j] = min(cost[i][i+j], cost[i][k-1] + cost[k][i+j] + R[i]*R[k]*R[i+j+1]);
			}
		}
	}

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

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int inf = INT32_MAX;

int main() {
  int n;
  cin >> n;
  V<int> column;

  rep(i, n) {
    int r, c;
    cin >> r >> c;
    if(i == 0) {
      column.push_back(r);
    }
    column.push_back(c);
  }

  V<V<int>> dp(n + 1, V<int>(n + 1));
  rep(i, n + 1) {
    dp[i][i] = 0;
  }

  int len = 2;
  while(len <= n) {
    for(int i = 1; i + len - 1 <= n; i++) {
      int j = i + len - 1;

      int min_cost = inf;
      for(int k = i; k < j; k++) {
        int cost = dp[i][k] + dp[k + 1][j] + column[i - 1] * column[k] * column[j];
        min_cost = min(min_cost, cost);
      }

      dp[i][j] = min_cost;
    }
    len++;
  }

  cout << dp[1][n] << endl;
}

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    vector<pair<int, int>> m(n);
    int a, b;
    rep(i, n) {
        cin >> a >> b;
        m[i] = make_pair(a, b);
    }
    vector<vector<int>> dp(n, vector<int>(n, INF));
    rep(i, n) dp[i][i] = 0;
    for (int len = 1; len <= n; len++) {
        for (int i = 0; i < n; i++) {
            int j = i + len - 1;
            if (j >= n)
                continue;
            for (int k = i; k < j; k++) {
                chmin(dp[i][j], dp[i][k] + dp[k + 1][j] +
                                    m[i].first * m[k].second * m[j].second);
            }
        }
    }
    cout << dp[0][n - 1] << endl;
}

C++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>

using namespace std;


int main(){

  int n;
  cin >> n;
  int m[n + 1][n + 1], p[n + 1];

  for(int i = 0; i < n; i++){
    cin >> p[i] >> p[i + 1];
    m[i][i] = 0;
  }
  m[n][n] = 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] = 1000000;
      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<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int main() {
	int n;
	int r[100];

	cin >> n;

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

	int m[100][100];

	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] + r[i - 1] * r[k] * r[j]);
			}
		}
	}
	cout << m[1][n] << endl;

	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<map>
using namespace std;
const int MAX_V = 100;
int a[MAX_V+1];
map<pair<int,int>, int> memo;

int dp(int s,int t){
  int &res=memo[make_pair(s,t)];
  if(res!=0) return res;
  if(t-s<2) return 0;
  int min=0x7fffffff;
  for(int i=s+1;i<=t-1;i++){
    int sum=dp(s,i)+dp(i,t)+a[s]*a[i]*a[t];
    if(sum<min){
      min=sum;
    }
  }
  res=min;
  return res;
}

int main(){
  int n; scanf("%d",&n);
  for(int i=0;i<n;i++){
    int fst,snd;
    scanf("%d %d",&fst,&snd);
    a[i]=fst; a[i+1]=snd;
  }
  int sum=dp(0,n);
  printf("%d\n",sum);
}

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